You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/docs/observe/features/manual-tracing/add-attributes-metadata-tags.mdx
+31-29Lines changed: 31 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,17 +3,19 @@ title: "Enriching Spans with Attributes, Metadata, and Tags"
3
3
description: "Capture additional context beyond what standard frameworks provide by enriching your traces with custom attributes, metadata, tags, session IDs, user IDs, and prompt templates."
4
4
---
5
5
6
-
## What it is
6
+
## About
7
7
8
-
**Enriching Spans** lets you attach custom key/value pairs and structured context to your OpenTelemetry spans so they carry the full picture of what's happening in your application. You can add raw attributes with `set_attribute()`, use traceAI Semantic Convention constants for structured LLM data, or use context managers (`using_metadata`, `using_tags`, `using_session`, `using_user`, `using_prompt_template`) to propagate attributes automatically to all child spans — without modifying every instrumented function.
8
+
A trace with only timing and status tells what happened, but not why. Without attributes like experiment IDs, feature flags, or prompt versions, filtering and debugging in the dashboard requires guesswork. Enriching spans attaches this application-specific context directly to traces so they become searchable, filterable, and meaningful. There are three ways to do it: add key/value pairs directly with `set_attribute()`, use traceAI Semantic Convention constants for structured LLM data, or use context managers (`using_metadata`, `using_tags`, `using_session`, `using_user`, `using_prompt_template`) to propagate attributes automatically to all child spans in a block.
9
9
10
-
## Use cases
10
+
---
11
+
12
+
## When to use
11
13
12
-
-**Custom attributes** — Add business-specific key/value pairs to spans for filtering and debugging in the Future AGI dashboard.
13
-
-**Semantic conventions** — Use traceAI constants like `OUTPUT_VALUE` and `LLM_OUTPUT_MESSAGES` to capture LLM outputs in a structured, queryable schema.
14
-
-**Metadata enrichment** — Attach experiment metadata, feature flags, or A/B test identifiers to all spans in a code block.
15
-
-**Session and user tracking** — Associate spans with a session ID and user ID for session replay and per-user analytics.
16
-
-**Prompt template tracking** — Record which prompt template, version, and variables were used in each LLM call.
14
+
-**Custom attributes for filtering**: Attach business-specific key/value pairs to spans so they can be filtered and searched in the dashboard.
15
+
-**Structured LLM outputs**: Use traceAI constants like `OUTPUT_VALUE` and `LLM_OUTPUT_MESSAGES` to capture LLM responses in a queryable schema.
16
+
-**Experiment and A/B test tracking**: Attach metadata like experiment IDs or feature flags to all spans in a code block.
17
+
-**Session and user grouping**: Associate spans with a session ID and user ID for session replay and per-user analytics.
18
+
-**Prompt template versioning**: Record which prompt template, version, and variables were used in each LLM call.
17
19
18
20
---
19
21
@@ -35,7 +37,7 @@ description: "Capture additional context beyond what standard frameworks provide
@@ -460,18 +462,18 @@ description: "Capture additional context beyond what standard frameworks provide
460
462
461
463
## Key concepts
462
464
463
-
-**`set_attribute()`** — Attaches a key/value pair directly to the active span. Supports strings, numbers, and booleans. Prefix custom attributes with your company name to avoid naming conflicts.
464
-
-**Semantic Conventions** — Structured attribute names defined by traceAI for common LLM data (messages, prompt templates, token counts). Use `SpanAttributes` and `MessageAttributes` constants from `fi_instrumentation.fi_types`.
465
-
-**Context attributes (Baggage)** — Set at the OpenTelemetry context level so they propagate automatically to all child spans within the block, without modifying instrumented functions.
466
-
-**`using_metadata`** — Attaches a JSON-serialized metadata dictionary to all spans in the context as the `metadata` attribute.
467
-
-**`using_tags`** — Attaches a JSON-serialized list of tag strings to all spans as `tag.tags`.
468
-
-**`using_session`** — Sets `session.id` on all spans in the context for session grouping.
469
-
-**`using_user`** — Sets `user.id` on all spans in the context for per-user tracking.
470
-
-**`using_prompt_template`** — Sets `llm.prompt_template.template`, `llm.prompt_template.version`, and `llm.prompt_template.variables` on all spans in the context.
465
+
-**`set_attribute()`**:Attaches a key/value pair directly to the active span. Supports strings, numbers, and booleans. Prefix custom attributes with your company name to avoid naming conflicts.
466
+
-**Semantic Conventions**:Structured attribute names defined by traceAI for common LLM data (messages, prompt templates, token counts). Use `SpanAttributes` and `MessageAttributes` constants from `fi_instrumentation.fi_types`.
467
+
-**Context attributes (Baggage)**:Set at the OpenTelemetry context level so they propagate automatically to all child spans within the block, without modifying instrumented functions.
468
+
-**`using_metadata`**:Attaches a JSON-serialized metadata dictionary to all spans in the context as the `metadata` attribute.
469
+
-**`using_tags`**:Attaches a JSON-serialized list of tag strings to all spans as `tag.tags`.
470
+
-**`using_session`**:Sets `session.id` on all spans in the context for session grouping.
471
+
-**`using_user`**:Sets `user.id` on all spans in the context for per-user tracking.
472
+
-**`using_prompt_template`**:Sets `llm.prompt_template.template`, `llm.prompt_template.version`, and `llm.prompt_template.variables` on all spans in the context.
471
473
472
474
---
473
475
474
-
## What you can do next
476
+
## Next Steps
475
477
476
478
<CardGroupcols={2}>
477
479
<Cardtitle="Set Up Tracing"icon="gear"href="/docs/observe/features/manual-tracing/set-up-tracing">
0 commit comments