mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-26 02:46:30 +00:00
fix: user-agent (#172)
* fix: user-agent * add deprecated_attributes on actions * add package-name/feature-name for visibility
This commit is contained in:
parent
33421175a8
commit
c90089ebd4
2 changed files with 10 additions and 3 deletions
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
|
@ -28,7 +28,7 @@ jobs:
|
||||||
- uses: actions-rs/cargo@v1
|
- uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --workspace --all-targets --features ${{ matrix.otel_version }}
|
args: --workspace --all-targets --features "reqwest-tracing/deprecated_attributes, ${{ matrix.otel_version }}"
|
||||||
|
|
||||||
rustfmt:
|
rustfmt:
|
||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
|
@ -73,7 +73,7 @@ jobs:
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: clippy
|
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:
|
typos:
|
||||||
name: Spell Check with Typos
|
name: Spell Check with Typos
|
||||||
|
@ -109,7 +109,7 @@ jobs:
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: doc
|
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:
|
publish-check:
|
||||||
name: Publish dry run
|
name: Publish dry run
|
||||||
|
|
|
@ -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.
|
/// Populates default success fields for a given [`reqwest_otel_span!`] span.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn default_on_request_success(span: &Span, response: &Response) {
|
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());
|
span.record(HTTP_RESPONSE_STATUS_CODE, response.status().as_u16());
|
||||||
#[cfg(feature = "deprecated_attributes")]
|
#[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_STATUS_CODE, response.status().as_u16());
|
||||||
span.record(HTTP_USER_AGENT, user_agent.as_str());
|
span.record(HTTP_USER_AGENT, user_agent.as_str());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue