logo
Expand description


opentelemetry-surf

OpenTelemetry integration for Surf


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

Notes

  • It is heavily inspired by opentelemetry-tide crate; surf and tide share very similar middleware structure. Thank you, dear @http-rs folks! 🙇🏻‍♂️
  • It only implements very basic request tracing on the middleware layer. If something is missing, please open an issue and describe your desired feature or create a PR with a change.
  • It can record http request/response life cycle events when used with isahc and its metrics feature enabled.
  • You probably do not want to use it in production. 🤷

How to use

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


cargo run --example simple

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

firefox http://localhost:16686/

example jaeger trace

Code example

Cargo.toml

async-std = { version = "1.10", features = ["attributes"] }
opentelemetry = { version = "0.17", features = ["rt-async-std"] }
opentelemetry-jaeger = { version = "0.16", features = ["rt-async-std"] }
opentelemetry-surf = "0.6"

client.rs

#[async_std::main]
async fn main() -> surf::Result<()> {
    let _tracer = opentelemetry_jaeger::new_pipeline().install_batch(opentelemetry::runtime::AsyncStd)?;
    let otel_mw = opentelemetry_surf::OpenTelemetryTracingMiddleware::default();
    let client = surf::client().with(otel_mw);
    let res = client.get("https://httpbin.org/get").await?;
    dbg!(res);

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

Cargo Features

flagdescription
isahc-metricsenables 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.

Structs

The middleware struct to be used in surf