Skip to content

Commit

Permalink
feat(builder): Add tokio feature, which can be omitted
Browse files Browse the repository at this point in the history
This enabled an application, that doesn't use a Tokio runtime, to use
axiom-tracing.
  • Loading branch information
bahlo committed Jan 29, 2024
1 parent 167a199 commit 2155e60
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
28 changes: 21 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,37 @@ include = ["src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
resolver = "2"

[dependencies]
opentelemetry = { version = "0.20", features = ["rt-tokio"] }
opentelemetry-otlp = { version = "0.13", features = ["prost", "tokio", "http-proto", "reqwest-client" ] }
opentelemetry = "0.20"
opentelemetry-otlp = { version = "0.13", features = [
"prost",
"http-proto",
"reqwest-client",
] }
tracing-core = { version = "0.1", default-features = false, features = ["std"] }
tracing-opentelemetry = { version = "0.21", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false, features = ["smallvec", "std", "registry", "fmt", "json" ] }
reqwest = { version = "0.11", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false, features = [
"smallvec",
"std",
"registry",
"fmt",
"json",
] }
reqwest = { version = "0.11", default-features = false, features = ["blocking"] }
thiserror = "1"
opentelemetry-semantic-conventions = "0.12"
url = "2.4.1"

[dev-dependencies]
tokio = "1"
tracing = { version = "0.1", features = [ "log" ] }
opentelemetry = { version = "0.20", features = ["rt-tokio"] }
tracing = { version = "0.1", features = ["log"] }
opentelemetry = { version = "0.20", features = ["rt-tokio"] }

[features]
default = ["default-tls"]
default = ["default-tls", "tokio"]
default-tls = ["reqwest/default-tls"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
tokio = [
"opentelemetry/rt-tokio",
"opentelemetry-otlp/tokio",
]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ that can be enabled or disabled:
over HTTPS.
- **native-tls**: Enables TLS functionality provided by `native-tls`.
- **rustls-tls**: Enables TLS functionality provided by `rustls`.
- **tokio** _(enabled by default)_: Uses a more efficient batch processor.

## FAQ & Troubleshooting
### How do I log traces to the console in addition to Axiom?
Expand Down
14 changes: 7 additions & 7 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ impl Builder {

let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.with_exporter({

Check failure on line 317 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Run tests

unreachable call

Check failure on line 317 in src/builder.rs

View workflow job for this annotation

GitHub Actions / clippy

unreachable call

error: unreachable call --> src/builder.rs:317:14 | 317 | .with_exporter({ | ^^^^^^^^^^^^^ unreachable call ... 323 | return exporter.with_http_client(reqwest::blocking::Client::new()); | ------------------------------------------------------------------ any code following this expression is unreachable | note: the lint level is defined here --> src/lib.rs:1:9 | 1 | #![deny(warnings)] | ^^^^^^^^ = note: `#[deny(unreachable_code)]` implied by `#[deny(warnings)]`
let exporter = opentelemetry_otlp::new_exporter()
.http()
.with_http_client(reqwest::Client::new())
.with_endpoint(url)
.with_headers(headers)
.with_timeout(Duration::from_secs(3)),
)
.with_trace_config(trace_config)
.install_batch(opentelemetry::runtime::Tokio)?;
.with_timeout(Duration::from_secs(3));
return exporter.with_http_client(reqwest::blocking::Client::new());

Check failure on line 323 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Run tests

mismatched types

Check failure on line 323 in src/builder.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> src/builder.rs:323:24 | 323 | return exporter.with_http_client(reqwest::blocking::Client::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<Tracer, Error>`, found `HttpExporterBuilder` | = note: expected enum `std::result::Result<opentelemetry::sdk::trace::Tracer, error::Error>` found struct `opentelemetry_otlp::HttpExporterBuilder`
})
.with_trace_config(trace_config);
let tracer = tracer.install_simple()?;
Ok(tracer)
}
}
Expand Down

0 comments on commit 2155e60

Please sign in to comment.