opentelemetry-auto-span

Crates.ioopentelemetry-auto-span
lib.rsopentelemetry-auto-span
version0.4.0
sourcesrc
created_at2022-08-09 11:36:48.269078
updated_at2024-11-30 12:04:25.648855
descriptionA helper library for opentelemetry tracing
homepage
repositoryhttps://github.com/hinohi/rust-opentelemetry-auto-span
max_upload_size
id641734
size298,535
daiju (hinohi)

documentation

README

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.

Commit count: 72

cargo fmt