Applies to:
- Plan - Any
- Deployment - Any
- Use case - Link Braintrust root spans and user feedback to an external OpenTelemetry trace ID
Summary
Your OpenTelemetry trace ID can serve as the Braintrust root span row ID. Create the root span withid=<external_trace_id> and leave root_span_id SDK-managed. Call logger.log_feedback(id=<external_trace_id>, ...) to attach feedback to the same row.
What is happening
Braintrust creates a distinct root row ID for traces by default. That ID is the valuelog_feedback expects. Your OpenTelemetry trace ID is different. That prevents a single ID from linking logs, traces, and feedback.
When you create the root span via logger.start_span, the SDK accepts an explicit span row ID via the id parameter. Child spans should keep SDK-generated IDs. Reusing a row ID recreates or replaces the root row for that ID.
Fix or suggestion
Option 1: Use your OpenTelemetry trace ID as the root row ID (recommended)
- Create the root span with
logger.start_span(..., id=trace_id)and add the external ID to metadata. Keep child spans using the SDK defaults. - Log feedback using the same ID with
logger.log_feedback(id=trace_id, scores={...}). - Flush the logger to ensure events are sent.
otel_span. Format its trace ID as a string and pass the same value to both helpers.
- Use one root row per external trace ID. Reusing the same
idfor a new root span can replace the existing row. - Do not overwrite the SDK-managed
root_span_idfield. Set only the span rowidon the root span.
Option 2: Map existing Braintrust row IDs to your trace IDs
- If Braintrust already generated row IDs, maintain a mapping from your
trace_idto the Braintrust row ID. - Alternatively, if the external trace ID was already stored in
metadata.otel_trace_id, query Braintrust with SQL to find the root row. Example query condition:
- Use the root row ID returned by the query or retrieved from your stored mapping. Then call
logger.log_feedbackwith that row ID:
- You already have traces with Braintrust-generated row IDs and cannot recreate the root spans.
How to confirm it worked
- Create a root span with
id=<trace_id>and verify a root row exists with that ID in Logs. The row should showotel_trace_idin metadata if you set it. - Call
logger.log_feedback(id=<trace_id>, ...)and confirm the feedback appears on the same root row.
Notes
- Leave
root_span_idSDK-managed as recommended in the tracing docs. Setting the root rowidon the root span is safe for linking external trace IDs. - If you need Braintrust spans to share actual OpenTelemetry trace context beyond storing the ID in metadata, use the OpenTelemetry context sharing integration.
- Use a stored mapping or a SQL lookup on
metadata.otel_trace_idto handle existing traces that already have Braintrust-generated row IDs. The SQL lookup requires the external ID to have been stored in that field.