Skip to main content
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 with id=<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 value log_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

  1. 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.
  2. Log feedback using the same ID with logger.log_feedback(id=trace_id, scores={...}).
  3. Flush the logger to ensure events are sent.
Minimal Python example: Use your existing OpenTelemetry span as otel_span. Format its trace ID as a string and pass the same value to both helpers.
Notes for this option:
  • Use one root row per external trace ID. Reusing the same id for a new root span can replace the existing row.
  • Do not overwrite the SDK-managed root_span_id field. Set only the span row id on the root span.

Option 2: Map existing Braintrust row IDs to your trace IDs

  1. If Braintrust already generated row IDs, maintain a mapping from your trace_id to the Braintrust row ID.
  2. 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:
  1. Use the root row ID returned by the query or retrieved from your stored mapping. Then call logger.log_feedback with that row ID:
When to prefer this option:
  • 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 show otel_trace_id in 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_id SDK-managed as recommended in the tracing docs. Setting the root row id on 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_id to handle existing traces that already have Braintrust-generated row IDs. The SQL lookup requires the external ID to have been stored in that field.