diff --git a/src/layer.rs b/src/layer.rs index 83bed1d..43d2193 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -970,13 +970,17 @@ where } fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) { + let span = ctx.span(id).expect("Span not found, this is a bug"); + let mut extensions = span.extensions_mut(); + + if let Some(otel_data) = extensions.get_mut::() { + otel_data.builder.end_time = Some(crate::time::now()); + } + if !self.tracked_inactivity { return; } - let span = ctx.span(id).expect("Span not found, this is a bug"); - let mut extensions = span.extensions_mut(); - if let Some(timings) = extensions.get_mut::() { let now = Instant::now(); timings.busy += (now - timings.last).as_nanos() as i64; @@ -1165,9 +1169,7 @@ where } // Assign end time, build and start span, drop span to export - builder - .with_end_time(crate::time::now()) - .start_with_context(&self.tracer, &parent_cx); + builder.start_with_context(&self.tracer, &parent_cx); } }