reqwest-middleware/reqwest-tracing
tl-flavio-barinas 8a6b2ea571
bump reqwest-tracing to v0.2.3 (#46)
* (cargo-release) reqwest-tracing v0.2.3

* sort dependencies

* Fix dependency versions

* Fix reqwest-middleware dependency

Co-authored-by: azanin <ale.zanin90@gmail.com>
2022-06-29 15:06:52 +01:00
..
src Update `otel.status_code` mapping with latest version of spec. (#41) 2022-05-17 10:25:58 +01:00
CHANGELOG.md bump reqwest-tracing to v0.2.3 (#46) 2022-06-29 15:06:52 +01:00
Cargo.toml bump reqwest-tracing to v0.2.3 (#46) 2022-06-29 15:06:52 +01:00
README.md docs: fix readme (#40) 2022-04-21 18:38:15 +01:00

README.md

reqwest-tracing

Opentracing middleware implementation for reqwest-middleware.

Crates.io Docs.rs CI Coverage Status

Overview

Attach TracingMiddleware to your client to automatically trace HTTP requests:

# Cargo.toml
# ...
[dependencies]
opentelemetry = "0.17"
reqwest = "0.11"
reqwest-middleware = "0.1.1"
reqwest-retry = "0.1.1"
reqwest-tracing = { version = "0.2.1", features = ["opentelemetry_0_17"] }
tokio = { version = "1.12.0", features = ["macros", "rt-multi-thread"] }
tracing = "0.1"
tracing-opentelemetry = "0.17"
tracing-subscriber = "0.3"
use opentelemetry::sdk::export::trace::stdout;
use reqwest_middleware::ClientBuilder;
use reqwest_tracing::TracingMiddleware;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;

#[tokio::main]
async fn main() {
  let tracer = stdout::new_pipeline().install_simple();
  let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
  let subscriber = Registry::default().with(telemetry);
  tracing::subscriber::set_global_default(subscriber).unwrap();

  run().await;
}

async fn run() {
  let client = ClientBuilder::new(reqwest::Client::new())
    .with(TracingMiddleware)
    .build();

  client.get("https://truelayer.com").send().await.unwrap();
}
$ cargo run
SpanData { span_context: SpanContext { trace_id: ...

See the tracing crate for more information on how to set up a tracing subscriber to make use of the spans.

How to install

Add reqwest-tracing to your dependencies. Optionally enable opentelemetry integration by enabling an opentelemetry version feature:

[dependencies]
# ...
reqwest-tracing = { version = "0.1.0", features = ["opentelemetry_0_17"] }

Available opentelemetry features are opentelemetry_0_17, opentelemetry_0_16, opentelemetry_0_15, opentelemetry_0_14 and opentelemetry_0_13.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.