This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod configuration; | ||
pub mod request_id; | ||
pub mod routes; | ||
pub mod startup; | ||
pub mod telemetry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use axum::{ | ||
body::Body, | ||
http::{HeaderName, HeaderValue, Request}, | ||
}; | ||
use tower_http::request_id::{MakeRequestId, RequestId}; | ||
use uuid::Uuid; | ||
|
||
#[derive(Clone)] | ||
pub struct RequestUuid; | ||
|
||
impl MakeRequestId for RequestUuid { | ||
fn make_request_id<B>(&mut self, _: &Request<B>) -> Option<RequestId> { | ||
match HeaderValue::from_str(&Uuid::new_v4().to_string()) { | ||
Ok(value) => Some(RequestId::new(value)), | ||
Err(e) => { | ||
tracing::warn!("Failed to create request id header value: {e:?}"); | ||
None | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn from_x_request_id(request: &Request<Body>) -> Option<&str> { | ||
request | ||
.headers() | ||
.get(HeaderName::from_static("x-request-id")) | ||
.and_then(|value| match value.to_str() { | ||
Ok(value) => Some(value), | ||
Err(e) => { | ||
tracing::warn!("Failed to convert x-request-id to str: {e:?}"); | ||
None | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters