Skip to content

Commit c3987a6

Browse files
authored
docs: update docs including OTEL and other integrations (#790)
* docs: update docs including OTEL and other integrations * fix * fix * fix
1 parent 701c358 commit c3987a6

File tree

5 files changed

+177
-21
lines changed

5 files changed

+177
-21
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ This workspace contains various crates that provide support for logging events a
6060

6161
An integration for the `log` and `env_logger` crate.
6262

63+
- [sentry-opentelemetry](./sentry-opentelemetry)
64+
[![crates.io](https://img.shields.io/crates/v/sentry-opentelemetry.svg)](https://crates.io/crates/sentry-opentelemetry)
65+
[![docs.rs](https://docs.rs/sentry-opentelemetry/badge.svg)](https://docs.rs/sentry-opentelemetry)
66+
67+
An integration for the `opentelemetry` crate.
68+
6369
- [sentry-panic](./sentry-panic)
6470
[![crates.io](https://img.shields.io/crates/v/sentry-panic.svg)](https://crates.io/crates/sentry-panic)
6571
[![docs.rs](https://docs.rs/sentry-panic/badge.svg)](https://docs.rs/sentry-panic)

sentry-opentelemetry/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<p align="center">
2+
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
3+
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
4+
</a>
5+
</p>
6+
7+
# Sentry Rust SDK: sentry-opentelemetry
8+
9+
Support for capturing Sentry spans from OpenTelemetry spans.
10+
11+
Sentry spans are automatically captured from OpenTelemetry spans via `SentrySpanProcessor`.
12+
Distributed tracing is supported via `SentryPropagator`.
13+
Note that it's assumed that only the OTEL API is used to create and manage spans.
14+
Mixing the OTEL and Sentry tracing API will not work, and will result in separate traces being captured.
15+
Using the Sentry API for other purposes is supported.
16+
For example, capturing an error inside a span will correctly send it to Sentry with the span association.
17+
18+
If you're using `tracing-opentelemetry`, use `sentry-tracing` instead.
19+
20+
# Configuration
21+
22+
Add the necessary dependencies to your Cargo.toml:
23+
24+
```toml
25+
[dependencies]
26+
opentelemetry = { version = "0.29.1", features = ["trace"] }
27+
opentelemetry_sdk = { version = "0.29.0", features = ["trace"] }
28+
sentry = { version = "0.38.0", features = ["opentelemetry"] }
29+
```
30+
31+
Initialize Sentry with a `traces_sample_rate`, then register the [`SentryPropagator`] and the
32+
[`SentrySpanProcessor`]:
33+
34+
```rust
35+
use opentelemetry::{
36+
global,
37+
trace::{TraceContextExt, Tracer},
38+
KeyValue,
39+
};
40+
use opentelemetry_sdk::trace::SdkTracerProvider;
41+
use sentry::integrations::opentelemetry as sentry_opentelemetry;
42+
43+
// Initialize the Sentry SDK
44+
let _guard = sentry::init((
45+
"https://[email protected]/0",
46+
sentry::ClientOptions {
47+
// Enable capturing of traces; set this a to lower value in production.
48+
// For more sophisticated behavior use a custom
49+
// [`sentry::ClientOptions::traces_sampler`] instead.
50+
// That's the equivalent of a tail sampling processor in OpenTelemetry.
51+
// These options will only affect sampling of the spans that are sent to Sentry,
52+
// not of the underlying OpenTelemetry spans.
53+
traces_sample_rate: 1.0,
54+
debug: true,
55+
..sentry::ClientOptions::default()
56+
},
57+
));
58+
59+
// Register the Sentry propagator to enable distributed tracing
60+
global::set_text_map_propagator(sentry_opentelemetry::SentryPropagator::new());
61+
62+
let tracer_provider = SdkTracerProvider::builder()
63+
// Register the Sentry span processor to send OpenTelemetry spans to Sentry
64+
.with_span_processor(sentry_opentelemetry::SentrySpanProcessor::new())
65+
.build();
66+
67+
global::set_tracer_provider(tracer_provider);
68+
```
69+
70+
# Usage
71+
72+
Use the OpenTelemetry API to create spans. They will be captured by Sentry:
73+
74+
```rust
75+
let tracer = global::tracer("tracer");
76+
// Creates a Sentry span (transaction) with the name set to "example"
77+
tracer.in_span("example", |_| {
78+
// Creates a Sentry child span with the name set to "child"
79+
tracer.in_span("child", |cx| {
80+
// OTEL span attributes are captured as data attributes on the Sentry span
81+
cx.span().set_attribute(KeyValue::new("my", "attribute"));
82+
83+
// Captures a Sentry error message and associates it with the ongoing child span
84+
sentry::capture_message("Everything is on fire!", sentry::Level::Error);
85+
});
86+
});
87+
```
88+
89+
## Resources
90+
91+
License: MIT
92+
93+
- [Discord](https://discord.gg/ez5KZN7) server for project discussions.
94+
- Follow [@getsentry](https://twitter.com/getsentry) on Twitter for updates

sentry-opentelemetry/src/lib.rs

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,53 @@
22
//!
33
//! This integration allows you to capture spans from your existing OpenTelemetry setup and send
44
//! them to Sentry, with support for distributed tracing.
5+
//!
56
//! It's assumed that only the [OpenTelemetry tracing
67
//! API](https://opentelemetry.io/docs/specs/otel/trace/api/) is used to start/end/modify Spans.
78
//! Mixing it with the Sentry tracing API (e.g. `sentry_core::start_transaction(ctx)`) will not
89
//! work, as the spans created with the two methods will not be nested properly.
9-
//! Capturing events (either manually with e.g. `sentry::capture_event`, or automatically with e.g. the
10-
//! `sentry-panic` integration) will send them to Sentry with the correct trace and span
11-
//! association.
10+
//!
11+
//! Capturing events with `sentry::capture_event` will send them to Sentry with the correct
12+
//! trace and span association.
1213
//!
1314
//! # Configuration
1415
//!
15-
//! Initialize Sentry, then register the [`SentryPropagator`] and the [`SentrySpanProcessor`]:
16+
//! Add the necessary dependencies to your Cargo.toml:
17+
//!
18+
//! ```toml
19+
//! [dependencies]
20+
//! opentelemetry = { version = "0.29.1", features = ["trace"] }
21+
//! opentelemetry_sdk = { version = "0.29.0", features = ["trace"] }
22+
//! sentry = { version = "0.38.0", features = ["opentelemetry"] }
23+
//! ```
24+
//!
25+
//! Initialize Sentry with a `traces_sample_rate`, then register the [`SentryPropagator`] and the
26+
//! [`SentrySpanProcessor`]:
1627
//!
1728
//! ```
18-
//! use opentelemetry::{global};
19-
//! use opentelemetry_sdk::{
20-
//! propagation::TraceContextPropagator, trace::SdkTracerProvider,
29+
//! use opentelemetry::{
30+
//! global,
31+
//! trace::{TraceContextExt, Tracer},
32+
//! KeyValue,
2133
//! };
34+
//! use opentelemetry_sdk::trace::SdkTracerProvider;
35+
//! use sentry::integrations::opentelemetry as sentry_opentelemetry;
2236
//!
2337
//! // Initialize the Sentry SDK
24-
//! let _guard = sentry::init(sentry::ClientOptions {
25-
//! // Enable capturing of traces; set this a to lower value in production.
26-
//! // For more sophisticated behavior use a custom
27-
//! // [`sentry::ClientOptions::traces_sampler`] instead.
28-
//! // That's the equivalent of a tail sampling processor in OpenTelemetry.
29-
//! // These options will only affect sampling of the spans that are sent to Sentry,
30-
//! // not of the underlying OpenTelemetry spans.
31-
//! traces_sample_rate: 1.0,
32-
//! ..sentry::ClientOptions::default()
33-
//! });
38+
//! let _guard = sentry::init((
39+
//! "https://[email protected]/0",
40+
//! sentry::ClientOptions {
41+
//! // Enable capturing of traces; set this a to lower value in production.
42+
//! // For more sophisticated behavior use a custom
43+
//! // [`sentry::ClientOptions::traces_sampler`] instead.
44+
//! // That's the equivalent of a tail sampling processor in OpenTelemetry.
45+
//! // These options will only affect sampling of the spans that are sent to Sentry,
46+
//! // not of the underlying OpenTelemetry spans.
47+
//! traces_sample_rate: 1.0,
48+
//! debug: true,
49+
//! ..sentry::ClientOptions::default()
50+
//! },
51+
//! ));
3452
//!
3553
//! // Register the Sentry propagator to enable distributed tracing
3654
//! global::set_text_map_propagator(sentry_opentelemetry::SentryPropagator::new());
@@ -42,6 +60,25 @@
4260
//!
4361
//! global::set_tracer_provider(tracer_provider);
4462
//! ```
63+
//!
64+
//! # Usage
65+
//!
66+
//! Use the OpenTelemetry API to create spans. They will be captured by Sentry:
67+
//!
68+
//! ```no_run
69+
//! let tracer = global::tracer("tracer");
70+
//! // Creates a Sentry span (transaction) with the name set to "example"
71+
//! tracer.in_span("example", |_| {
72+
//! // Creates a Sentry child span with the name set to "child"
73+
//! tracer.in_span("child", |cx| {
74+
//! // OTEL span attributes are captured as data attributes on the Sentry span
75+
//! cx.span().set_attribute(KeyValue::new("my", "attribute"));
76+
//!
77+
//! // Captures a Sentry error message and associates it with the ongoing child span
78+
//! sentry::capture_message("Everything is on fire!", sentry::Level::Error);
79+
//! });
80+
//! });
81+
//! ```
4582
4683
mod converters;
4784
mod processor;

sentry/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,20 @@ extra setup to function properly.
8080
| `reqwest` || | | |
8181
| `native-tls` || | | `reqwest` must be enabled. |
8282
| `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
83-
| `curl` | | | | |
84-
| `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
8583
| `ureq` | | | | `ureq` transport support using `rustls` by default |
8684
| `ureq-native-tls` | | | | |
85+
| `curl` | | | | |
86+
| `actix` | | 🔌 | | Requires extra setup; See [`sentry-actix`]'s documentation. |
87+
| `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
88+
| `tracing` | | 🔌 | | Requires extra setup; See [`sentry-tracing`]'s documentation. |
89+
| `opentelemetry` | | 🔌 | | Requires extra setup; See [`sentry-opentelemetry`]'s documentation. |
8790

8891
[`sentry-log`]: https://crates.io/crates/sentry-log
8992
[`sentry-slog`]: https://crates.io/crates/sentry-slog
93+
[`sentry-actix`]: https://crates.io/crates/sentry-actix
9094
[`sentry-tower`]: https://crates.io/crates/sentry-tower
95+
[`sentry-tracing`]: https://crates.io/crates/sentry-tracing
96+
[`sentry-opentelemetry`]: https://crates.io/crates/sentry-opentelemetry
9197

9298
### Default features
9399
- `backtrace`: Enables backtrace support.
@@ -116,7 +122,10 @@ extra setup to function properly.
116122
- `ureq-native-tls`: Enables the `ureq` transport using `native-tls`.
117123

118124
### Integrations
125+
- `actix`: Enables support for the `actix-web` crate.
119126
- `tower`: Enables support for the `tower` crate and those using it.
127+
- `tracing`: Enables support for the `tracing` crate and those using it.
128+
- `opentelemetry`: Enables support for the `opentelemetry` and `opentelemetry-sdk` crates.
120129

121130
## Resources
122131

sentry/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
//! [`Transport`]: trait.Transport.html
5353
//! [`sentry-core`]: https://crates.io/crates/sentry-core
5454
//!
55+
//!
5556
//! # Features
5657
//!
5758
//! Additional functionality and integrations are enabled via feature flags. Some features require
@@ -72,14 +73,20 @@
7273
//! | `reqwest` | ✅ | | | |
7374
//! | `native-tls` | ✅ | | | `reqwest` must be enabled. |
7475
//! | `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
75-
//! | `curl` | | | | |
76-
//! | `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
7776
//! | `ureq` | | | | `ureq` transport support using `rustls` by default |
7877
//! | `ureq-native-tls` | | | | |
78+
//! | `curl` | | | | |
79+
//! | `actix` | | 🔌 | | Requires extra setup; See [`sentry-actix`]'s documentation. |
80+
//! | `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
81+
//! | `tracing` | | 🔌 | | Requires extra setup; See [`sentry-tracing`]'s documentation. |
82+
//! | `opentelemetry` | | 🔌 | | Requires extra setup; See [`sentry-opentelemetry`]'s documentation. |
7983
//!
8084
//! [`sentry-log`]: https://crates.io/crates/sentry-log
8185
//! [`sentry-slog`]: https://crates.io/crates/sentry-slog
86+
//! [`sentry-actix`]: https://crates.io/crates/sentry-actix
8287
//! [`sentry-tower`]: https://crates.io/crates/sentry-tower
88+
//! [`sentry-tracing`]: https://crates.io/crates/sentry-tracing
89+
//! [`sentry-opentelemetry`]: https://crates.io/crates/sentry-opentelemetry
8390
//!
8491
//! ## Default features
8592
//! - `backtrace`: Enables backtrace support.
@@ -108,7 +115,10 @@
108115
//! - `ureq-native-tls`: Enables the `ureq` transport using `native-tls`.
109116
//!
110117
//! ## Integrations
118+
//! - `actix`: Enables support for the `actix-web` crate.
111119
//! - `tower`: Enables support for the `tower` crate and those using it.
120+
//! - `tracing`: Enables support for the `tracing` crate and those using it.
121+
//! - `opentelemetry`: Enables support for the `opentelemetry` and `opentelemetry-sdk` crates.
112122
113123
#![doc(html_favicon_url = "https://sentry-brand.storage.googleapis.com/favicon.ico")]
114124
#![doc(html_logo_url = "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png")]

0 commit comments

Comments
 (0)