OpenTelemetry GenAI instrumentations
cetra reads the OpenTelemetry GenAI semantic conventions, so the official opentelemetry-instrumentation-* packages work with a plain OTLP exporter.
Point the exporter at cetra
Section titled “Point the exporter at cetra”Add an OTLP exporter to your provider, then instrument the library. This is the setup the fixtures were captured with, with the endpoint and the key changed.
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporterfrom opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentorfrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import BatchSpanProcessor
provider = TracerProvider()provider.add_span_processor( BatchSpanProcessor( OTLPSpanExporter( endpoint="http://localhost:8080/v1/traces", headers={"Authorization": "Bearer <SK_CETRA_KEY>"}, ) ))OpenAIInstrumentor().instrument(tracer_provider=provider)Replace <SK_CETRA_KEY> with your sk-cetra- API key. See Send OpenTelemetry for the endpoint and the ports.
What carries over
Section titled “What carries over”- The
gen_ai.operation.namedecides the span kind:chatandgenerate_contentarellm,embeddingsisembedding,execute_toolistool,invoke_agentisagent,retrievalisretrieverandinvoke_workflowischain. - Messages come from
gen_ai.input.messagesandgen_ai.output.messages, and when the span does not have them, from the operation-details event. The oldergen_ai.*.messageevents are read as well. - System instructions, tool definitions, the token counts including cache and reasoning tokens, request parameters and finish reasons are read.
- The time to first token is read from
gen_ai.response.time_to_first_chunk.
Limits
Section titled “Limits”- The captured fixtures are two Python packages:
opentelemetry-instrumentation-openai-v22.4b0 andopentelemetry-instrumentation-google-genai1.1b1. - Some instrumentations send prompts and completions as log events instead of span attributes. cetra drops log events, so those prompts do not arrive. Turn on the instrumentation’s option to record content on spans. See OTLP endpoint.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Online rules: score these traces automatically.