Skip to content

Commit

Permalink
feat: Add ureq transport support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarijnS95 committed Jan 27, 2022
1 parent d0d5abc commit d0b60d9
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 44 deletions.
4 changes: 4 additions & 0 deletions sentry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ surf-h1 = ["surf_/h1-client", "httpdate"]
surf = ["surf_/curl-client", "httpdate", "tokio"]
native-tls = ["reqwest_/default-tls"]
rustls = ["reqwest_/rustls-tls"]
ureq = ["ureq_", "httpdate", "tokio"]
ureq-tls = ["ureq", "ureq_/tls"]
ureq-native-tls = ["ureq", "ureq_/native-tls"]

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

[dev-dependencies]
sentry-anyhow = { path = "../sentry-anyhow" }
Expand Down
43 changes: 25 additions & 18 deletions sentry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,27 @@ one should use the [`sentry-core`] crate instead.
Additional functionality and integrations are enabled via feature flags. Some features require
extra setup to function properly.

| Feature | Default | Is Integration | Deprecated | Additional notes |
| -------------- | ------- | -------------- | ---------- | ---------------------------------------------------------------------------------------- |
| `backtrace` || 🔌 | | |
| `contexts` || 🔌 | | |
| `panic` || 🔌 | | |
| `transport` || | | |
| `anyhow` | | 🔌 | | |
| `test` | | | | |
| `debug-images` | | 🔌 | | |
| `log` | | 🔌 | | Requires extra setup; See [`sentry-log`]'s documentation. |
| `debug-logs` | | || Requires extra setup; See [`sentry-log`]'s documentation. |
| `slog` | | 🔌 | | Requires extra setup; See [`sentry-slog`]'s documentation. |
| `reqwest` || | | |
| `native-tls` || | | `reqwest` must be enabled. |
| `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
| `curl` | | | | |
| `surf` | | | | |
| `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
| Feature | Default | Is Integration | Deprecated | Additional notes |
| -------------- | ------- | -------------- | ---------- | ---------------------------------------------------------------------------------------- |
| `backtrace` || 🔌 | | |
| `contexts` || 🔌 | | |
| `panic` || 🔌 | | |
| `transport` || | | |
| `anyhow` | | 🔌 | | |
| `test` | | | | |
| `debug-images` | | 🔌 | | |
| `log` | | 🔌 | | Requires extra setup; See [`sentry-log`]'s documentation. |
| `debug-logs` | | || Requires extra setup; See [`sentry-log`]'s documentation. |
| `slog` | | 🔌 | | Requires extra setup; See [`sentry-slog`]'s documentation. |
| `reqwest` || | | |
| `native-tls` || | | `reqwest` must be enabled. |
| `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
| `curl` | | | | |
| `surf` | | | | |
| `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
| `ureq` | | | | |
| `ureq-tls` | | | | |
| `ureq-native-tls` | | | | |

[`sentry-log`]: https://crates.io/crates/sentry-log
[`sentry-slog`]: https://crates.io/crates/sentry-slog
Expand Down Expand Up @@ -111,6 +114,10 @@ extra setup to function properly.
dependencies.
- `curl`: Enables the curl transport.
- `surf`: Enables the surf transport.
- `ureq`: Enables the ureq transport.
- `ureq-tls`: Enables `rustls` support for `ureq`. Please note that this has to be enabled for
https support, and cannot be enabled by default.
- `ureq-native-tls`: Enables `native-tls` support for `ureq`.

### Integrations
- `tower`: Enables support for the `tower` crate and those using it.
Expand Down
43 changes: 25 additions & 18 deletions sentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,27 @@
//! Additional functionality and integrations are enabled via feature flags. Some features require
//! extra setup to function properly.
//!
//! | Feature | Default | Is Integration | Deprecated | Additional notes |
//! | -------------- | ------- | -------------- | ---------- | ---------------------------------------------------------------------------------------- |
//! | `backtrace` | ✅ | 🔌 | | |
//! | `contexts` | ✅ | 🔌 | | |
//! | `panic` | ✅ | 🔌 | | |
//! | `transport` | ✅ | | | |
//! | `anyhow` | | 🔌 | | |
//! | `test` | | | | |
//! | `debug-images` | | 🔌 | | |
//! | `log` | | 🔌 | | Requires extra setup; See [`sentry-log`]'s documentation. |
//! | `debug-logs` | | | ❗ | Requires extra setup; See [`sentry-log`]'s documentation. |
//! | `slog` | | 🔌 | | Requires extra setup; See [`sentry-slog`]'s documentation. |
//! | `reqwest` | ✅ | | | |
//! | `native-tls` | ✅ | | | `reqwest` must be enabled. |
//! | `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
//! | `curl` | | | | |
//! | `surf` | | | | |
//! | `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
//! | Feature | Default | Is Integration | Deprecated | Additional notes |
//! | -------------- | ------- | -------------- | ---------- | ---------------------------------------------------------------------------------------- |
//! | `backtrace` | ✅ | 🔌 | | |
//! | `contexts` | ✅ | 🔌 | | |
//! | `panic` | ✅ | 🔌 | | |
//! | `transport` | ✅ | | | |
//! | `anyhow` | | 🔌 | | |
//! | `test` | | | | |
//! | `debug-images` | | 🔌 | | |
//! | `log` | | 🔌 | | Requires extra setup; See [`sentry-log`]'s documentation. |
//! | `debug-logs` | | | ❗ | Requires extra setup; See [`sentry-log`]'s documentation. |
//! | `slog` | | 🔌 | | Requires extra setup; See [`sentry-slog`]'s documentation. |
//! | `reqwest` | ✅ | | | |
//! | `native-tls` | ✅ | | | `reqwest` must be enabled. |
//! | `rustls` | | | | `reqwest` must be enabled. `native-tls` must be disabled via `default-features = false`. |
//! | `curl` | | | | |
//! | `surf` | | | | |
//! | `tower` | | 🔌 | | Requires extra setup; See [`sentry-tower`]'s documentation. |
//! | `ureq` | | | | |
//! | `ureq-tls` | | | | |
//! | `ureq-native-tls` | | | | |
//!
//! [`sentry-log`]: https://crates.io/crates/sentry-log
//! [`sentry-slog`]: https://crates.io/crates/sentry-slog
Expand Down Expand Up @@ -103,6 +106,10 @@
//! dependencies.
//! - `curl`: Enables the curl transport.
//! - `surf`: Enables the surf transport.
//! - `ureq`: Enables the ureq transport.
//! - `ureq-tls`: Enables `rustls` support for `ureq`. Please note that this has to be enabled for
//! https support, and cannot be enabled by default.
//! - `ureq-native-tls`: Enables `native-tls` support for `ureq`.
//!
//! ## Integrations
//! - `tower`: Enables support for the `tower` crate and those using it.
Expand Down
64 changes: 56 additions & 8 deletions sentry/src/transports/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
//! The provided transports.
//!
//! This module exposes all transports that are compiled into the sentry
//! library. The `reqwest`, `curl` and `surf` features turn on these transports.
//! library. The `reqwest`, `curl`, `surf` and `ureq` features turn on these transports.
use crate::{ClientOptions, Transport, TransportFactory};
use std::sync::Arc;

#[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
#[cfg(any(
feature = "reqwest",
feature = "curl",
feature = "surf",
feature = "ureq"
))]
mod ratelimit;
#[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
#[cfg(any(
feature = "reqwest",
feature = "curl",
feature = "surf",
feature = "ureq"
))]
mod thread;

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

#[cfg(feature = "ureq")]
mod ureq;
#[cfg(feature = "ureq")]
pub use ureq::UreqHttpTransport;

#[cfg(feature = "reqwest")]
type DefaultTransport = ReqwestHttpTransport;

#[cfg(all(feature = "curl", not(feature = "reqwest"), not(feature = "surf")))]
#[cfg(all(
feature = "curl",
not(feature = "reqwest"),
not(feature = "surf"),
not(feature = "ureq")
))]
type DefaultTransport = CurlHttpTransport;

#[cfg(all(feature = "surf", not(feature = "reqwest"), not(feature = "curl")))]
#[cfg(all(
feature = "surf",
not(feature = "reqwest"),
not(feature = "curl"),
not(feature = "ureq")
))]
type DefaultTransport = SurfHttpTransport;

#[cfg(all(
feature = "ureq",
not(feature = "reqwest"),
not(feature = "curl"),
not(feature = "surf")
))]
type DefaultTransport = UreqHttpTransport;

/// The default http transport.
#[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
#[cfg(any(
feature = "reqwest",
feature = "curl",
feature = "surf",
feature = "ureq"
))]
pub type HttpTransport = DefaultTransport;

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

impl TransportFactory for DefaultTransportFactory {
fn create_transport(&self, options: &ClientOptions) -> Arc<dyn Transport> {
#[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
#[cfg(any(
feature = "reqwest",
feature = "curl",
feature = "surf",
feature = "ureq"
))]
{
Arc::new(HttpTransport::new(options))
}
#[cfg(not(any(feature = "reqwest", feature = "curl", feature = "surf")))]
#[cfg(not(any(
feature = "reqwest",
feature = "curl",
feature = "surf",
feature = "ureq"
)))]
{
let _ = options;
panic!("sentry crate was compiled without transport")
Expand Down
Loading

0 comments on commit d0b60d9

Please sign in to comment.