feat(evals): wire opt-in OTEL transport (EVAL_TRACE_TRANSPORT=otel; native unchanged)#2353
Open
miguelg719 wants to merge 2 commits into
Open
Conversation
|
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Confidence score: 5/5
- Safe to merge after the addressed issues were fixed.
Architecture diagram
sequenceDiagram
participant CLI as CLI / Signal Handler
participant Runner as runner.ts
participant Braintrust as braintrust.ts (tracedSpan)
participant OTEL as @opentelemetry/api (OtelSpan)
participant AISDK as AISdkClientWrapped
participant BraintrustAPI as Braintrust Backend
participant OTELExporter as OTEL Exporter
Note over CLI,OTELExporter: OTEL Transport (EVAL_TRACE_TRANSPORT=otel)
Runner->>Runner: resolveTraceTransport() => "otel"
Runner->>OTEL: buildTracerProvider()
OTEL-->>Runner: provider ready
Runner->>Braintrust: tracedSpan(fn, options)
alt EVAL_TRACE_TRANSPORT equals otel
Braintrust->>OTEL: getTracer().startActiveSpan(name)
OTEL-->>Braintrust: active OtelSpan
Braintrust->>OTEL: setAttribute(type, input.*)
Braintrust->>fn: call with OTEL adapter
fn->>AISDK: createChatCompletion()
AISDK->>AISDK: loadAISDK() (no wrapAISDK)
AISDK->>AISDK: pass experimental_telemetry block
Note over AISDK: generates OTEL spans for generateObject/generateText
AISDK-->>fn: response
fn->>Braintrust: adapter.log({output, scores, metadata, ...})
Braintrust->>OTEL: setAttribute(metadata.*, metrics.*)
Braintrust->>OTEL: addEvent("scores", ...)
Braintrust->>OTEL: addEvent("output", ...)
alt error in fn
Braintrust->>OTEL: setStatus(ERROR)
Braintrust->>OTEL: recordException(error)
Braintrust-->>Runner: throw error
else success
Braintrust->>OTEL: span.end()
Braintrust-->>Runner: return result
end
Runner->>Braintrust: flush() (Braintrust log)
Braintrust->>BraintrustAPI: send logs
Runner->>OTEL: shutdownTracing()
OTEL->>OTELExporter: export final spans
OTEL-->>Runner: done
else native (default)
Braintrust->>Braintrust: hasBraintrustApiKey()
alt has key
Braintrust->>BraintrustAPI: create Braintrust span
Braintrust-->>fn: Braintrust adapter
fn->>Braintrust: adapter.log(...)
Braintrust->>BraintrustAPI: log output/scores
else no key
Braintrust-->>fn: NOOP_SPAN
end
Braintrust-->>Runner: return result
end
Note over CLI,Runner: Signal teardown
CLI->>CLI: handleSignal(SIGINT)
CLI->>OTEL: shutdownTracing()
OTEL->>OTELExporter: final flush
CLI->>CLI: process.exit(code)
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
840c0e5 to
3055aa4
Compare
…unchanged) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…edSpan otel tests Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
c9a9f41 to
7e05a8a
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
Turns the OTEL fan-out on behind an opt-in flag. The native (default) path stays byte-identical — no keys/flags means today's behavior exactly.
what changed
framework/braintrust.ts:tracedSpangains an otel branch — opens an OTEL active span, adaptsspan.log({output,scores,metrics,metadata})→setAttribute/addEvent; native +NOOP_SPANbranches untouched, signature unchanged (verifier/runner call sites need zero edits)lib/AISdkClientWrapped.ts:EVAL_TRACE_TRANSPORT=otel→experimental_telemetry(nowrapAISDK); native path verbatimframework/runner.ts: provider init at run start;shutdownTracing()after the Braintrust flushcli.ts: best-effort flush on signal teardowntest plan
braintrust-optional/braintrust-runner-nologpass unchanged (native invariant)EVAL_TRACE_TRANSPORT=otel LANGSMITH_TRACING=truedual-backend run (env: browserbase) — spans land in both UIs;.trajectories/identical to nativeStack 3/5 · base: #2352
🤖 Generated with Claude Code
Summary by cubic
Adds an opt-in OpenTelemetry transport for eval traces via
EVAL_TRACE_TRANSPORT=otel. Native Braintrust tracing stays the default and unchanged.New Features
framework/braintrust.ts:tracedSpanadds an OTEL path that maps inputs/metadata/metrics to attributes and outputs/scores to events; records errors; native path untouched.framework/runner.ts: builds the tracer provider at run start with a project-aware parent (project_name:*) when OTEL is enabled.cli.ts: best-effortshutdownTracing()on signal teardown.lib/AISdkClientWrapped.ts: whenEVAL_TRACE_TRANSPORT=otel, call the SDK directly and passexperimental_telemetryforgenerateObject/generateText; native wrapping otherwise.Bug Fixes
framework/runner.ts: always callsshutdownTracing()in afinallyblock to avoid leaks.tracedspan-otel.test.tsto verify attribute/event mapping and error recording.Written for commit 7e05a8a. Summary will update on new commits.