1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! 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](https://opentelemetry.io/docs/specs/otel/trace/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:
//!
//! ```toml
//! [dependencies]
//! opentelemetry = { version = "0.29.1", features = ["trace"] }
//! opentelemetry_sdk = { version = "0.29.0", features = ["trace"] }
//! sentry = { version = "0.38.0", features = ["opentelemetry"] }
//! ```
//!
//! Initialize Sentry with a `traces_sample_rate`, then register the [`SentryPropagator`] and the
//! [`SentrySpanProcessor`]:
//!
//! ```
//! use opentelemetry::{
//! global,
//! trace::{TraceContextExt, Tracer},
//! KeyValue,
//! };
//! use opentelemetry_sdk::trace::SdkTracerProvider;
//! use sentry::integrations::opentelemetry as sentry_opentelemetry;
//!
//! // Initialize the Sentry SDK
//! let _guard = sentry::init((
//! "https://your-dsn@sentry.io/0",
//! sentry::ClientOptions::new()
//! // Enable capturing of traces; set this a to lower value in production.
//! // For more sophisticated behavior use a custom
//! // [`sentry::ClientOptions::traces_sampler`] instead.
//! // That's the equivalent of a tail sampling processor in OpenTelemetry.
//! // These options will only affect sampling of the spans that are sent to Sentry,
//! // not of the underlying OpenTelemetry spans.
//! .traces_sample_rate(1.0)
//! .debug(true),
//! ));
//!
//! // Register the Sentry propagator to enable distributed tracing
//! global::set_text_map_propagator(sentry_opentelemetry::SentryPropagator::new());
//!
//! let tracer_provider = SdkTracerProvider::builder()
//! // Register the Sentry span processor to send OpenTelemetry spans to Sentry
//! .with_span_processor(sentry_opentelemetry::SentrySpanProcessor::new())
//! .build();
//!
//! global::set_tracer_provider(tracer_provider);
//! ```
//!
//! # Usage
//!
//! Use the OpenTelemetry API to create spans. They will be captured by Sentry:
//!
//! ```
//! # use opentelemetry::{
//! # global,
//! # trace::{TraceContextExt, Tracer},
//! # KeyValue,
//! # };
//!
//! let tracer = global::tracer("tracer");
//! // Creates a Sentry span (transaction) with the name set to "example"
//! tracer.in_span("example", |_| {
//! // Creates a Sentry child span with the name set to "child"
//! tracer.in_span("child", |cx| {
//! // OTEL span attributes are captured as data attributes on the Sentry span
//! cx.span().set_attribute(KeyValue::new("my", "attribute"));
//!
//! // Captures a Sentry error message and associates it with the ongoing child span
//! sentry::capture_message("Everything is on fire!", sentry::Level::Error);
//! });
//! });
//! ```
pub use *;
pub use *;