Mask Span Attributes: Redact Sensitive Trace Data

Redact sensitive inputs, outputs, images, and embeddings from spans before export, using environment variables or TraceConfig in code.

About

Traces often contain sensitive data: user messages, API responses, PII, or large base64-encoded images. Sending all of this to a trace backend creates privacy and compliance problems. Masking span attributes removes this data before it leaves the application: it only truncates for one field, base64_image_max_length, which caps the length of base64-encoded images. Everything else is either sent in full or hidden completely; there is no general truncation. To cap the size of arbitrary attribute values (large prompts, tool outputs), see Cap attribute size instead. Configuration is available at two levels: environment variables for defaults across instrumentors that support TraceConfig, and TraceConfig in code for per-instrumentor control. These settings are not an exporter-wide filter for native OpenTelemetry spans; follow the integration’s own privacy instructions.


When to use

  • Privacy and compliance: Hide user inputs and LLM outputs to prevent sensitive data from being stored in trace backends.
  • Image redaction: Suppress base64-encoded images from input messages or cap their length to reduce payload size.
  • Selective masking: Hide only specific parts of a span (e.g. input text but not output messages) while keeping the rest visible.
  • Error text: A provider error body can quote your prompt back, and a framework error can include a traceback with local file paths. Hiding inputs or outputs hides error details too; see Errors and privacy to keep or drop them independently.
  • Environment-specific config: Use environment variables for deployment-level defaults and TraceConfig in code for per-instrumentor overrides.

How to

Set these before initializing instrumentors that support TraceConfig. An explicit value in code takes precedence.

Environment VariableDescriptionTypeDefault
FI_HIDE_INPUTSHides input values, all input messages, and embedding input textboolFalse
FI_HIDE_OUTPUTSHides output values and all output messagesboolFalse
FI_HIDE_INPUT_MESSAGESHides all input messages and embedding input textboolFalse
FI_HIDE_OUTPUT_MESSAGESHides all output messagesboolFalse
FI_HIDE_INPUT_IMAGESHides images from input messagesboolFalse
FI_HIDE_INPUT_TEXTHides text from input messages and input embeddingsboolFalse
FI_HIDE_OUTPUT_TEXTHides text from output messagesboolFalse
FI_HIDE_EMBEDDING_VECTORSHides returned embedding vectorsboolFalse
FI_BASE64_IMAGE_MAX_LENGTHCaps the character count of a base64 encoded imageint32,000
FI_HIDE_ERROR_DETAILSHides the status description, exception message, and stack trace on supported traceAI spans. Use Python fi-instrumentation-otel 1.2.3 or later or TypeScript @traceai/fi-core 1.1.1 or laterboolWhen unset, derived from the resolved input/output content flags in code or the environment; see Errors and privacy

Pass a TraceConfig object to an instrumentor that supports it, such as the OpenAI instrumentors below, for per-instrumentor control. Values set here take precedence over environment variables.

from fi_instrumentation import TraceConfig

config = TraceConfig(
    hide_inputs=False,
    hide_outputs=False,
    hide_input_messages=False,
    hide_output_messages=False,
    hide_input_images=False,
    hide_input_text=False,
    hide_output_text=False,
    hide_embedding_vectors=False,
    base64_image_max_length=32000,
)

from traceai_openai import OpenAIInstrumentor
OpenAIInstrumentor().instrument(
    tracer_provider=trace_provider,
    config=config,
)
const { OpenAIInstrumentation } = require("@traceai/openai");

const instrumentation = new OpenAIInstrumentation({
    traceConfig: {
        hideInputs: false,
        hideOutputs: false,
        hideInputMessages: false,
        hideOutputMessages: false,
        hideInputImages: false,
        hideInputText: false,
        hideOutputText: false,
        hideEmbeddingVectors: false,
        base64ImageMaxLength: 32000,
    },
});

Key concepts

  • TraceConfig: An object accepted by supporting traceAI instrumentors. Use it to specify masking settings directly in code, scoped to a single instrumentor.
  • Environment variables: Defaults shared by instrumentors that support these settings. Useful for deployment-level configuration without changing code.
  • Precedence order:TraceConfig in code → environment variables → default values. More specific settings always win.
  • hide_inputs / hide_outputs:Broad flags that hide all input/output values and messages in one setting.
  • base64_image_max_length:Caps the logged length of base64-encoded images. Default is 32,000 characters.
  • hide_error_details: Drops the status description, exception message, and stack trace from failed spans while keeping the ERROR status, error.type, and exception.type. On by default when hide_inputs, hide_outputs, or an input/output message or text hiding flag is true. Image-only masking does not enable it. See Errors and privacy.

Next Steps

Was this page helpful?

Questions & Discussion