From 920cb5ac16d061982ad379172647dff0d306045e Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 7 Nov 2022 09:45:58 +0100 Subject: [PATCH] Capture URL as http.url (#64) --- reqwest-tracing/CHANGELOG.md | 1 + reqwest-tracing/src/lib.rs | 4 ++-- reqwest-tracing/src/reqwest_otel_span_builder.rs | 6 ++++-- reqwest-tracing/src/reqwest_otel_span_macro.rs | 10 ++++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/reqwest-tracing/CHANGELOG.md b/reqwest-tracing/CHANGELOG.md index 68e715e..1f616b3 100644 --- a/reqwest-tracing/CHANGELOG.md +++ b/reqwest-tracing/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- HTTP URL is captured in traces as the `http.url` attribute. ## [0.3.1] - 2022-09-21 - Added support for `opentelemetry` version `0.18`. diff --git a/reqwest-tracing/src/lib.rs b/reqwest-tracing/src/lib.rs index 8649b45..527461c 100644 --- a/reqwest-tracing/src/lib.rs +++ b/reqwest-tracing/src/lib.rs @@ -51,8 +51,8 @@ pub use middleware::TracingMiddleware; pub use reqwest_otel_span_builder::{ default_on_request_end, default_on_request_failure, default_on_request_success, DefaultSpanBackend, ReqwestOtelSpanBackend, ERROR_CAUSE_CHAIN, ERROR_MESSAGE, HTTP_HOST, - HTTP_METHOD, HTTP_SCHEME, HTTP_STATUS_CODE, HTTP_USER_AGENT, NET_HOST_PORT, OTEL_KIND, - OTEL_NAME, OTEL_STATUS_CODE, + HTTP_METHOD, HTTP_SCHEME, HTTP_STATUS_CODE, HTTP_URL, HTTP_USER_AGENT, NET_HOST_PORT, + OTEL_KIND, OTEL_NAME, OTEL_STATUS_CODE, }; #[doc(hidden)] diff --git a/reqwest-tracing/src/reqwest_otel_span_builder.rs b/reqwest-tracing/src/reqwest_otel_span_builder.rs index 04f546f..48901d9 100644 --- a/reqwest-tracing/src/reqwest_otel_span_builder.rs +++ b/reqwest-tracing/src/reqwest_otel_span_builder.rs @@ -12,14 +12,16 @@ pub const HTTP_METHOD: &str = "http.method"; pub const HTTP_SCHEME: &str = "http.scheme"; /// The `http.host` field added to the span by [`reqwest_otel_span`] pub const HTTP_HOST: &str = "http.host"; +/// The `http.url` field added to the span by [`reqwest_otel_span`] +pub const HTTP_URL: &str = "http.url"; /// The `host.port` field added to the span by [`reqwest_otel_span`] pub const NET_HOST_PORT: &str = "net.host.port"; /// The `otel.kind` field added to the span by [`reqwest_otel_span`] pub const OTEL_KIND: &str = "otel.kind"; /// The `otel.name` field added to the span by [`reqwest_otel_span`] pub const OTEL_NAME: &str = "otel.name"; -/// The `otel.status.code` field added to the span by [`reqwest_otel_span`] -pub const OTEL_STATUS_CODE: &str = "otel.status_code"; +/// The `otel.status_code.code` field added to the span by [`reqwest_otel_span`] +pub const OTEL_STATUS_CODE: &str = "http.status_code"; /// The `error.message` field added to the span by [`reqwest_otel_span`] pub const ERROR_MESSAGE: &str = "error.message"; /// The `error.cause_chain` field added to the span by [`reqwest_otel_span`] diff --git a/reqwest-tracing/src/reqwest_otel_span_macro.rs b/reqwest-tracing/src/reqwest_otel_span_macro.rs index 6917c0f..ced64b2 100644 --- a/reqwest-tracing/src/reqwest_otel_span_macro.rs +++ b/reqwest-tracing/src/reqwest_otel_span_macro.rs @@ -114,10 +114,11 @@ macro_rules! reqwest_otel_span { (level=$level:expr, $request:ident, $($field:tt)*) => { { let method = $request.method(); - let scheme = $request.url().scheme(); - let host = $request.url().host_str().unwrap_or(""); - let host_port = $request.url().port().unwrap_or(0) as i64; - let path = $request.url().path(); + let url = $request.url(); + let scheme = url.scheme(); + let host = url.host_str().unwrap_or(""); + let host_port = url.port().unwrap_or(0) as i64; + let path = url.path(); let otel_name = format!("{} {}", method, path); macro_rules! request_span { @@ -128,6 +129,7 @@ macro_rules! reqwest_otel_span { http.method = %method, http.scheme = %scheme, http.host = %host, + http.url = %url, net.host.port = %host_port, otel.kind = "client", otel.name = %otel_name,