Manually pass the current context around

This commit is contained in:
Cameron
2025-06-03 14:06:19 -04:00
parent c4153b404c
commit 6aff7f456a
3 changed files with 73 additions and 48 deletions

View File

@@ -82,15 +82,16 @@ pub fn extract_context_from_request(req: &HttpRequest) -> Context {
propagator.extract(&HeaderExtractor(req.headers()))
}
pub fn trace_db_call<F, O>(query_type: &str, operation: &str, func: F) -> anyhow::Result<O>
pub fn trace_db_call<F, O>(context: &Context, query_type: &str, operation: &str, func: F) -> anyhow::Result<O>
where F: FnOnce() -> anyhow::Result<O> {
let tracer = global::tracer("db");
let mut span = tracer
.span_builder(format!("db.{}.{}", query_type, operation))
.with_attributes(vec![
KeyValue::new("db.query_type", query_type.to_string().clone()),
KeyValue::new("db.operation", operation.to_string().clone()),
]).start_with_context(&tracer, &Context::current());
]).start_with_context(&tracer, context);
let result = func();
match &result {