feat(opencode): bridge global OTel tracer for AI SDK telemetry#21799
Draft
kitlangton wants to merge 1 commit intodevfrom
Draft
feat(opencode): bridge global OTel tracer for AI SDK telemetry#21799kitlangton wants to merge 1 commit intodevfrom
kitlangton wants to merge 1 commit intodevfrom
Conversation
The existing Effect Otlp.layerJson (merged via #21387) instruments Effect services but does not register a global OTel tracer provider. The AI SDK's experimental_telemetry reads from the global provider, so its spans were silently dropped. This adds a lightweight BasicTracerProvider bridge that registers globally when OTEL_EXPORTER_OTLP_ENDPOINT is set, using the same endpoint and headers the Effect layer already reads. AI SDK spans (ai.streamText, ai.toolCall, prompt/response content, token counts) now export alongside Effect service spans to any OTLP/HTTP collector. Also enables recordInputs/recordOutputs on both streamText and generateObject call sites so full message content is captured as span attributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BasicTracerProviderbridge (src/otel-bridge.ts) that registers a global OTel tracer whenOTEL_EXPORTER_OTLP_ENDPOINTis setexperimental_telemetryspans to be exported alongside Effect's own OTLP spans (added in feat(opencode): add OTLP observability support #21387)recordInputs/recordOutputson bothstreamText(llm.ts) andgenerateObject(agent.ts) call sites so full prompt/response content is captured as span attributesOTEL_EXPORTER_OTLP_ENDPOINTis unset (dynamic imports, conditional init)How it works
Effect's
Otlp.layerJsoninstruments Effect services but uses an internal fiber-scoped tracer — it does NOT register a globalTracerProvider. The AI SDK'sexperimental_telemetryreads from@opentelemetry/api's global tracer, so without a global provider its spans are silently dropped.This bridge fills the gap with
BasicTracerProviderfrom@opentelemetry/sdk-trace-base(much lighter than@opentelemetry/sdk-node) exporting viaOTLPTraceExporter(HTTP/JSON) to the same endpoint. Both trace streams land in the same collector.What you get
With
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 opencode:Session.create,Tool.run,Provider.chat, etc.ai.streamText,ai.streamText.doStream,ai.toolCallrecordInputs/recordOutputs):ai.prompt,ai.response.text,ai.toolCall.args,ai.toolCall.result,ai.usage.*ai.telemetry.metadata.userId,ai.telemetry.metadata.sessionIdWorks with any OTLP/HTTP collector — Jaeger, Aspire, SigNoz, Grafana Tempo, or a local dev tool like leto.
New deps
@opentelemetry/sdk-trace-base—BasicTracerProvider+BatchSpanProcessor@opentelemetry/exporter-trace-otlp-http— OTLP/HTTP JSON exporter@opentelemetry/api— global tracer registration@opentelemetry/resources+@opentelemetry/semantic-conventions— service resource attributesRelated
experimental_telemetryworkTest plan
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318, run Jaeger/Aspire/leto, verify AI SDK spans appear with message contentbun run typecheckpasses across all 13 packages