Skip to content

Commit

Permalink
fix: set span end time when it exits
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mladedav authored and djc committed May 24, 2024
1 parent d0123e4 commit afe9b33
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<OtelData>() {
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::<Timings>() {
let now = Instant::now();
timings.busy += (now - timings.last).as_nanos() as i64;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit afe9b33

Please sign in to comment.