Sentry Support#
Unfortunately, Sentry does not fully support OpenTelemetry. Specifically, Sentry uses its own context format, which does not work well with Python implementations. The depth of cached spans is insufficient to properly bind to the root span.
OpenTelemetry Collector#
Fortunately, there is a workaround for exporting spans to Sentry. You just need to launch the opentelemetry-collector container, which will convert the traces to the Sentry format and export them according to the specified DSN.
-
Install opentelemetry-exporter-otlp to export spans via gRPC:
pip install opentelemetry-exporter-otlp -
Set up the
TracerProviderwith the gRPC exporter:1 2 3 4 5 6 7 8 9 10 11 12
from opentelemetry import trace from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter from opentelemetry.sdk.trace.export import BatchSpanProcessor resource = Resource.create(attributes={"service.name": "faststream"}) tracer_provider = TracerProvider(resource=resource) trace.set_tracer_provider(tracer_provider) exporter = OTLPSpanExporter(endpoint="http://localhost:4317") processor = BatchSpanProcessor(exporter) tracer_provider.add_span_processor(processor) -
Create an
otel.yamlconfiguration file with your SentryDSN:otel.yaml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
receivers: otlp: protocols: grpc: endpoint: 0.0.0.0:4317 exporters: sentry: dsn: "https://your-secret-dsn.com" service: pipelines: traces: receivers: [otlp] exporters: [sentry] -
Run the Docker container with the
opentelemetry-collector:docker-compose.yaml 1 2 3 4 5 6 7 8
services: otel-collector: image: otel/opentelemetry-collector-contrib:latest command: [ "--config=/etc/otel.yaml" ] volumes: - ./otel.yaml:/etc/otel.yaml ports: - "4317:4317"
Note
While this setup is somewhat limited due to the lack of full support from the sentry-sdk, your code remains independent of the tracing backend. You can switch to Tempo or Jaeger at any time by simply updating otel.yaml.
Visualization#
An example of a distributed trace visualization between two services in Sentry.
Alternatives#
If you're looking for a tracing and visualization system that is easy to configure and does not require additional infrastructure, consider Logfire.

