mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
Log curl command line for all requests at trace
This commit is contained in:
parent
b0f33207fe
commit
5c4062742f
3 changed files with 103 additions and 19 deletions
52
src/main.rs
52
src/main.rs
|
|
@ -147,26 +147,42 @@ async fn run_server() -> Result<(), error::Serve> {
|
|||
let middlewares = ServiceBuilder::new()
|
||||
.sensitive_headers([header::AUTHORIZATION])
|
||||
.layer(axum::middleware::from_fn(spawn_task))
|
||||
.layer(TraceLayer::new_for_http().make_span_with(
|
||||
|request: &http::Request<_>| {
|
||||
let endpoint = if let Some(endpoint) =
|
||||
request.extensions().get::<MatchedPath>()
|
||||
{
|
||||
endpoint.as_str()
|
||||
} else {
|
||||
request.uri().path()
|
||||
};
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.make_span_with(|request: &http::Request<_>| {
|
||||
let endpoint = if let Some(endpoint) =
|
||||
request.extensions().get::<MatchedPath>()
|
||||
{
|
||||
endpoint.as_str()
|
||||
} else {
|
||||
request.uri().path()
|
||||
};
|
||||
|
||||
let method = request.method();
|
||||
let method = request.method();
|
||||
|
||||
tracing::info_span!(
|
||||
"http_request",
|
||||
otel.name = format!("{method} {endpoint}"),
|
||||
%method,
|
||||
%endpoint,
|
||||
)
|
||||
},
|
||||
))
|
||||
tracing::info_span!(
|
||||
"http_request",
|
||||
otel.name = format!("{method} {endpoint}"),
|
||||
%method,
|
||||
%endpoint,
|
||||
)
|
||||
})
|
||||
.on_request(
|
||||
|request: &http::Request<_>, _span: &tracing::Span| {
|
||||
// can be enabled selectively using `filter =
|
||||
// grapevine[incoming_request_curl]=trace` in config
|
||||
tracing::trace_span!("incoming_request_curl").in_scope(
|
||||
|| {
|
||||
tracing::trace!(
|
||||
cmd = utils::curlify(request),
|
||||
"curl command line for incoming request \
|
||||
(guessed hostname)"
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
.layer(axum::middleware::from_fn(unrecognized_method))
|
||||
.layer(
|
||||
CorsLayer::new()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue