Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce locking in the implementation of Layer::on_close #173

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,25 +1104,31 @@ where
/// [`Span`]: opentelemetry::trace::Span
fn on_close(&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();
let (otel_data, timings) = {
let mut extensions = span.extensions_mut();
let timings = if self.tracked_inactivity {
extensions.remove::<Timings>()
} else {
None
};
(extensions.remove::<OtelData>(), timings)
};

if let Some(OtelData {
mut builder,
parent_cx,
}) = extensions.remove::<OtelData>()
}) = otel_data
{
if self.tracked_inactivity {
// Append busy/idle timings when enabled.
if let Some(timings) = extensions.get_mut::<Timings>() {
let busy_ns = Key::new("busy_ns");
let idle_ns = Key::new("idle_ns");
// Append busy/idle timings when enabled.
if let Some(timings) = timings {
let busy_ns = Key::new("busy_ns");
let idle_ns = Key::new("idle_ns");

let attributes = builder
.attributes
.get_or_insert_with(|| Vec::with_capacity(2));
attributes.push(KeyValue::new(busy_ns, timings.busy));
attributes.push(KeyValue::new(idle_ns, timings.idle));
}
let attributes = builder
.attributes
.get_or_insert_with(|| Vec::with_capacity(2));
attributes.push(KeyValue::new(busy_ns, timings.busy));
attributes.push(KeyValue::new(idle_ns, timings.idle));
}

// Build and start span, drop span to export
Expand Down
Loading