Genkit Go
Genkit Go writes OpenTelemetry spans with GenAI attributes when you register its otelgenai plugin, and cetra reads those spans. This page is setup only: no Genkit program was run, and every fact comes from the plugin’s source and documentation.
Install
Section titled “Install”go get github.com/firebase/genkit/go@v1.14.0go get go.opentelemetry.io/otel@v1.46.0 go.opentelemetry.io/otel/sdk@v1.46.0go get go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp@v1.46.0Set up
Section titled “Set up”The application owns the OpenTelemetry SDK. Export over OTLP/HTTP with the standard variables, and set a service name so your traces are named:
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8080export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer sk-cetra-…"export OTEL_SERVICE_NAME=my-appRegister the plugin, then call models as usual:
ctx := context.Background()exp, err := otlptracehttp.New(ctx) // go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttpif err != nil { log.Fatal(err)}tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exp))otel.SetTracerProvider(tp)defer tp.Shutdown(ctx)tracing.SetInstrumentation(otelgenai.New(&otelgenai.Options{ ContentCapturingMode: otelgenai.SpanOnly, EmitToolSpans: true,}))
plugin := &oai.OpenAI{APIKey: os.Getenv("OPENAI_API_KEY")} // github.com/firebase/genkit/go/plugins/compat_oai/openaig := genkit.Init(ctx, genkit.WithPlugins(plugin), genkit.WithDefaultModel("openai/gpt-5.4"))resp, err := genkit.Generate(ctx, g, ai.WithPrompt("What is the weather in Lyon?"))_ = resp.Text()- Set the global tracer provider before
otelgenai.New(...): the plugin resolves its tracer once, whenNewruns. - Registering the plugin replaces Genkit’s own default instrumentation. To keep Genkit’s
genkit:*spans as well, the plugin’s README saysOTelInstrumentationmust be listed too. - Add provider plugins such as
oai.OpenAItogenkit.Init;otelgenaitakes no Genkit instance.
Content is off by default. Turn it on with ContentCapturingMode, or leave the option unset and set OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to NO_CONTENT, SPAN_ONLY, EVENT_ONLY or SPAN_AND_EVENT; the variable is read only when the option is empty. Use SPAN_ONLY: it writes gen_ai.input.messages, gen_ai.output.messages and gen_ai.system_instructions on the span, which cetra reads. EVENT_ONLY and SPAN_AND_EVENT write the content to a log event, which cetra does not read.
What you get
Section titled “What you get”- An
llmspan namedchat <model>for each model call, with the provider derived from the model’s prefix (openai/gpt-5.4givesopenai), the request model, the finish reasons and the token counts; cetra computes the cost from the built-in prices. - A
toolspan namedexecute_tool <name>for each tool call, whenEmitToolSpansis on. - With
SPAN_ONLY, the input and output messages and the system instructions on thellmspans. - Other Genkit actions become plain spans carrying
genkit.action.type.
Limits
Section titled “Limits”- Not captured: written from the library’s source and documentation. No Genkit Go program was run.
- Content is off by default. cetra reads it only from spans (
SPAN_ONLY); theEVENT_ONLYandSPAN_AND_EVENTmodes write log records, which cetra drops. - Tool spans need
EmitToolSpans: true. - No
gen_ai.response.modelis written: cetra shows the request model only. - The plugin also emits
gen_ai.client.token.usageandgen_ai.client.operation.durationmetrics by default. cetra reads traces only; setDisableMetrics: trueto turn them off. - This page was written against Genkit Go v1.14.0 and OpenTelemetry Go v1.46.0.
- Send OpenTelemetry: the endpoint and the headers cetra expects.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.