opentelemetry-surf

[OpenTelemetry] integration for [Surf]

Crates.io version docs.rs docs CI status Download

Add OpenTelemetry tracing support to your [Surf] clients. Be part of the new observability movement!

Notes

How to use

```shell

Run jaeger in background

docker run -d \ -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 \ jaegertracing/all-in-one:latest

Run simple client example with tracing middleware

cargo run --example simple

Run metrics client example (uses isahc with metrics enabled)

cargo run --example metrics --features isahc-metrics

Open browser and view the traces

firefox http://localhost:16686/ ```

example jaeger trace

Code example

Cargo.toml

toml async-std = { version = "1.9", features = ["attributes"] } opentelemetry = { version = "0.13", features = ["async-std", "rt-async-std"] } opentelemetry-jaeger = { version = "0.12", features = ["async-std"] } opentelemetry-surf = "0.2"

client.rs

```rust

[async_std::main]

async fn main() -> surf::Result<()> { let tracer = opentelemetryjaeger::newpipeline().installbatch(opentelemetry::runtime::AsyncStd)?; let otelmw = opentelemetrysurf::OpenTelemetryTracingMiddleware::new(tracer); let client = surf::client().with(otelmw); let res = client.get("https://httpbin.org/get").await?; dbg!(res);

opentelemetry::global::shutdown_tracer_provider();
Ok(())

} ```

Cargo Features

| flag | description | | --------------: | :---------- | | isahc-metrics | enables more details when using a custom ishac client configuration, see examples/client/metrics.rs for details |

Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

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 this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.