tracing-stackdriver icon indicating copy to clipboard operation
tracing-stackdriver copied to clipboard

httpRequest and spans

Open tomocrafter opened this issue 9 months ago • 0 comments

Hi, Thank you for great crate! I would like to use this on GCE + Cloud Logging environment but httpRequest does not work well if using with spans in tracing.

I made axum Router as:

    Router::new()
        .route("/health", get(health))
        .layer(
            TraceLayer::new_for_http()
                .make_span_with(|request: &Request<_>| {
                    tracing::info_span!(
                        "http_request",
                        http_request.requestMethod = ?request.method(),
                        http_request.requestUrl = %request.uri(),
                        http_request.protocol = ?request.version(),
                    );
                })
        )

but all of info in tracing::info_span! will be in "spans" field, which should be in "httpRequest". I tried following code:

    Router::new()
        .route("/health", get(health))
        .layer(
            TraceLayer::new_for_http()
                .make_span_with(|request: &Request<_>| {
                    tracing::info_span!(
                        "http_request",
                        requestMethod = ?request.method(),
                        requestUrl = %request.uri(),
                        protocol = ?request.version(),
                    );
                })
        )

above code does not work either.

Do I need to add http_request every time I do tracing::info!() ? I hope it can be in spans so I don't need to add those everytime.

Thank you.

tomocrafter avatar May 20 '24 16:05 tomocrafter