Skip to content

Commit 3c3d0e3

Browse files
authored
Merge pull request #562 from future-agi/fix/rewrite-tracing-mask-span
rewrite manual tracing mask span
2 parents a33acb2 + bcfda4e commit 3c3d0e3

1 file changed

Lines changed: 39 additions & 44 deletions

File tree

src/pages/docs/observe/features/manual-tracing/mask-span-attributes.mdx

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
---
22
title: "Mask Span Attributes"
3-
description: "Redact sensitive inputs, outputs, images, and embeddings from spans before they are exportedusing environment variables or TraceConfig in code."
3+
description: "Redact sensitive inputs, outputs, images, and embeddings from spans before they are exported:using environment variables or TraceConfig in code."
44
---
55

6-
## What it is
6+
## About
77

8-
**Mask Span Attributes** lets you control which data gets recorded in your traces. Using environment variables or a `TraceConfig` object passed to any auto-instrumentor, you can hide inputs, outputs, messages, images, text, and embedding vectors before they leave your application. This is useful for preventing sensitive data from being logged and for reducing payload size when working with large base64-encoded images.
8+
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, compliance, and payload size problems. Masking span attributes removes or truncates this data before it leaves the application. Configuration is available at two levels: environment variables for global defaults across all instrumentors, and `TraceConfig` in code for per-instrumentor control.
99

10-
## Use cases
10+
---
11+
12+
## When to use
1113

12-
- **Privacy and compliance** Hide user inputs and LLM outputs to prevent sensitive data from being stored in trace backends.
13-
- **Image redaction** Suppress base64-encoded images from input messages or cap their length to reduce payload size.
14-
- **Selective masking** Hide only specific parts of a span (e.g. input text but not output messages) while keeping the rest visible.
15-
- **Environment-specific config** Use environment variables for deployment-level defaults and `TraceConfig` in code for per-instrumentor overrides.
14+
- **Privacy and compliance**: Hide user inputs and LLM outputs to prevent sensitive data from being stored in trace backends.
15+
- **Image redaction**: Suppress base64-encoded images from input messages or cap their length to reduce payload size.
16+
- **Selective masking**: Hide only specific parts of a span (e.g. input text but not output messages) while keeping the rest visible.
17+
- **Environment-specific config**: Use environment variables for deployment-level defaults and `TraceConfig` in code for per-instrumentor overrides.
1618

1719
---
1820

1921
## How to
2022

21-
<Steps>
22-
<Step title="Review available settings">
23-
The following environment variables control what gets masked. Set them before your application starts for a global default, or configure them in code using `TraceConfig` (see next step).
23+
<Tabs>
24+
<Tab title="Environment Variables">
25+
These apply globally to all instrumentors at startup.
2426

2527
| Environment Variable | Description | Type | Default |
2628
|----------------------|-------------|------|---------|
@@ -33,10 +35,10 @@ description: "Redact sensitive inputs, outputs, images, and embeddings from span
3335
| `FI_HIDE_OUTPUT_TEXT` | Hides text from output messages | bool | False |
3436
| `FI_HIDE_EMBEDDING_VECTORS` | Hides returned embedding vectors | bool | False |
3537
| `FI_BASE64_IMAGE_MAX_LENGTH` | Caps the character count of a base64 encoded image | int | 32,000 |
36-
</Step>
38+
</Tab>
3739

38-
<Step title="Configure in code with TraceConfig">
39-
Pass a `TraceConfig` object to any auto-instrumentor to set masking options directly in code. Values set here take precedence over environment variables.
40+
<Tab title="TraceConfig in Code">
41+
Pass a `TraceConfig` object to any auto-instrumentor for per-instrumentor control. Values set here take precedence over environment variables.
4042

4143
<CodeGroup>
4244

@@ -63,47 +65,40 @@ description: "Redact sensitive inputs, outputs, images, and embeddings from span
6365
```
6466

6567
```javascript JS/TS
66-
import { OpenAIInstrumentor, FITraceConfig } from "@traceai/openai";
67-
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
68-
69-
const config: FITraceConfig = {
70-
hideInputs: false,
71-
hideOutputs: false,
72-
hideInputMessages: false,
73-
hideOutputMessages: false,
74-
hideInputImages: false,
75-
hideInputText: false,
76-
hideOutputText: false,
77-
hideEmbeddingVectors: false,
78-
base64ImageMaxLength: 32000,
79-
};
80-
81-
const instrumentor = new OpenAIInstrumentor();
82-
instrumentor.instrument(
83-
tracerProvider,
84-
config
85-
);
86-
87-
console.log("OpenAIInstrumentor configured with custom TraceConfig.");
68+
const { OpenAIInstrumentation } = require("@traceai/openai");
69+
70+
const instrumentation = new OpenAIInstrumentation({
71+
traceConfig: {
72+
hideInputs: false,
73+
hideOutputs: false,
74+
hideInputMessages: false,
75+
hideOutputMessages: false,
76+
hideInputImages: false,
77+
hideInputText: false,
78+
hideOutputText: false,
79+
hideEmbeddingVectors: false,
80+
base64ImageMaxLength: 32000,
81+
},
82+
});
8883
```
8984

9085
</CodeGroup>
91-
</Step>
92-
</Steps>
86+
</Tab>
87+
</Tabs>
9388

9489
---
9590

9691
## Key concepts
9792

98-
- **`TraceConfig`**An object accepted by all traceAI auto-instrumentors. Use it to specify masking settings directly in code, scoped to a single instrumentor.
99-
- **Environment variables**Global defaults applied to all instrumentors. Useful for deployment-level configuration without changing code.
100-
- **Precedence order**`TraceConfig` in code → environment variables → default values. More specific settings always win.
101-
- **`hide_inputs` / `hide_outputs`**Broad flags that hide all input/output values and messages in one setting.
102-
- **`base64_image_max_length`**Caps the logged length of base64-encoded images. Default is 32,000 characters.
93+
- **`TraceConfig`**:An object accepted by all traceAI auto-instrumentors. Use it to specify masking settings directly in code, scoped to a single instrumentor.
94+
- **Environment variables**:Global defaults applied to all instrumentors. Useful for deployment-level configuration without changing code.
95+
- **Precedence order**:`TraceConfig` in code → environment variables → default values. More specific settings always win.
96+
- **`hide_inputs` / `hide_outputs`**:Broad flags that hide all input/output values and messages in one setting.
97+
- **`base64_image_max_length`**:Caps the logged length of base64-encoded images. Default is 32,000 characters.
10398

10499
---
105100

106-
## What you can do next
101+
## Next Steps
107102

108103
<CardGroup cols={2}>
109104
<Card title="Set Up Tracing" icon="gear" href="/docs/observe/features/manual-tracing/set-up-tracing">

0 commit comments

Comments
 (0)