Skip to content

fix(mastra): use Mastra span id as Braintrust row id for logFeedback#2211

Draft
Cedric / ViaDézo1er (viadezo1er) wants to merge 1 commit into
mainfrom
cedric/logfeedback-row-id
Draft

fix(mastra): use Mastra span id as Braintrust row id for logFeedback#2211
Cedric / ViaDézo1er (viadezo1er) wants to merge 1 commit into
mainfrom
cedric/logfeedback-row-id

Conversation

@viadezo1er

Copy link
Copy Markdown
Contributor

BraintrustObservabilityExporter.onStart let SpanImpl auto-generate the
row id (this._id = eventId ?? idGenerator.getSpanId()), so the id was
unknowable to anyone outside the exporter. A Mastra user calling
logger.logFeedback({ id: }) — or Mastra's score-event
bus forwarding score.spanId — targeted a row that didn't exist, and the
feedback landed as a stray row instead of merging into the generation
it was meant to score.

Pass event: { id: exported.id } on startSpan so the Mastra span id is
used as the Braintrust row id, matching the upstream @mastra/braintrust
fix (mastra-ai/mastra#11927, fixes #11899). The Braintrust span_id is
left auto-generated so W3C trace-context propagation still works for
subspans; only the row id (which logFeedback/mergeRowBatch key on) is
aliased to the Mastra span id.

Adds js/src/wrappers/mastra.test.ts covering both the row-id aliasing
and a subsequent logFeedback merge.

Refs: mastra-ai/mastra#11927

BraintrustObservabilityExporter.onStart let SpanImpl auto-generate the
row id (this._id = eventId ?? idGenerator.getSpanId()), so the id was
unknowable to anyone outside the exporter. A Mastra user calling
logger.logFeedback({ id: <mastra span id> }) — or Mastra's score-event
bus forwarding score.spanId — targeted a row that didn't exist, and the
feedback landed as a stray row instead of merging into the generation
it was meant to score.

Pass event: { id: exported.id } on startSpan so the Mastra span id is
used as the Braintrust row id, matching the upstream @mastra/braintrust
fix (mastra-ai/mastra#11927, fixes #11899). The Braintrust span_id is
left auto-generated so W3C trace-context propagation still works for
subspans; only the row id (which logFeedback/mergeRowBatch key on) is
aliased to the Mastra span id.

Adds js/src/wrappers/mastra.test.ts covering both the row-id aliasing
and a subsequent logFeedback merge.

Refs: mastra-ai/mastra#11927
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