Repository navigation
LOU-K4: ship a bundled, opt-in OpenTelemetry TraceExporter - #14
Merged
Merged
Conversation
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>
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
examples/tracing/run-otel.tsevery time.createOtelTraceExporter()(src/execution/otel.ts), exported via a new@loushy/build-ai-agent/otelsubpath, implementingTraceExporterby translating this SDK'sSpanshape into real OpenTelemetry spans via@opentelemetry/api'strace.getTracer(...), propagating parent/child relationships through OTel's context API.@opentelemetry/api), never a concrete SDK/exporter backend (sdk-trace-node/sdk-trace-basestay dev-only, used solely by the example's own local span processor setup) - the host app still supplies its ownTracerProvider.@opentelemetry/apimoved fromdevDependenciestopeerDependencies(optional, viapeerDependenciesMeta, matching the existing pattern for@ai-sdk/openaietc.) since it's now something a consumer of this new subpath needs installed.examples/tracing/run-otel.tsupdated to use the bundled exporter instead of the hand-rolled adapter;examples/tracing/otel-exporter.tsremoved since its logic moved intosrc/execution/otel.ts.docs/api-overview.mdupdated to recommend the bundled exporter for real OTel integration, while keepingwithSpan()/TraceExporterdocumented as the underlying BYO-exporter extensibility point.Test plan
npm run typecheck- cleannpm run lint- clean on all touched files (pre-existing unrelated warnings/errors insrc/execution/__fixtures__/sample-repo/*,src/tools/built-in/index.test.ts,src/utils/errors.tsare untouched by this change)npx vitest run src/execution/otel.test.ts- 6/6 passingnpx 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 correctlynpm run example:tracing:otel- runs end-to-end, emits realagent.run->llm.generate/tool.callOTel spans viaConsoleSpanExporternpm run docs:verify-snippets- all 5 snippets still pass🤖 Generated with Claude Code