#open-telemetry #tracing #logging-tracing #logging #spans #helper #web

macro opentelemetry-auto-span

A helper library for opentelemetry tracing

6 releases (3 breaking)

0.4.0 Nov 30, 2024
0.3.2 Nov 21, 2023
0.2.0 Aug 13, 2022
0.1.0 Aug 9, 2022

#745 in Debugging

Download history 2/week @ 2024-09-20 3/week @ 2024-09-27 5/week @ 2024-10-04 2/week @ 2024-10-11 1/week @ 2024-11-01 2/week @ 2024-11-22 159/week @ 2024-11-29 80/week @ 2024-12-06

241 downloads per month

Apache-2.0

250KB
571 lines

rust-opentelemetry-auto-span

Usage

add dependencies

[dependencies]
opentelemetry-auto-span = "0.4"

annotate function

use opentelemetry_auto_span::auto_span;

#[get("/user/{id}")]
#[auto_span]
async fn get_user(
    id: web::Path<(i64,)>,
    db: web::Data<sqlx::MySqlPool>,
) -> actix_web::Result<HttpResponse, Error> {
    let user: User = sqlx::query_as("SELECT * FROM users WHERE id = ?")
        .bind(id.into_inner().0)
        .fetch_one(&**db)
        .await?;
    Ok(HttpResponse::Ok().json(&user))
}

then, capture bellow information

  • function span (from get_user start to end)
  • .await of sqlx::query* span
    • also capture SQL string
  • if error return (at .await?) and handle by ?, logging the error

See Examples.

Dependencies

~3–4.5MB
~84K SLoC