Skip to content

LOU-K4: ship a bundled, opt-in OpenTelemetry TraceExporter - #14

Merged
LinuxDevil merged 1 commit into
mainfrom
loushy/lou-k4
Sep 28, 2026
Merged

LinuxDevil merged 1 commit into
mainfrom
loushy/lou-k4

Conversation

@LinuxDevil

Copy link
Copy Markdown
Owner

Summary

  • The published feature-matrix audit flags tracing as "span hooks with BYO-exporter, not bundled OTel" - users had to hand-roll the OTel adapter shown in examples/tracing/run-otel.ts every time.
  • Adds createOtelTraceExporter() (src/execution/otel.ts), exported via a new @loushy/build-ai-agent/otel subpath, implementing TraceExporter by translating this SDK's Span shape into real OpenTelemetry spans via @opentelemetry/api's trace.getTracer(...), propagating parent/child relationships through OTel's context API.
  • Only depends on the OTel API (@opentelemetry/api), never a concrete SDK/exporter backend (sdk-trace-node/sdk-trace-base stay dev-only, used solely by the example's own local span processor setup) - the host app still supplies its own TracerProvider.
  • @opentelemetry/api moved from devDependencies to peerDependencies (optional, via peerDependenciesMeta, matching the existing pattern for @ai-sdk/openai etc.) since it's now something a consumer of this new subpath needs installed.
  • examples/tracing/run-otel.ts updated to use the bundled exporter instead of the hand-rolled adapter; examples/tracing/otel-exporter.ts removed since its logic moved into src/execution/otel.ts.
  • docs/api-overview.md updated to recommend the bundled exporter for real OTel integration, while keeping withSpan()/TraceExporter documented as the underlying BYO-exporter extensibility point.
  • The published audit artifact itself was intentionally left untouched (out of scope for this ticket).

Test plan

  • npm run typecheck - clean
  • npm run lint - clean on all touched files (pre-existing unrelated warnings/errors in src/execution/__fixtures__/sample-repo/*, src/tools/built-in/index.test.ts, src/utils/errors.ts are untouched by this change)
  • npx vitest run src/execution/otel.test.ts - 6/6 passing
  • npx vitest run src/execution - 189/189 passing (full execution suite, no regressions)
  • npm run build - dist/execution/otel.{js,mjs,d.ts,d.mts} emitted correctly
  • npm run example:tracing:otel - runs end-to-end, emits real agent.run -> llm.generate/tool.call OTel spans via ConsoleSpanExporter
  • npm run docs:verify-snippets - all 5 snippets still pass

🤖 Generated with Claude Code

Adds createOtelTraceExporter() (src/execution/otel.ts), exported via a
new "@loushy/build-ai-agent/otel" subpath, so consumers no longer have
to hand-roll the Span -> OTel span bridge shown in
examples/tracing/run-otel.ts every time. It only depends on
@opentelemetry/api (now an optional peer dependency, moved out of
devDependencies), never a concrete OTel SDK/exporter backend, so the
host app still supplies its own TracerProvider.

- src/execution/otel.ts: createOtelTraceExporter({ tracerName,
  tracerVersion, tracer }) implementing TraceExporter, translating
  Span start/end + parentId into real OTel spans/context.
- src/execution/otel.test.ts: unit tests against a fake OTel Tracer
  covering span naming/timing, attribute translation (primitives kept,
  objects stringified), span end/attribute merge, parent/child context
  threading, and the default trace.getTracer(...) resolution path.
- package.json: new "./otel" exports entry; @opentelemetry/api moved
  to peerDependencies (optional) instead of devDependencies only.
- tsup.config.ts: new execution/otel entry point, @opentelemetry/api
  externalized.
- examples/tracing/run-otel.ts: now uses createOtelTraceExporter()
  instead of the local hand-rolled adapter; examples/tracing/otel-exporter.ts
  removed as its logic moved into src/execution/otel.ts.
- docs/api-overview.md: documents the bundled exporter as the
  recommended path for real OTel integration, with TraceExporter/
  withSpan() still documented as the underlying BYO-exporter interface.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@LinuxDevil
LinuxDevil merged commit aa92c70 into main Sep 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant