#actix #actix-web #opentelemetry #jaeger #prometheus

actix-web-opentelemetry

OpenTelemetry integration for Actix Web apps

5 unstable releases

✓ Uses Rust 2018 edition

0.3.0 Jun 25, 2020
0.2.0 Feb 11, 2020
0.1.2 Dec 2, 2019
0.1.1 Nov 26, 2019
0.1.0 Nov 20, 2019

#7 in #actix-web

Download history 40/week @ 2020-03-14 23/week @ 2020-03-21 17/week @ 2020-03-28 51/week @ 2020-04-04 55/week @ 2020-04-11 17/week @ 2020-04-18 21/week @ 2020-04-25 2/week @ 2020-05-02 7/week @ 2020-05-09 1/week @ 2020-05-16 9/week @ 2020-05-23 19/week @ 2020-05-30 17/week @ 2020-06-06 119/week @ 2020-06-13 19/week @ 2020-06-20 102/week @ 2020-06-27

113 downloads per month

MIT license

170KB
546 lines

Actix Web OpenTelemetry

Crates.io: actix-web-opentelemetry Documentation License: MIT

OpenTelemetry integration for Actix Web.

Execute client and server example

# Run jaeger in background
$ docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 jaegertracing/all-in-one:latest

# Run server example with tracing middleware
$ cargo run --example server
# (In other tab) Run client example with request tracing
$ cargo run --example client

# View spans (see the image below)
$ firefox http://localhost:16686/

Jaeger UI


lib.rs:

Actix Web OpenTelemetry

OpenTelemetry integration for Actix Web.

This crate allows you to easily instrument client and server requests.

  • Client requests can be traced by using the with_tracing function.
  • Server requests can be traced by using the RequestTracing struct.

Client Request Example:

use actix_web::client;
use futures::Future;

async fn execute_request(client: &client::Client) -> Result<(), client::SendRequestError> {
    let mut res = actix_web_opentelemetry::with_tracing(
        client.get("http://localhost:8080"),
        |request| request.send()
    )
    .await;

    res.and_then(|res| {
        println!("Response: {:?}", res);
        Ok(())
    })
}

Server middlware example:

use actix_web::{web, App, HttpServer};
use actix_web_opentelemetry::RequestTracing;
use opentelemetry::api;

fn init_tracer() {
    opentelemetry::global::set_provider(api::NoopProvider {});
}

async fn index() -> &'static str {
    "Hello world!"
}

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    init_tracer();
    HttpServer::new(|| {
        App::new()
            .wrap(RequestTracing::default())
            .service(web::resource("/").to(index))
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}

Dependencies

~19MB
~454K SLoC