-
Notifications
You must be signed in to change notification settings - Fork 892
Open
Labels
Description
In order to record span data (which allows us to write out the service name in the log, and also allows us to determine if certain errors are crits), we store them in an Arc<Mutex<HashMap<_, _>>
. This has the downside of causing us to need to manage the lock, check if it's poisoned, etc. We are also using an unwrap here:
lighthouse/common/logging/src/tracing_logging_layer.rs
Lines 426 to 434 in bde0f1e
if let Some(scope) = ctx.event_scope(event) { | |
for span in scope { | |
let id = span.id(); | |
let span_fields_map = span_fields.lock().unwrap(); | |
if let Some(span_data) = span_fields_map.get(&id) { | |
collected_span_fields.push((span_data.name.clone(), span_data.fields.clone())); | |
} | |
} | |
} |
I believe we can use tracing
's built in Extension
system to manage this data for us, something like this:
let mut extensions = span.extensions_mut();
let span_data = SpanData {
name: attrs.metadata().name().to_string(),
fields: visitor.fields,
};
extensions.insert(span_data);
This would allow us to remove the Mutex
and the unwrap
.