Author:
Hash:
Timestamp:
+10 -3 +/-1 browse
Kevin Schoon [me@kevinschoon.com]
4ecd0169aeab3725e8e015532e7b73c5122e4847
Sun, 13 Apr 2025 12:13:34 +0000 (6 months ago)
| 1 | diff --git a/examples/server.rs b/examples/server.rs |
| 2 | index 118c051..8456ba5 100644 |
| 3 | --- a/examples/server.rs |
| 4 | +++ b/examples/server.rs |
| 5 | @@ -1,10 +1,10 @@ |
| 6 | - use std::{error::Error, path::Path, str::FromStr}; |
| 7 | + use std::{collections::HashMap, error::Error, path::Path, str::FromStr}; |
| 8 | |
| 9 | use axum::{Router, extract::Request}; |
| 10 | use papyri::storage::Storage; |
| 11 | use tower::Layer; |
| 12 | use tower_http::{normalize_path::NormalizePathLayer, trace::TraceLayer}; |
| 13 | - use tracing::{Level, info_span}; |
| 14 | + use tracing::{event, info_span, trace, Level}; |
| 15 | |
| 16 | const ADDRESS: &str = "127.0.0.1:8700"; |
| 17 | |
| 18 | @@ -33,7 +33,14 @@ async fn main() -> Result<(), Box<dyn Error>> { |
| 19 | .nest_service("/v2/", middleware.layer(registry)) |
| 20 | .layer(TraceLayer::new_for_http().make_span_with( |
| 21 | |req: &Request<_>| { |
| 22 | - info_span!("http_request", method = ?req.method(), uri = req.uri().to_string()) |
| 23 | + let headers: Vec<(String, String)> = req.headers().iter().map(|(key, value)| (key.to_string(), value.to_str().unwrap().to_string())).collect(); |
| 24 | + let span = info_span!("http_request", method = ?req.method(), uri = req.uri().to_string()); |
| 25 | + span.in_scope(|| { |
| 26 | + headers.iter().for_each(|(key, value)| { |
| 27 | + event!(Level::DEBUG, key = key, value = value); |
| 28 | + }) |
| 29 | + }); |
| 30 | + span |
| 31 | }, |
| 32 | )) |
| 33 | .layer(NormalizePathLayer::trim_trailing_slash()); |