Skip to content

enhance BraintrustSpanProcessor to support custom exporters#43

Open
colinbennettbrain wants to merge 1 commit intomainfrom
otel-custom-exporter
Open

enhance BraintrustSpanProcessor to support custom exporters#43
colinbennettbrain wants to merge 1 commit intomainfrom
otel-custom-exporter

Conversation

@colinbennettbrain
Copy link
Copy Markdown
Contributor

@colinbennettbrain colinbennettbrain commented Mar 5, 2026

This change makes BraintrustSpanProcessor support custom OpenTelemetry exporters in addition to the default Braintrust export path. Some users need to route traces through their existing OTEL pipeline (e.g. vendor-specific exporters, internal collectors, or multi-destination export) while still using Braintrust instrumentation. Previously, BraintrustSpanProcessor did not make that customization path explicit/easy.

  • Added exporter=None to:
    • BraintrustSpanProcessor(...)
    • add_braintrust_span_processor(...)
  • If exporter is provided, the processor uses it directly.
  • In that case, api_key, parent, api_url, and headers are ignored.
  • If exporter is not provided, behavior is unchanged (the default Braintrust OtelExporter is still created).

You can create your exporter as usual, then pass it via the new exporter argument.

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from braintrust.otel import BraintrustSpanProcessor

custom_exporter = OTLPSpanExporter(endpoint="http://localhost:4318/v1/traces")
processor = BraintrustSpanProcessor(exporter=custom_exporter)

Or with the helper:

from braintrust.otel import add_braintrust_span_processor
add_braintrust_span_processor(
    tracer_provider=provider,
    exporter=custom_exporter,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add more details to the PR description about why this change was needed, and what users have to now do to add custom exporters? This will be useful for the changelogs.

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