fix: user-agent (#172)

* fix: user-agent

* add deprecated_attributes on actions

* add package-name/feature-name for visibility
push-rswvytnyqnqq
Aitor Fernández 2024-07-29 18:47:29 +01:00 committed by GitHub
parent 33421175a8
commit c90089ebd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -78,6 +78,12 @@ pub fn default_on_request_end(span: &Span, outcome: &Result<Response>) {
}
}
#[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());
}