Skip to content

feat(sdk): Add trace-aware scorers - #2839

Open
Luca Forstner (lforst) wants to merge 2 commits into
mainfrom
lforst/dum-e/montreal-8fa661b65d
Open

Luca Forstner (lforst) wants to merge 2 commits into
mainfrom
lforst/dum-e/montreal-8fa661b65d

Conversation

@lforst

Copy link
Copy Markdown
Member
  • Add defineScorer so the same scoring function can run on its own or in an Eval.
    import { defineScorer } from "braintrust";
    
    // Score 1 when the output matches the expected value, or 0 otherwise.
    export default defineScorer(({ output, expected }) => Number(output === expected));
  • A worker can now set BRAINTRUST_TRACE_PARENT to attach new spans to the caller’s trace. Previously, it had to pass the parent explicitly. With this variable set, defineScorer signs in with the worker’s current credentials on each call and flushes trace data even if scoring fails.
  • Give this SDK version its own global state so it can run alongside older copies without sharing their logger or trace context.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T19:32:57.365542Z fd611b5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd611b5fdd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread js/src/logger/core.ts
}
}

const stateKey = Symbol.for("braintrust-state-v4");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Coordinate instrumentation ownership with the isolated state

When an older SDK copy registers provider instrumentation first, this new state key separates the newer copy's logger and current span, but instrumentation remains shared: instrumentation/registry.ts still deduplicates providers through braintrust.registry.global-hooks.v2, and the invocation hooks retain protocol version 2. Consequently, the newer copy skips registering its own tracing interceptors, and provider calls inside its traced() or defineScorer() callbacks execute the older copy's tracing functions against the older state. Those calls can become no-op spans or log to the older logger instead of joining the new trace. Coordinate instrumentation ownership with the state isolation so mixed-version processes retain correctly parented provider spans.

AGENTS.md reference: AGENTS.md:L53-L53

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

2 participants