diff --git a/sentry-core/src/hub.rs b/sentry-core/src/hub.rs index 456948a0..87226765 100644 --- a/sentry-core/src/hub.rs +++ b/sentry-core/src/hub.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, RwLock}; -use crate::hub_impl::SwitchGuard; +// use crate::hub_impl::SwitchGuard; use crate::protocol::{Event, Level, SessionStatus}; use crate::types::Uuid; use crate::{Integration, IntoBreadcrumbs, Scope, ScopeGuard}; @@ -243,10 +243,4 @@ impl Hub { }) }} } - - #[inline(always)] - /// Consumes self to create switch guard, that can be used to modify current hub in thread local storage - pub fn into_switch_guard(self: Arc) -> SwitchGuard { - crate::hub_impl::SwitchGuard::new(self) - } } diff --git a/sentry-core/src/hub_impl.rs b/sentry-core/src/hub_impl.rs index 6692d1a1..59c91bf9 100644 --- a/sentry-core/src/hub_impl.rs +++ b/sentry-core/src/hub_impl.rs @@ -21,15 +21,17 @@ thread_local! { ); } -///Hub switch guard -/// -///Used to temporarily swap active hub in thread local storage. +/// A Hub switch guard used to temporarily swap +/// active hub in thread local storage. pub struct SwitchGuard { inner: Option<(Arc, bool)>, } impl SwitchGuard { - pub(crate) fn new(mut hub: Arc) -> Self { + /// Swaps the current thread's Hub by the one provided + /// and returns a guard that, when dropped, replaces it + /// to the previous one. + pub fn new(mut hub: Arc) -> Self { let inner = THREAD_HUB.with(|(thread_hub, is_process_hub)| { // SAFETY: `thread_hub` will always be a valid thread local hub, // by definition not shared between threads. diff --git a/sentry-tracing/src/layer.rs b/sentry-tracing/src/layer.rs index e48fd71d..0540fe76 100644 --- a/sentry-tracing/src/layer.rs +++ b/sentry-tracing/src/layer.rs @@ -292,7 +292,7 @@ where let mut extensions = span.extensions_mut(); if let Some(data) = extensions.get_mut::() { - data.hub_switch_guard = Some(data.hub.clone().into_switch_guard()); + data.hub_switch_guard = Some(sentry_core::HubSwitchGuard::new(data.hub.clone())); data.hub.configure_scope(|scope| { scope.set_span(Some(data.sentry_span.clone())); }) @@ -311,7 +311,7 @@ where data.hub.configure_scope(|scope| { scope.set_span(data.parent_sentry_span.clone()); }); - data.hub_switch_guard = None; + data.hub_switch_guard.take(); } }