diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4eba60..6f64683 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: test - args: --workspace --all-targets --features ${{ matrix.otel_version }} + args: --workspace --all-targets --features "reqwest-tracing/deprecated_attributes, ${{ matrix.otel_version }}" rustfmt: name: Rustfmt @@ -73,7 +73,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --all-targets --features ${{ matrix.otel_version }} --workspace -- -D warnings + args: --all-targets --features "reqwest-tracing/deprecated_attributes, ${{ matrix.otel_version }}" --workspace -- -D warnings typos: name: Spell Check with Typos @@ -109,7 +109,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: doc - args: --no-deps --document-private-items --features ${{ matrix.otel_version }} --workspace + args: --no-deps --document-private-items --features "reqwest-tracing/deprecated_attributes, ${{ matrix.otel_version }}" --workspace publish-check: name: Publish dry run diff --git a/reqwest-tracing/src/reqwest_otel_span_builder.rs b/reqwest-tracing/src/reqwest_otel_span_builder.rs index 86bce52..7848389 100644 --- a/reqwest-tracing/src/reqwest_otel_span_builder.rs +++ b/reqwest-tracing/src/reqwest_otel_span_builder.rs @@ -78,6 +78,12 @@ pub fn default_on_request_end(span: &Span, outcome: &Result) { } } +#[cfg(feature = "deprecated_attributes")] +fn get_header_value(key: &str, headers: &reqwest::header::HeaderMap) -> String { + let header_default = &reqwest::header::HeaderValue::from_static(""); + format!("{:?}", headers.get(key).unwrap_or(header_default)).replace('"', "") +} + /// Populates default success fields for a given [`reqwest_otel_span!`] span. #[inline] pub fn default_on_request_success(span: &Span, response: &Response) { @@ -88,6 +94,7 @@ pub fn default_on_request_success(span: &Span, response: &Response) { span.record(HTTP_RESPONSE_STATUS_CODE, response.status().as_u16()); #[cfg(feature = "deprecated_attributes")] { + let user_agent = get_header_value("user_agent", response.headers()); span.record(HTTP_STATUS_CODE, response.status().as_u16()); span.record(HTTP_USER_AGENT, user_agent.as_str()); }