Skip to content

Commit d0b60d9

Browse files
committed
feat: Add ureq transport support
Ureq is easy to use, smaller than the other http crates and doesn't pull in as many crate dependencies either, which is why [we] are actively switching to it and in need of an `ureq` transport in Sentry too. [we]: https://github.com/Traverse-Research
1 parent d0d5abc commit d0b60d9

File tree

5 files changed

+212
-44
lines changed

5 files changed

+212
-44
lines changed

Diff for: sentry/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ surf-h1 = ["surf_/h1-client", "httpdate"]
4444
surf = ["surf_/curl-client", "httpdate", "tokio"]
4545
native-tls = ["reqwest_/default-tls"]
4646
rustls = ["reqwest_/rustls-tls"]
47+
ureq = ["ureq_", "httpdate", "tokio"]
48+
ureq-tls = ["ureq", "ureq_/tls"]
49+
ureq-native-tls = ["ureq", "ureq_/native-tls"]
4750

4851
[dependencies]
4952
sentry-core = { version = "0.24.2", path = "../sentry-core", features = ["client"] }
@@ -63,6 +66,7 @@ httpdate = { version = "1.0.0", optional = true }
6366
surf_ = { package = "surf", version = "2.0.0", optional = true, default-features = false }
6467
serde_json = { version = "1.0.48", optional = true }
6568
tokio = { version = "1.0", features = ["rt"], optional = true }
69+
ureq_ = { package = "ureq", version = "2.3.0", optional = true, default-features = false }
6670

6771
[dev-dependencies]
6872
sentry-anyhow = { path = "../sentry-anyhow" }

Diff for: sentry/README.md

+25-18
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,27 @@ one should use the [`sentry-core`] crate instead.
6464
Additional functionality and integrations are enabled via feature flags. Some features require
6565
extra setup to function properly.
6666

67-
| Feature | Default | Is Integration | Deprecated | Additional notes |
68-
| -------------- | ------- | -------------- | ---------- | ---------------------------------------------------------------------------------------- |
69-
| `backtrace` || 🔌 | | |
70-
| `contexts` || 🔌 | | |
71-
| `panic` || 🔌 | | |
72-
| `transport` || | | |
73-
| `anyhow` | | 🔌 | | |
74-
| `test` | | | | |
75-
| `debug-images` | | 🔌 | | |
76-
| `log` | | 🔌 | | Requires extra setup; See [`sentry-log`]'s documentation. |
77-
| `debug-logs` | | || Requires extra setup; See [`sentry-log`]'s documentation. |
78-
| `slog` | | 🔌 | | Requires extra setup; See [`sentry-slog`]'s documentation. |
79-
| `reqwest` || | | |
80-
| `native-tls` || | | `reqwest` must be enabled. |
81-
| `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
82-
| `curl` | | | | |
83-
| `surf` | | | | |
84-
| `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
67+
| Feature | Default | Is Integration | Deprecated | Additional notes |
68+
| -------------- | ------- | -------------- | ---------- | ---------------------------------------------------------------------------------------- |
69+
| `backtrace` || 🔌 | | |
70+
| `contexts` || 🔌 | | |
71+
| `panic` || 🔌 | | |
72+
| `transport` || | | |
73+
| `anyhow` | | 🔌 | | |
74+
| `test` | | | | |
75+
| `debug-images` | | 🔌 | | |
76+
| `log` | | 🔌 | | Requires extra setup; See [`sentry-log`]'s documentation. |
77+
| `debug-logs` | | || Requires extra setup; See [`sentry-log`]'s documentation. |
78+
| `slog` | | 🔌 | | Requires extra setup; See [`sentry-slog`]'s documentation. |
79+
| `reqwest` || | | |
80+
| `native-tls` || | | `reqwest` must be enabled. |
81+
| `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
82+
| `curl` | | | | |
83+
| `surf` | | | | |
84+
| `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
85+
| `ureq` | | | | |
86+
| `ureq-tls` | | | | |
87+
| `ureq-native-tls` | | | | |
8588

8689
[`sentry-log`]: https://crates.io/crates/sentry-log
8790
[`sentry-slog`]: https://crates.io/crates/sentry-slog
@@ -111,6 +114,10 @@ extra setup to function properly.
111114
dependencies.
112115
- `curl`: Enables the curl transport.
113116
- `surf`: Enables the surf transport.
117+
- `ureq`: Enables the ureq transport.
118+
- `ureq-tls`: Enables `rustls` support for `ureq`. Please note that this has to be enabled for
119+
https support, and cannot be enabled by default.
120+
- `ureq-native-tls`: Enables `native-tls` support for `ureq`.
114121

115122
### Integrations
116123
- `tower`: Enables support for the `tower` crate and those using it.

Diff for: sentry/src/lib.rs

+25-18
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,27 @@
5656
//! Additional functionality and integrations are enabled via feature flags. Some features require
5757
//! extra setup to function properly.
5858
//!
59-
//! | Feature | Default | Is Integration | Deprecated | Additional notes |
60-
//! | -------------- | ------- | -------------- | ---------- | ---------------------------------------------------------------------------------------- |
61-
//! | `backtrace` | ✅ | 🔌 | | |
62-
//! | `contexts` | ✅ | 🔌 | | |
63-
//! | `panic` | ✅ | 🔌 | | |
64-
//! | `transport` | ✅ | | | |
65-
//! | `anyhow` | | 🔌 | | |
66-
//! | `test` | | | | |
67-
//! | `debug-images` | | 🔌 | | |
68-
//! | `log` | | 🔌 | | Requires extra setup; See [`sentry-log`]'s documentation. |
69-
//! | `debug-logs` | | | ❗ | Requires extra setup; See [`sentry-log`]'s documentation. |
70-
//! | `slog` | | 🔌 | | Requires extra setup; See [`sentry-slog`]'s documentation. |
71-
//! | `reqwest` | ✅ | | | |
72-
//! | `native-tls` | ✅ | | | `reqwest` must be enabled. |
73-
//! | `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
74-
//! | `curl` | | | | |
75-
//! | `surf` | | | | |
76-
//! | `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
59+
//! | Feature | Default | Is Integration | Deprecated | Additional notes |
60+
//! | -------------- | ------- | -------------- | ---------- | ---------------------------------------------------------------------------------------- |
61+
//! | `backtrace` | ✅ | 🔌 | | |
62+
//! | `contexts` | ✅ | 🔌 | | |
63+
//! | `panic` | ✅ | 🔌 | | |
64+
//! | `transport` | ✅ | | | |
65+
//! | `anyhow` | | 🔌 | | |
66+
//! | `test` | | | | |
67+
//! | `debug-images` | | 🔌 | | |
68+
//! | `log` | | 🔌 | | Requires extra setup; See [`sentry-log`]'s documentation. |
69+
//! | `debug-logs` | | | ❗ | Requires extra setup; See [`sentry-log`]'s documentation. |
70+
//! | `slog` | | 🔌 | | Requires extra setup; See [`sentry-slog`]'s documentation. |
71+
//! | `reqwest` | ✅ | | | |
72+
//! | `native-tls` | ✅ | | | `reqwest` must be enabled. |
73+
//! | `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
74+
//! | `curl` | | | | |
75+
//! | `surf` | | | | |
76+
//! | `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
77+
//! | `ureq` | | | | |
78+
//! | `ureq-tls` | | | | |
79+
//! | `ureq-native-tls` | | | | |
7780
//!
7881
//! [`sentry-log`]: https://crates.io/crates/sentry-log
7982
//! [`sentry-slog`]: https://crates.io/crates/sentry-slog
@@ -103,6 +106,10 @@
103106
//! dependencies.
104107
//! - `curl`: Enables the curl transport.
105108
//! - `surf`: Enables the surf transport.
109+
//! - `ureq`: Enables the ureq transport.
110+
//! - `ureq-tls`: Enables `rustls` support for `ureq`. Please note that this has to be enabled for
111+
//! https support, and cannot be enabled by default.
112+
//! - `ureq-native-tls`: Enables `native-tls` support for `ureq`.
106113
//!
107114
//! ## Integrations
108115
//! - `tower`: Enables support for the `tower` crate and those using it.

Diff for: sentry/src/transports/mod.rs

+56-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
//! The provided transports.
22
//!
33
//! This module exposes all transports that are compiled into the sentry
4-
//! library. The `reqwest`, `curl` and `surf` features turn on these transports.
4+
//! library. The `reqwest`, `curl`, `surf` and `ureq` features turn on these transports.
55
66
use crate::{ClientOptions, Transport, TransportFactory};
77
use std::sync::Arc;
88

9-
#[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
9+
#[cfg(any(
10+
feature = "reqwest",
11+
feature = "curl",
12+
feature = "surf",
13+
feature = "ureq"
14+
))]
1015
mod ratelimit;
11-
#[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
16+
#[cfg(any(
17+
feature = "reqwest",
18+
feature = "curl",
19+
feature = "surf",
20+
feature = "ureq"
21+
))]
1222
mod thread;
1323

1424
#[cfg(feature = "reqwest")]
@@ -26,17 +36,45 @@ mod surf;
2636
#[cfg(feature = "surf")]
2737
pub use surf::SurfHttpTransport;
2838

39+
#[cfg(feature = "ureq")]
40+
mod ureq;
41+
#[cfg(feature = "ureq")]
42+
pub use ureq::UreqHttpTransport;
43+
2944
#[cfg(feature = "reqwest")]
3045
type DefaultTransport = ReqwestHttpTransport;
3146

32-
#[cfg(all(feature = "curl", not(feature = "reqwest"), not(feature = "surf")))]
47+
#[cfg(all(
48+
feature = "curl",
49+
not(feature = "reqwest"),
50+
not(feature = "surf"),
51+
not(feature = "ureq")
52+
))]
3353
type DefaultTransport = CurlHttpTransport;
3454

35-
#[cfg(all(feature = "surf", not(feature = "reqwest"), not(feature = "curl")))]
55+
#[cfg(all(
56+
feature = "surf",
57+
not(feature = "reqwest"),
58+
not(feature = "curl"),
59+
not(feature = "ureq")
60+
))]
3661
type DefaultTransport = SurfHttpTransport;
3762

63+
#[cfg(all(
64+
feature = "ureq",
65+
not(feature = "reqwest"),
66+
not(feature = "curl"),
67+
not(feature = "surf")
68+
))]
69+
type DefaultTransport = UreqHttpTransport;
70+
3871
/// The default http transport.
39-
#[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
72+
#[cfg(any(
73+
feature = "reqwest",
74+
feature = "curl",
75+
feature = "surf",
76+
feature = "ureq"
77+
))]
4078
pub type HttpTransport = DefaultTransport;
4179

4280
/// Creates the default HTTP transport.
@@ -49,11 +87,21 @@ pub struct DefaultTransportFactory;
4987

5088
impl TransportFactory for DefaultTransportFactory {
5189
fn create_transport(&self, options: &ClientOptions) -> Arc<dyn Transport> {
52-
#[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
90+
#[cfg(any(
91+
feature = "reqwest",
92+
feature = "curl",
93+
feature = "surf",
94+
feature = "ureq"
95+
))]
5396
{
5497
Arc::new(HttpTransport::new(options))
5598
}
56-
#[cfg(not(any(feature = "reqwest", feature = "curl", feature = "surf")))]
99+
#[cfg(not(any(
100+
feature = "reqwest",
101+
feature = "curl",
102+
feature = "surf",
103+
feature = "ureq"
104+
)))]
57105
{
58106
let _ = options;
59107
panic!("sentry crate was compiled without transport")

0 commit comments

Comments
 (0)