Skip to main content

genkit-otel

OpenTelemetry instrumentation and backend for Genkit.

It provides GenAiInstrumentation: OpenTelemetry GenAI semantic-conventions instrumentation emitting gen_ai.* spans and metrics.

Pass tracer to mint on that tracer instead of the process-global one.

GenAI Semantic Conventions Instrumentation

Plugs into Genkit's pluggable instrumentation system and emits telemetry that follows the OTel GenAI semantic conventions:

  • gen_ai.* client spans for model operations (chat <model>), with request config, token usage, and finish reasons.
  • The GenAI client metrics gen_ai.client.token.usage (split by gen_ai.token.type) and gen_ai.client.operation.duration.
  • Optional message-content capture, either as span attributes or a dedicated gen_ai.client.inference.operation.details event.
  • Optional execute_tool spans, and generic spans for other Genkit action types so the trace tree stays connected.

Usage

The application owns the OpenTelemetry SDK and picks its exporter. Install them alongside this package:

pip install genkit-otel opentelemetry-sdk opentelemetry-exporter-otlp

Initialize the SDK, then register the provider before creating Genkit:

from opentelemetry import trace
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

from genkit import Genkit
from genkit.telemetry import configure_instrumentation
from genkit_otel import GenAiInstrumentation

resource = Resource.create({SERVICE_NAME: 'my-service'})
provider = TracerProvider(resource=resource)
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)

configure_instrumentation(GenAiInstrumentation())

ai = Genkit()

When the SDK is not initialized, the provider is effectively a no-op.

Content capture (PII)

Prompt and response content may contain PII, so capture is off by default. content_capturing_mode is one of the spec tokens:

Mode Where content goes
NO_CONTENT (default) not captured
SPAN_ONLY span attributes (gen_ai.*.messages) as JSON strings
EVENT_ONLY a gen_ai.client.inference.operation.details log event
SPAN_AND_EVENT both
from genkit_otel import GenAiInstrumentation

GenAiInstrumentation(content_capturing_mode='SPAN_ONLY')

Or omit the token and set the env. Same four tokens. Same result:

export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY
GenAiInstrumentation()

A token on the constructor wins over the env var, including an explicit NO_CONTENT. Garbage in the env var warns and stays NO_CONTENT.

To annotate a config field or variable, import the type:

from genkit_otel import ContentCapturingMode

mode: ContentCapturingMode = 'SPAN_ONLY'

EVENT_ONLY emits content on the OpenTelemetry logs signal (a gen_ai.client.inference.operation.details log record), not on the span. Trace-only backends like Jaeger cannot display it (its GenAI tab reads span attributes; its "Trace Logs" tab reads span events, neither is the logs signal). Use SPAN_ONLY or SPAN_AND_EVENT for Jaeger, or a logs backend (e.g. Loki, Elasticsearch/OpenSearch) for EVENT_ONLY.

Options

Option Default Description
content_capturing_mode env var, else NO_CONTENT Where spec-shaped gen_ai.* message content is recorded.
capture_action_io False Capture raw Genkit input/output as genkit.input/genkit.output on every span (debugging / Dev UI).
emit_metrics True Emit token-usage and operation-duration metrics.
emit_tool_spans False Emit execute_tool spans for tool actions.
scope_name genkit-genai Instrumentation scope for tracer/meter/logger.
tracer / meter / otel_logger resolved lazily Escape hatches to inject explicit instances.

Example

See samples/otel-jaeger for a runnable sample that exports traces to Jaeger and metrics to a local collector. ./tool/telemetry.sh downloads Jaeger and otelcol-contrib and keeps them running.

Metadata

Release files for genkit-otel 0.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genkit-otel 0.13.0
File Size Uploaded Provenance Actions
genkit_otel-0.13.0.tar.gz 25.6 kB With provenance Details for genkit_otel-0.13.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for genkit-otel 0.13.0
File Interpreter ABI Platform Actions
genkit_otel-0.13.0-py3-none-any.whl Python 3 none any Details for genkit_otel-0.13.0-py3-none-any.whl

Total release size: 46.6 kB

Release files / genkit_otel-0.13.0.tar.gz

Download URL genkit_otel-0.13.0.tar.gz
Size 25.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9790c6c4cd5c3d46cef8fce62e5c84d67769c84ed5592a1488a99fe653707798
BLAKE2b-256 checksum
How to use checksums
5e84c43a996c811c9b13db0ffcb3d7b036163d1cc9d025c77a32205c95423d2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / genkit_otel-0.13.0-py3-none-any.whl

Download URL genkit_otel-0.13.0-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
203e3919198cc2553e6a39aa56e31ee7a92aafc9a09c6fd660ff25b50bef6404
BLAKE2b-256 checksum
How to use checksums
e57fd5c79cdda9416bf8a6188ad1b2b580e228ff9ba1ae55476899b952e2cf53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for genkit-otel 0.13.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for genkit_otel-0.13.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.13.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page