Skip to main content

Genainormalizer Processor

Status Available in: contrib Maintainers: @TylerHelmuth, @kylehounslow Source: opentelemetry-collector-contrib

Supported Telemetry

Traces

Overview

The GenAI Normalizer Processor rewrites attributes on spans emitted by non-OTel GenAI instrumentation libraries into the OTel GenAI Semantic Conventions.

Configuration

Built-in sources:

Any other name is a user-defined source: the entry’s mappings and value_mappings drive the normalization.

Top-level fields

Source

Each entry in sources accepts the following fields:

Scope

Normalization is applied to:
  • Span attributes
The following are not modified:
  • Resource attributes
  • Scope attributes
  • Span event attributes
  • Span link attributes

Schema URL

When a mapping fires on a span, the enclosing ScopeSpans.schema_url is set to the OTel semantic-conventions version this processor targets (https://opentelemetry.io/schemas/1.40.0). An existing schema_url is overwritten. ResourceSpans.schema_url is never modified.

Type handling

After renaming, the processor enforces target attribute types against the OTel GenAI semantic conventions, derived from the typed constructor functions in go.opentelemetry.io/otel/semconv. For target keys with a typed primitive constructor in semconv (gen_ai.usage.input_tokens int, gen_ai.request.temperature float64, gen_ai.request.model string, gen_ai.response.finish_reasons []string, etc.), the processor coerces between compatible scalar types and drops the rename when coercion is unsafe:
  • string -> int: parsed via strconv.ParseInt; non-numeric strings drop.
  • string -> float64: parsed via strconv.ParseFloat; non-numeric strings drop.
  • string -> []string: wrapped into a single-element slice.
  • int / double / bool -> string: converted to canonical string form.
  • structured source (map / slice) -> primitive target: dropped (would lose information).
For target keys defined as any in the spec (gen_ai.input.messages, gen_ai.output.messages, gen_ai.tool.definitions, gen_ai.operation.name enum, etc.), the processor preserves whatever shape the source emitted. Backends that require a uniform type for these targets should pair this processor with the transformprocessor for OTTL-based shape normalization.

Examples

Default configuration:
Delete source attributes after mapping:
Overwrite existing target attributes:
Normalize both OpenInference and OpenLLMetry:
User-defined renames and value foldings (see User-defined sources):

User-defined sources

Any name that is not a built-in (openinference, openllmetry) is a user-defined source. The entry’s mappings and value_mappings drive the normalization. User-defined sources reuse the same remove_originals, overwrite, and type-coercion semantics as the built-in sources. Validation rules:
  • mappings must be non-empty on any user-defined source.
  • mappings and value_mappings are rejected on built-in sources.
  • Each value_mappings outer key must appear as a target in mappings (catches unreachable rules at config time).
  • name must be unique across sources.
User-defined mappings landing on typed gen_ai.* targets get the same int/float/string/bool/[]string coercion as built-in mappings (see Type handling). User-defined mappings landing on non-gen_ai.* targets pass through verbatim. Future built-in sources. New built-in source names may be added in future releases. This is not treated as a breaking change. To avoid collisions, namespace user-defined names with a vendor or company prefix (e.g. custom.anthropic, acme.internal).

Performance

For user-defined sources, cost grows with the number of attributes on each span, not with the size of the mappings table. The processor walks every attribute on every span, and looking up a single attribute in mappings is constant time. Real-world spans carry tens to a few hundred attributes and process in microseconds. Spans with thousands of attributes still work, but know that per-span cost grows proportionally to the number of attributes in each span. See processor_benchmark_test.go for the benchmark suite. Run with go test -bench=. -benchmem.

Built-in mappings

openinference

Attribute renames: See internal/openinference/mappings.go for the canonical map. Source reference: OpenInference semantic conventions.

Message reconstruction

OpenInference represents messages as flattened indexed span attributes (e.g., llm.input_messages.0.message.role, llm.input_messages.0.message.content). The processor reconstructs these into a single JSON string attribute following the GenAI input messages schema and sets it as gen_ai.input.messages (or gen_ai.output.messages). Supported OpenInference message fields:
  • llm.{input,output}_messages.N.message.role
  • llm.{input,output}_messages.N.message.content
  • llm.{input,output}_messages.N.message.name — emitted as the name field on the message object when present
  • llm.{input,output}_messages.N.message.tool_calls.M.tool_call.id
  • llm.{input,output}_messages.N.message.tool_calls.M.tool_call.function.name
  • llm.{input,output}_messages.N.message.tool_calls.M.tool_call.function.arguments
  • llm.{input,output}_messages.N.message.tool_call_id
Not supported: multimodal content arrays (llm.{input,output}_messages.N.message.contents.M.message_content.*). OpenInference’s indexed content array format for images, audio, and other modalities is not reconstructed. Only the flat message.content string field is handled. Multimodal spans pass through with the original flattened attributes intact.
Role inference
Roles are constrained to the GenAI semconv enum: system, user, assistant, tool. When the source role is absent, empty, or not one of these values, the processor infers it from context:
GenAI semconv part types not produced
The following part types are defined in the GenAI input messages schema and output messages schema but are not emitted by this processor:
Output format
Messages are serialized as a JSON array of objects. Input messages (gen_ai.input.messages) follow the GenAI input messages schema; output messages (gen_ai.output.messages) follow the GenAI output messages schema. Example gen_ai.input.messages:
Example gen_ai.output.messages:
The name field (participant name) is included on a message object only when the source carries message.name; otherwise it is omitted. Example:
The finish_reason field is always present on output messages (required by the schema) and always set to "" because OpenInference does not carry per-message finish reasons. Use gen_ai.response.finish_reasons (a span-level attribute) for the model’s stop reason. Messages are ordered by their numeric index N. The arguments field is parsed as JSON if valid; otherwise kept as a raw string.

openllmetry

Attribute renames: Coverage: this table covers the most common OpenLLMetry attributes. OpenLLMetry attributes not listed pass through unchanged. Open an issue if a missing attribute is blocking your migration. OpenLLMetry instrumentation typically emits one of each collision pair (llm.response.finish_reason xor llm.response.stop_reason; llm.request.type xor traceloop.span.kind). When both attributes in a pair are present on a span, the resolved value at the target key is undefined. See internal/openllmetry/mappings.go for the canonical map. Source reference: OpenLLMetry semantic conventions.

Value transformations

When a built-in mapping lands on gen_ai.operation.name, the string value is normalized to the OTel GenAI enum. Built-in lookups are case-insensitive; user-defined value_mappings are exact-match. When a mapped attribute lands on gen_ai.response.finish_reasons with a string source value, the value is wrapped into a single-element string[] to match the OTel GenAI spec type. Target reference: OTel GenAI operation names.

Relationship to other processors

The schemaprocessor translates between OTel semantic convention versions using schema_url and the OTel schema file format. Source conventions normalized by this processor do not set schema_url and do not publish OTel schema files, so schemaprocessor cannot be used for this translation today. The transformprocessor can rewrite attributes via OTTL but requires users to author and maintain the full mapping set themselves. This processor ships the mappings built-in. For pure value-mutation without renames, prefer transformprocessor.

Configuration

Example Configuration


Last generated: 2026-07-06