Skip to content

Commit f75f642

Browse files
committed
Use const initialization for INACTIVE_SPAN
This lets us avoid the `LazyLock`. Also remove an unnecessary `Arc::clone` when unwrapping a `SharedSpanHandle::Untracked`.
1 parent f6cd4f3 commit f75f642

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ foundations = { version = "5.1.0", path = "./foundations" }
2929
foundations-macros = { version = "5.1.0", path = "./foundations-macros", default-features = false }
3030
bindgen = { version = "0.72", default-features = false }
3131
cc = "1.0"
32-
cf-rustracing = "1.2"
32+
cf-rustracing = "1.2.1"
3333
cf-rustracing-jaeger = "1.2.2"
3434
clap = "4.4"
3535
darling = "0.21"

foundations/src/telemetry/tracing/internal.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use parking_lot::RwLock;
99
use rand::{self, Rng};
1010
use std::borrow::Cow;
1111
use std::error::Error;
12-
use std::sync::{Arc, LazyLock};
12+
use std::sync::Arc;
1313

1414
pub(crate) type Tracer = cf_rustracing::Tracer<BoxSampler<SpanContextState>, SpanContextState>;
1515

16-
static INACTIVE_SPAN: LazyLock<RwLock<Span>> = LazyLock::new(|| RwLock::new(Span::inactive()));
16+
static INACTIVE_SPAN: RwLock<Span> = RwLock::new(Span::inactive());
1717

1818
/// Shared span with mutability and additional reference tracking for
1919
/// ad-hoc inspection.
@@ -33,15 +33,15 @@ impl SharedSpanHandle {
3333
match self {
3434
SharedSpanHandle::Tracked(handle) => handle.read(),
3535
SharedSpanHandle::Untracked(rw_lock) => rw_lock.read(),
36-
SharedSpanHandle::Inactive => (*INACTIVE_SPAN).read(),
36+
SharedSpanHandle::Inactive => INACTIVE_SPAN.read(),
3737
}
3838
}
3939

4040
pub(crate) fn write(&self) -> parking_lot::RwLockWriteGuard<'_, Span> {
4141
match self {
4242
SharedSpanHandle::Tracked(handle) => handle.write(),
4343
SharedSpanHandle::Untracked(rw_lock) => rw_lock.write(),
44-
SharedSpanHandle::Inactive => (*INACTIVE_SPAN).write(),
44+
SharedSpanHandle::Inactive => INACTIVE_SPAN.write(),
4545
}
4646
}
4747
}
@@ -50,7 +50,7 @@ impl From<SharedSpanHandle> for Arc<RwLock<Span>> {
5050
fn from(value: SharedSpanHandle) -> Self {
5151
match value {
5252
SharedSpanHandle::Tracked(handle) => Arc::clone(&handle),
53-
SharedSpanHandle::Untracked(rw_lock) => Arc::clone(&rw_lock),
53+
SharedSpanHandle::Untracked(rw_lock) => rw_lock,
5454
SharedSpanHandle::Inactive => Arc::new(RwLock::new(Span::inactive())),
5555
}
5656
}

0 commit comments

Comments
 (0)