Skip to content

Commit 620ec61

Browse files
Rasmus ViitanenFishrock123
authored andcommitted
use replace instead of insert to add extension
Previously `ExtensionsMut::insert` was used without a guarantee that we had exclusive access to a SpanRef's extensions. This could lead to a panic in the `insert` function in the case where the extension was inserted concurrently by multiple calls to `eval_ctx`. By using `replace` the assertion is ignored and it no longer matters whether we have exclusive access or not to a span in `eval_ctx`.
1 parent 53aeced commit 620ec61

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tracing-distributed/src/telemetry_layer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ where
9999

100100
for span_ref in path.into_iter() {
101101
let mut write_guard = span_ref.extensions_mut();
102-
write_guard.insert::<LazyTraceCtx<SpanId, TraceId>>(LazyTraceCtx(
102+
write_guard.replace::<LazyTraceCtx<SpanId, TraceId>>(LazyTraceCtx(
103103
TraceCtx {
104104
trace_id: local_trace_root.trace_id.clone(),
105105
parent_span: None,
@@ -122,7 +122,7 @@ where
122122

123123
for span_ref in path.into_iter() {
124124
let mut write_guard = span_ref.extensions_mut();
125-
write_guard.insert::<LazyTraceCtx<SpanId, TraceId>>(LazyTraceCtx(
125+
write_guard.replace::<LazyTraceCtx<SpanId, TraceId>>(LazyTraceCtx(
126126
TraceCtx {
127127
trace_id: already_evaluated.trace_id.clone(),
128128
parent_span: None,

0 commit comments

Comments
 (0)