GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(opencode): bridge global OTel tracer for AI SDK telemetry by kitlangton · Pull Request #21799 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a lightweight BasicTracerProvider bridge (src/otel-bridge.ts) that registers a global OTel tracer when OTEL_EXPORTER_OTLP_ENDPOINT is set
  • Enables AI SDK's experimental_telemetry spans to be exported alongside Effect's own OTLP spans (added in feat(opencode): add OTLP observability support #21387)
  • Turns on recordInputs/recordOutputs on both streamText (llm.ts) and generateObject (agent.ts) call sites so full prompt/response content is captured as span attributes
  • Telemetry auto-enables when the OTLP endpoint env var is set — no separate config flag needed
  • Zero runtime cost when OTEL_EXPORTER_OTLP_ENDPOINT is unset (dynamic imports, conditional init)

How it works

Effect's Otlp.layerJson instruments Effect services but uses an internal fiber-scoped tracer — it does NOT register a global TracerProvider. The AI SDK's experimental_telemetry reads from @opentelemetry/api's global tracer, so without a global provider its spans are silently dropped.

This bridge fills the gap with BasicTracerProvider from @opentelemetry/sdk-trace-base (much lighter than @opentelemetry/sdk-node) exporting via OTLPTraceExporter (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:

  • Effect spans: Session.create, Tool.run, Provider.chat, etc.
  • AI SDK spans: ai.streamText, ai.streamText.doStream, ai.toolCall
  • Message content (via recordInputs/recordOutputs): ai.prompt, ai.response.text, ai.toolCall.args, ai.toolCall.result, ai.usage.*
  • Metadata: ai.telemetry.metadata.userId, ai.telemetry.metadata.sessionId

Works 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 attributes

Related

  • feat(opencode): add OTLP observability support #21387 — Effect OTLP layer (already merged, complements this)
  • feat(telemetry): add OpenTelemetry instrumentation with Aspire Dashboard support #6629 — Luke's comprehensive Aspire integration (draft, much broader scope — this PR is the minimal bridge)
  • add experimental.open_telemetry config option to enable OTEL spans #4978, feat(telemetry): Add userId and sessionId metadata to experimental_telemetry #5279, fix(telemetry): restore userId and sessionId metadata in experimental_telemetry #8195 — original experimental_telemetry work

Test plan

  • Set OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318, run Jaeger/Aspire/leto, verify AI SDK spans appear with message content
  • Verify Effect spans still export correctly
  • Verify zero overhead when env var is unset (no OTel packages loaded)
  • bun run typecheck passes across all 13 packages

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitlangton
feat(opencode): bridge global OTel tracer for AI SDK telemetry
c5b5d17
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.
@github-actions github-actions Bot added Vouched contributor labels Apr 10, 2026
@kitlangton kitlangton closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor Vouched

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@kitlangton
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.