OpenTelemetry GenAI semantic conventions
The OpenTelemetry GenAI semantic conventions are a vendor-neutral vocabulary for model telemetry: what a span for a model call is named, which attributes carry the model and provider, and which metrics report token usage and latency. Genkit can emit telemetry in that shape, so any backend that speaks OTLP receives data it already understands, with no Genkit-specific mapping on your side.
This is separate from the Developer UI pipeline. The Developer UI is fed by a built-in provider that posts spans straight to the Genkit telemetry server; see Local observability and metrics for that workflow. The two compose, so you can keep the Developer UI while also exporting OTLP.
What gets emitted
Section titled “What gets emitted”The conventions are defined by the spec, so the shape below is the same wherever Genkit implements them.
Model spans. One client span per model call, named chat <model>, carrying:
| Attribute | Notes |
|---|---|
gen_ai.operation.name | chat |
gen_ai.provider.name | Derived from the plugin, for example gcp.gemini, gcp.vertex_ai, openai, anthropic. Unknown plugins pass through lowercased. |
gen_ai.request.model | The model name, without the plugin prefix. |
gen_ai.request.* | Request config that was actually set: temperature, top_p, top_k, max_tokens, stop_sequences, frequency_penalty, presence_penalty, seed, choice.count. |
gen_ai.output.type | json or text, when an output format was requested. |
gen_ai.usage.input_tokens, gen_ai.usage.output_tokens | Token counts from the response. Reasoning and cached tokens land in gen_ai.usage.reasoning.output_tokens and gen_ai.usage.cache_read.input_tokens when the model reports them. |
gen_ai.response.finish_reasons | Mapped to spec values. A turn that ends in tool calls reports tool_calls. |
error.type | On failure. The exception is recorded on the span and rethrown unchanged. |
Metrics. The two spec-defined client metrics:
gen_ai.client.token.usage, a histogram of token counts split bygen_ai.token.type(inputoroutput).gen_ai.client.operation.duration, in seconds, recorded for successful and failed calls alike. Failures carryerror.type.
Both are tagged only with operation name, model, and provider, so cardinality stays low.
Everything else in the trace. With emit_tool_spans=True, tool calls get
execute_tool <name> spans with gen_ai.tool.name and
gen_ai.tool.type = 'function'. Every other action gets an INTERNAL span
named after the action, with genkit.action.type, so model calls nest under
their flow. Metadata set with set_metadata in a
genkit.telemetry.run_in_new_span callback is written as
genkit:metadata:<key>.
A few mapping rules are specific to Python:
error.typeis the exception class name, such asGenkitErrororValidationError. The span gets an error status withstr(exc)and an exception event, and the exception is re-raised unchanged.- A tool or flow that raises
Interruptsetsgenkit.interrupted = Trueon its span. The span is not marked as an error. gen_ai.request.*values are read from Pydantic ordictconfigs, under either Python names (top_p,max_output_tokens,candidate_count) or wire names (topP,maxOutputTokens,candidateCount).choice.countis recorded only when it is not1.- With content capture on, inline
data:media longer than 128 characters is replaced with<header>,<omitted N bytes>to stay within attribute size limits.
The instrumentation lives in the genkit-otel package:
uv add genkit-otel opentelemetry-sdk opentelemetry-exporter-otlpYour application owns the OpenTelemetry SDK. Register its providers, register
the GenAI instrumentation with configure_instrumentation, then create Genkit:
import asynciofrom opentelemetry import metrics, tracefrom opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporterfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporterfrom opentelemetry.sdk.metrics import MeterProviderfrom opentelemetry.sdk.metrics.export import PeriodicExportingMetricReaderfrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import BatchSpanProcessorfrom genkit import Genkitfrom genkit.telemetry import configure_instrumentationfrom genkit_google_genai import GoogleAIfrom genkit_otel import GenAiInstrumentation
# 1. Register the global trace and metric providers; exporters read OTEL_* env varstracer_provider = TracerProvider()tracer_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))trace.set_tracer_provider(tracer_provider)
meter_provider = MeterProvider( metric_readers=[PeriodicExportingMetricReader(OTLPMetricExporter())])metrics.set_meter_provider(meter_provider)
# 2. Register the GenAI instrumentation, then create Genkitconfigure_instrumentation(GenAiInstrumentation(emit_tool_spans=True))
ai = Genkit(plugins=[GoogleAI()], model=GoogleAI.gemini('gemini-flash-latest'))
async def main() -> None: # 3. Generate, then flush spans and metrics response = await ai.generate(prompt='Explain OpenTelemetry in one sentence.') print(response.text) # => OpenTelemetry is a vendor-neutral standard for traces, metrics, and logs. tracer_provider.shutdown() meter_provider.shutdown()
asyncio.run(main())Point it at a collector with the usual environment variables, no code change:
export OTEL_SERVICE_NAME=my-serviceexport OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318The EVENT_ONLY and SPAN_AND_EVENT content modes also need an SDK
LoggerProvider with a log exporter.
Some properties to know before you deploy:
- The Developer UI keeps working. Under
genkit start, the Developer UI’s own provider exports to a separate pipeline, so it keeps showing Genkit’s traces next to this export. - Without an SDK, it does nothing. When no
TracerProvideris recording, spans and instruments are no-ops. The first span logs one warning that nothing is exported. - It composes with Google Cloud telemetry.
enable_google_cloud_telemetry()is built onGenAiInstrumentation. If you register one first, it keeps yours instead of adding its own, and still redacts content attributes on the spans it sends to Cloud Trace.
Capturing message content
Section titled “Capturing message content”Prompts and responses can contain PII, so content capture is off by default.
The mode mirrors the spec’s ContentCapturingMode:
| Mode | Where content goes |
|---|---|
noContent (default) | Not captured. |
spanOnly | Span attributes gen_ai.input.messages, gen_ai.output.messages, and gen_ai.system_instructions, as JSON strings. |
eventOnly | A gen_ai.client.inference.operation.details log record. |
spanAndEvent | Both. |
In Python, the modes are the ContentCapturingMode string values
'NO_CONTENT', 'SPAN_ONLY', 'EVENT_ONLY', and 'SPAN_AND_EVENT':
from genkit.telemetry import configure_instrumentationfrom genkit_otel import GenAiInstrumentation
configure_instrumentation( GenAiInstrumentation(content_capturing_mode='SPAN_ONLY') # May contain PII.)Left unset, the value comes from the
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable using
the same tokens, case-insensitive. An unrecognized token in the variable logs
one warning and falls back to NO_CONTENT. An explicit argument overrides the
variable, so 'NO_CONTENT' is a hard opt-out; an unrecognized argument raises
ValueError. With emit_tool_spans=True, content also covers tool call
arguments and results (gen_ai.tool.call.arguments,
gen_ai.tool.call.result).
Options
Section titled “Options”GenAiInstrumentation(...) takes keyword-only arguments:
content_capturing_mode(default: env, else'NO_CONTENT'): where spec-shapedgen_ai.*message content is recorded.capture_action_io(defaultFalse): records raw Genkit input and output asgenkit.input/genkit.outputon every span. A debugging aid, independent ofcontent_capturing_mode. May contain PII.emit_tool_spans(defaultFalse):execute_toolspans for tool actions.emit_metrics(defaultTrue): emits the token usage and operation duration metrics.scope_name(default'genkit-genai'): instrumentation scope for the tracer, meter, and logger.tracer,meter,otel_logger(default: resolved lazily from the globals): explicit OpenTelemetry instruments, for when you do not want the global providers.
GenAiInstrumentation.CONTENT_ATTRIBUTES is the set of span attribute keys that
can hold prompt, reply, or tool payload text. Use it in a custom exporter that
must drop content.
Try it
Section titled “Try it”The otel-jaeger sample
is a runnable end-to-end setup: traces to Jaeger and metrics to a collector.