Skip to content

Commit 0e89efa

Browse files
committed
fix: set span end time when it exits
Setting end time when a span is closed makes it impossible for child spans to live longer than their parents if we want to keep the relationship in `tracing` itself.
1 parent 5e3354e commit 0e89efa

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/layer.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,19 @@ where
970970
}
971971

972972
fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
973+
let span = ctx.span(id).expect("Span not found, this is a bug");
974+
let mut extensions = span.extensions_mut();
975+
976+
extensions
977+
.get_mut::<OtelData>()
978+
.expect("Missing otel data span extensions")
979+
.builder
980+
.end_time = Some(crate::time::now());
981+
973982
if !self.tracked_inactivity {
974983
return;
975984
}
976985

977-
let span = ctx.span(id).expect("Span not found, this is a bug");
978-
let mut extensions = span.extensions_mut();
979-
980986
if let Some(timings) = extensions.get_mut::<Timings>() {
981987
let now = Instant::now();
982988
timings.busy += (now - timings.last).as_nanos() as i64;
@@ -1165,9 +1171,7 @@ where
11651171
}
11661172

11671173
// Assign end time, build and start span, drop span to export
1168-
builder
1169-
.with_end_time(crate::time::now())
1170-
.start_with_context(&self.tracer, &parent_cx);
1174+
builder.start_with_context(&self.tracer, &parent_cx);
11711175
}
11721176
}
11731177

0 commit comments

Comments
 (0)