OTel trace processor
The otel_traces processor completes trace-group-related fields in all incoming OpenSearch Data Prepper span records by caching the root span information for each traceId. It also enriches traces from generative AI (GenAI) agents and large language model (LLM) applications. For more information, see GenAI agent trace enrichment.
The processor was previously named otel_trace_raw. You can still use the otel_trace_raw name, but it is deprecated and is planned for removal in Data Prepper 3.0.
Usage
This processor adds the following fields to span events:
traceGroup: Root span nameendTime: End time of the entire trace in International Organization for Standardization (ISO) 8601 formatdurationInNanos: Duration of the entire trace in nanosecondsstatusCode: Status code for the entire trace
Configuration
The following table describes the options you can use to configure the otel_traces processor.
| Option | Required | Type | Description |
|---|---|---|---|
trace_flush_interval | No | Integer | The amount of time, in seconds, after which the processor flushes descendant spans that have no root span. Default is 180. |
trace_group_cache_ttl | No | Duration | The amount of time to keep trace group details in the cache. Accepts ISO 8601 notation, such as PT1M30S, or a duration and unit, such as 45s. Default is 15s. |
trace_group_cache_max_size | No | Integer | The maximum number of trace groups from root spans to keep in the cache. Default is 1000000. |
disable_genai_enrichment | No | Boolean | Turns off GenAI agent trace enrichment: normalizing vendor attributes to gen_ai.*, stripping flattened sub-keys that conflict with their parent, marking agent root spans, and copying agent data onto trace roots. Traces that contain no GenAI spans are not changed. Default is false. |
genai_coverage_cache_max_size | No | Integer | The maximum number of GenAI span IDs to keep in the coverage cache across all traces. The cache prevents GenAI spans that arrive after their ancestors from being marked as a trace’s AI root. Must be at least 1. Cannot be set when disable_genai_enrichment is true. For more information, see Late spans and the coverage cache. Default is 500000. |
genai_root_propagation | No | String | Determines which root spans receive the GenAI attributes and token totals copied from their child spans. Valid values are ai_root, all_roots, and none. Cannot be set when disable_genai_enrichment is true. For more information, see Root span enrichment. Default is ai_root. |
The disable_genai_enrichment, genai_coverage_cache_max_size, and genai_root_propagation options are available in Data Prepper 2.17 and later.
GenAI agent trace enrichment
The otel_traces processor enriches traces from GenAI agents and LLM applications so that agent runs can be found, listed, and measured from the spans themselves, for example, in the OpenSearch Dashboards Agent Traces page. Enrichment is turned on by default, is available in Data Prepper 2.14 and later, and does not change traces that contain no GenAI data.
Enrichment matches attributes by their OpenTelemetry (OTel) key names, for example, gen_ai.operation.name, so the source must emit spans in the OTel format. The otel_trace_source source defaults to the opensearch format, so set its output_format to otel. The otlp source uses the otel format by default. The opensearch format rewrites attribute keys (for example, http.method becomes span.attributes.http@method), and the enrichment then finds no GenAI data.
For each trace in a batch, the processor applies the following steps in order:
To turn off all of these steps, set disable_genai_enrichment to true. Span attributes are then left as they arrive, and the processor creates no coverage cache.
Vendor attribute normalization
Instrumentation libraries name the same data differently. For example, input tokens are llm.token_count.prompt in OpenInference, llm.usage.prompt_tokens in OpenLLMetry, and gen_ai.usage.input_tokens in the OTel GenAI semantic conventions. The processor copies vendor attributes to their gen_ai.* names so that queries, dashboards, and the rest of the enrichment only need the standard names. The normalization follows these rules:
- The mappings are listed in
genai-attribute-mappings.yamland grouped by source:openinference,openllmetry(Traceloop), andclaude_code. - The original attributes are kept. The
gen_ai.*copy is added next to them. - A
gen_ai.*attribute that is already on the span is never overwritten. - When several attributes on one span map to the same
gen_ai.*name, the one listed first in the mappings file is used. For example, the OpenInferencesession.idattribute is used before Traceloop’straceloop.association.properties.session_id; both map togen_ai.conversation.id. - Operation kinds are mapped to
gen_ai.operation.namevalues. For example, the OpenInferenceLLMkind becomeschat,AGENTandCHAINbecomeinvoke_agent, andTOOLbecomesexecute_tool. - Some mappings wrap a single value in a JSON array, for example, a finish reason in
gen_ai.response.finish_reasons.
Starting in Data Prepper 2.17, Traceloop session IDs (traceloop.association.properties.session_id) are mapped to gen_ai.conversation.id, which groups traces into sessions.
Flattened sub-key stripping
Some instrumentations emit the same field twice: as a JSON string (for example, llm.input_messages) and as flattened sub-keys (for example, llm.input_messages.0.message.content). OpenSearch rejects such documents with a mapping conflict. When the parent string is present, the processor removes the indexed sub-keys. When only the sub-keys are present, they are kept so that no data is lost.
Root span enrichment
The processor can copy gen_ai.system, gen_ai.provider.name, gen_ai.agent.name, gen_ai.request.model, and the trace’s token totals from child spans onto the trace’s root span. Attributes that the root span already has are kept. Values are taken from the outermost GenAI spans first (by earliest start time), then from other GenAI spans, and then from the remaining children.
The genai_root_propagation option selects which root spans receive the copies, as described in the following table.
| Value | Root spans that receive the copies |
|---|---|
ai_root (default) | Only a root span that is its trace’s AI root: a GenAI span, or a span marked derived.gen_ai.is_root: true at the source. |
all_roots | Every root span, including non-GenAI roots such as the HTTP span that an agent runs behind. This was the default before Data Prepper 2.17. |
none | No root span. |
With ai_root, a non-GenAI root span keeps only its own attributes. Copying agent data onto a non-GenAI root span makes the HTTP span appear to call a model and use tokens, combines parallel agents into one agent name, and counts the trace’s tokens again for any consumer that sums usage across spans. The agent root marker span carries this data instead.
Marking does not depend on this option: with none, an agent span that the processor marks still receives its descendants’ token totals.
In Data Prepper 2.17, the default changed from copying onto every root span to ai_root. If your queries or dashboards read agent data, such as gen_ai.agent.name or token totals, from non-GenAI root spans, set genai_root_propagation to all_roots to keep the previous behavior, or read the data from the marked agent span.
Agent root marker
Agents often run behind a service: the trace’s root span is an HTTP or RPC span, such as POST /plan, and the agent span is nested under it. Consumers that list traces by their root span then miss the agent or show the HTTP span instead. Starting in Data Prepper 2.17, the processor marks the span that represents each agent run with derived.gen_ai.is_root: true. The marker follows these rules:
- Each outermost GenAI span of a trace is marked. This is a span that has
gen_ai.operation.nameand no GenAI ancestor: either the root span itself, when it is a GenAI span, or the agent span nested under a non-GenAI root. - When several top-level agents run under one root span, each is marked as one agent run.
- In a chain of agents that call agents, such as
invoke_agent> HTTP client > HTTP server >invoke_agent, only the calling agent is marked because the called agent has a GenAI ancestor. - A span that the processor marks and that reports no token usage of its own receives the usage of its descendants. Spans marked at the source do not receive these totals. Descendant usage is counted as described in Token usage.
- An SDK or the user can set the marker on a span at the source. If any span in a trace is marked
trueat the source, the processor marks no other span in that trace. A span set tofalseis never marked, so settingfalseon a trace’s outermost GenAI spans excludes the trace from marking. - Spans that are flushed after
trace_flush_intervalwithout their root span are still marked because the marker only needs the span’s descendants.
To list a trace’s agent runs, query its marked spans. For data indexed before the marker existed, query root spans that are GenAI spans instead.
Late spans and the coverage cache
The spans of one trace can arrive in several batches. A span that arrives after its agent span was processed is enriched without its ancestors, so it would appear to be outermost and would be marked as a second agent run. To prevent this, the processor records, per trace, which span IDs are already covered by a GenAI span or a marker, and checks this record when a span’s parent is not in the batch. The coverage cache works as follows:
- Entries are kept for twice the
trace_flush_intervalplus thetrace_group_cache_ttl(375 seconds by default), so they outlive the flush of spans that arrive without their root span. - The cache stores at most
genai_coverage_cache_max_sizespan IDs across all traces. Only traces that contain GenAI spans are stored. ThegenAiCoverageSpanIdCountmetric reports how full the cache is, in span IDs. - The cache supports about
genai_coverage_cache_max_size/ (2 ×trace_flush_interval+trace_group_cache_ttl) GenAI spans per second, which is about 1,300 spans per second by default. At higher rates, traces are evicted early and a late span can be marked again, so increasegenai_coverage_cache_max_sizefor higher GenAI span rates. - The covered-span lookup, the marking, and the update run atomically for each trace, so pipeline workers that process spans of the same trace at the same time do not both mark a span.
The coverage cache has the following limitations:
- A span that arrives after its trace’s entry has expired or was evicted can be marked.
- If a trace’s child spans are flushed before a GenAI root span arrives, both the root span and the outermost child span can be marked. Consumers should prefer the marked span that has no parent.
- If a called service’s spans are flushed after
trace_flush_intervalwithout the caller’s spans, the called agent is also marked and is listed as a separate agent run.
Token usage
When the processor sums gen_ai.usage.input_tokens and gen_ai.usage.output_tokens, either onto a root span or onto a marked agent span, it counts only spans that have no ancestor that also reports usage. Agent spans such as invoke_agent often report the total of their own LLM calls, so adding every span that reports usage would count those calls twice. Token counting follows these rules:
- An ancestor’s reported usage is assumed to include its subtree. A sub-agent that runs its own LLM calls under a parent that reports only its own usage is not added.
- A span that reports either token count is treated as reporting usage and keeps its own values.
- Token counts sent as numeric strings are read as numbers. Other values are ignored.
Example
The following pipeline receives OpenTelemetry Protocol (OTLP) traces in the OTel format and writes enriched spans to OpenSearch. The GenAI options are shown with their default values:
otel-traces-pipeline:
source:
otel_trace_source:
ssl: false
output_format: otel
processor:
- otel_traces:
disable_genai_enrichment: false
genai_root_propagation: ai_root
genai_coverage_cache_max_size: 500000
sink:
- opensearch:
hosts: ["https://opensearch:9200"]
index_type: trace-analytics-plain-raw
Metrics
The following table describes common Abstract processor metrics.
| Metric name | Type | Description |
|---|---|---|
recordsIn | Counter | Metric representing the ingress of records to a pipeline component. |
recordsOut | Counter | Metric representing the egress of records from a pipeline component. |
timeElapsed | Timer | Metric representing the time elapsed during execution of a pipeline component. |
The otel_traces processor includes the following custom metrics:
traceGroupCacheCount: The number of trace groups in the trace group cache.spanSetCount: The number of span sets in the span set collection.genAiCoverageCount: The number of traces in the GenAI coverage cache.genAiCoverageSpanIdCount: The number of span IDs in the GenAI coverage cache, in the same unit asgenai_coverage_cache_max_size. Available in Data Prepper 2.17 and later.