mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(logging): add a logging middleware to log all api requests (#3437)
This commit is contained in:
@ -92,6 +92,8 @@ impl Visit for Storage<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
const PERSISTENT_KEYS: [&str; 3] = ["payment_id", "connector_name", "merchant_id"];
|
||||
|
||||
impl<S: Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>> Layer<S>
|
||||
for StorageSubscription
|
||||
{
|
||||
@ -99,6 +101,7 @@ impl<S: Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>> Layer
|
||||
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
|
||||
#[allow(clippy::expect_used)]
|
||||
let span = ctx.span(id).expect("No span");
|
||||
let mut extensions = span.extensions_mut();
|
||||
|
||||
let mut visitor = if let Some(parent_span) = span.parent() {
|
||||
let mut extensions = parent_span.extensions_mut();
|
||||
@ -110,7 +113,6 @@ impl<S: Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>> Layer
|
||||
Storage::default()
|
||||
};
|
||||
|
||||
let mut extensions = span.extensions_mut();
|
||||
attrs.record(&mut visitor);
|
||||
extensions.insert(visitor);
|
||||
}
|
||||
@ -150,6 +152,18 @@ impl<S: Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>> Layer
|
||||
.unwrap_or(0)
|
||||
};
|
||||
|
||||
if let Some(s) = span.extensions().get::<Storage<'_>>() {
|
||||
s.values.iter().for_each(|(k, v)| {
|
||||
if PERSISTENT_KEYS.contains(k) {
|
||||
span.parent().and_then(|p| {
|
||||
p.extensions_mut()
|
||||
.get_mut::<Storage<'_>>()
|
||||
.map(|s| s.values.insert(k, v.to_owned()))
|
||||
});
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let mut extensions_mut = span.extensions_mut();
|
||||
#[allow(clippy::expect_used)]
|
||||
let visitor = extensions_mut
|
||||
|
||||
Reference in New Issue
Block a user