feat(evals): add OTEL tracer-provider module + deps (unwired)#2352
Open
miguelg719 wants to merge 2 commits into
Open
feat(evals): add OTEL tracer-provider module + deps (unwired)#2352miguelg719 wants to merge 2 commits into
miguelg719 wants to merge 2 commits into
Conversation
|
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Confidence score: 5/5
- Safe to merge after the addressed issues were fixed.
Architecture diagram
sequenceDiagram
participant Caller as Eval Runner (future)
participant Builder as buildTracerProvider()
participant Init as initializeTracerProvider()
participant Env as Environment Variables
participant BTExporter as OTLPTraceExporter (Braintrust)
participant LSExporter as LangSmithOTLPTraceExporter
participant Provider as NodeTracerProvider
Note over Caller,Provider: NEW: OTEL Tracer Provider Initialization
Caller->>Builder: buildTracerProvider()
Builder->>Env: EVAL_TRACE_TRANSPORT
alt Transport != "otel"
Env-->>Builder: "native" or other
Builder-->>Caller: null (no-op)
else Transport == "otel"
Env-->>Builder: "otel"
Builder->>Init: initializeTracerProvider() (memoized)
Init->>Env: BRAINTRUST_API_KEY?
alt Key set
Env-->>Init: key present
Init->>Env: BRAINTRUST_OTEL_URL? else default url
Init->>Env: BRAINTRUST_OTEL_PARENT? else project_name:stagehand-dev (or stagehand in CI)
Init->>BTExporter: new OTLPTraceExporter(url, headers)
BTExporter-->>Init: exporter instance
Init->>Init: create BatchSpanProcessor(exporter)
else Key missing
Env-->>Init: no key
end
Init->>Env: LANGSMITH_API_KEY && LANGSMITH_TRACING=="true"?
alt Both set
Env-->>Init: keys set
Init->>LSExporter: new LangSmithOTLPTraceExporter()
LSExporter-->>Init: exporter instance
Init->>Init: create BatchSpanProcessor(exporter)
else Missing
Env-->>Init: not set
end
alt spanProcessors.length > 0
Init->>Provider: new NodeTracerProvider({ spanProcessors })
Provider->>Provider: register() (global)
Provider-->>Init: provider instance
Init-->>Builder: provider
else No processors
Init-->>Builder: null
end
Builder-->>Caller: provider or null
end
Note over Caller,Provider: Shutdown flow
Caller->>Builder: shutdownTracing()
Builder->>Env: EVAL_TRACE_TRANSPORT == "otel"?
alt Not otel or provider null
Builder-->>Caller: return (no-op)
else Valid provider
Builder->>Provider: forceFlush()
Provider-->>Builder: ok
Builder->>Provider: shutdown()
Provider-->>Builder: ok
Builder->>Builder: reset provider to null
Builder-->>Caller: done
end
Note over Caller,Provider: Tracer retrieval
Caller->>Builder: getTracer()
alt provider exists
Provider-->>Builder: tracer from provider
else No provider
Builder-->>Caller: ProxyTracerProvider noop tracer
end
Builder-->>Caller: Tracer
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tional braintrustParent for provider init Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
840c0e5 to
3055aa4
Compare
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.
why
The fan-out core for the opt-in OTEL transport: one
NodeTracerProviderwhose span processors route eval traces to Braintrust and LangSmith, each gated on its own key. Unwired — imported by nothing yet.what changed
framework/otel.ts(new):buildTracerProvider()(memoized; null unlessEVAL_TRACE_TRANSPORT=otel; per-backend gated processors),getTracer(), null-safeshutdownTracing()(forceFlush+shutdown, 10s timeout)@opentelemetry/{api,sdk-trace-base,sdk-trace-node}depstests/framework/otel.test.ts(new): native→null; both keys→2 processors; each alone→1test plan
Stack 2/5 · base: #2351
🤖 Generated with Claude Code
Summary by cubic
Adds an opt-in OpenTelemetry tracer provider for evals that can fan out spans to Braintrust and/or LangSmith, gated by their own keys. The module is added but not wired yet, and shutdown now tolerates forceFlush failures.
New Features
framework/otel.tswithbuildTracerProvider(); returns null unlessEVAL_TRACE_TRANSPORT=otel.BRAINTRUST_API_KEYis set (supportsBRAINTRUST_OTEL_PARENT,BRAINTRUST_OTEL_URL, or an initbraintrustParentoverride) and LangSmith whenLANGSMITH_API_KEYis set andLANGSMITH_TRACING=true.getTracer()andshutdownTracing()(10s timeout); shutdown proceeds even ifforceFlushrejects; tests cover native mode, single/dual-backend setups, and shutdown behavior.Dependencies
@opentelemetry/api,@opentelemetry/exporter-trace-otlp-proto,@opentelemetry/sdk-trace-base,@opentelemetry/sdk-trace-node.Written for commit 3055aa4. Summary will update on new commits.