Sentry Rust SDK: sentry-opentelemetry
OpenTelemetry support for Sentry.
This integration allows you to capture spans from your existing OpenTelemetry setup and send them to Sentry, with support for distributed tracing.
It's assumed that only the OpenTelemetry tracing
API is used to start/end/modify Spans.
Mixing it with the Sentry tracing API (e.g. sentry_core::start_transaction(ctx)) will not
work, as the spans created with the two methods will not be nested properly.
Capturing events with sentry::capture_event will send them to Sentry with the correct
trace and span association.
Configuration
Add the necessary dependencies to your Cargo.toml:
[]
= { = "0.29.1", = ["trace"] }
= { = "0.29.0", = ["trace"] }
= { = "0.38.0", = ["opentelemetry"] }
Initialize Sentry with a traces_sample_rate, then register the [SentryPropagator] and the
[SentrySpanProcessor]:
use ;
use SdkTracerProvider;
use opentelemetry as sentry_opentelemetry;
// Initialize the Sentry SDK
let _guard = init;
// Register the Sentry propagator to enable distributed tracing
set_text_map_propagator;
let tracer_provider = builder
// Register the Sentry span processor to send OpenTelemetry spans to Sentry
.with_span_processor
.build;
set_tracer_provider;
Usage
Use the OpenTelemetry API to create spans. They will be captured by Sentry:
let tracer = tracer;
// Creates a Sentry span (transaction) with the name set to "example"
tracer.in_span;
Resources
License: MIT
- Discord server for project discussions.
- Follow @getsentry on Twitter for updates