pub struct Hub { /* private fields */ }
Expand description
The central object that can manages scopes and clients.
This can be used to capture events and manage the scope. This object is internally synchronized so it can be used from multiple threads if needed.
Each thread has its own thread-local (Hub::current()
) hub, which is
automatically derived from the main hub (Hub::main()
).
In most situations developers do not need to interface with the hub directly. Instead
toplevel convenience functions are expose that will automatically dispatch
to the thread-local (Hub::current()
) hub. In some situations this might not be
possible in which case it might become necessary to manually work with the
hub. This is for instance the case when working with async code.
Hubs that are wrapped in Arc
s can be bound to the current thread with
the run
static method.
Most common operations:
Hub::new
: creates a brand new hubHub::current
: returns the thread local hubHub::with
: invoke a callback with the thread local hubHub::with_active
: likeHub::with
but does not invoke the callback if the client is not in a supported state or not boundHub::new_from_top
: creates a new hub with just the top scope of another hub.
Implementations§
Source§impl Hub
impl Hub
Sourcepub fn capture_error<E>(&self, error: &E) -> Uuid
pub fn capture_error<E>(&self, error: &E) -> Uuid
Capture any std::error::Error
.
See the global capture_error
for more documentation.
Source§impl Hub
impl Hub
Sourcepub fn new(client: Option<Arc<Client>>, scope: Arc<Scope>) -> Hub
pub fn new(client: Option<Arc<Client>>, scope: Arc<Scope>) -> Hub
Creates a new hub from the given client and scope.
Sourcepub fn new_from_top<H>(other: H) -> Hub
pub fn new_from_top<H>(other: H) -> Hub
Creates a new hub based on the top scope of the given hub.
Sourcepub fn current() -> Arc<Hub>
pub fn current() -> Arc<Hub>
Returns the current hub.
By default each thread gets a different thread local hub. If an
atomically reference counted hub is available it can override this
one here by calling Hub::run
with a closure.
This method is unavailable if the client implementation is disabled.
When using the minimal API set use Hub::with_active
instead.
Sourcepub fn main() -> Arc<Hub>
pub fn main() -> Arc<Hub>
Returns the main thread’s hub.
This is similar to current
but instead of picking the current
thread’s hub it returns the main thread’s hub instead.
Sourcepub fn with<F, R>(f: F) -> R
pub fn with<F, R>(f: F) -> R
Invokes the callback with the default hub.
This is a slightly more efficient version than Hub::current()
and
also unavailable in minimal mode.
Sourcepub fn with_active<F, R>(f: F) -> R
pub fn with_active<F, R>(f: F) -> R
Like Hub::with
but only calls the function if a client is bound.
This is useful for integrations that want to do efficiently nothing if there is no client bound. Additionally this internally ensures that the client can be safely synchronized. This prevents accidental recursive calls into the client.
Sourcepub fn run<F, R>(hub: Arc<Hub>, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn run<F, R>(hub: Arc<Hub>, f: F) -> Rwhere
F: FnOnce() -> R,
Binds a hub to the current thread for the duration of the call.
Sourcepub fn with_integration<I, F, R>(&self, f: F) -> R
pub fn with_integration<I, F, R>(&self, f: F) -> R
Looks up an integration on the hub.
Calls the given function with the requested integration instance when it is active on the currently active client.
See the global capture_event
for more documentation.
Sourcepub fn last_event_id(&self) -> Option<Uuid>
pub fn last_event_id(&self) -> Option<Uuid>
Returns the last event id.
Sourcepub fn capture_event(&self, event: Event<'static>) -> Uuid
pub fn capture_event(&self, event: Event<'static>) -> Uuid
Sends the event to the current client with the current scope.
In case no client is bound this does nothing instead.
See the global capture_event
for more documentation.
Sourcepub fn capture_message(&self, msg: &str, level: Level) -> Uuid
pub fn capture_message(&self, msg: &str, level: Level) -> Uuid
Captures an arbitrary message.
See the global capture_message
for more documentation.
Sourcepub fn bind_client(&self, client: Option<Arc<Client>>)
pub fn bind_client(&self, client: Option<Arc<Client>>)
Binds a new client to the hub.
Sourcepub fn start_session(&self)
pub fn start_session(&self)
Start a new session for Release Health.
See the global start_session
for more documentation.
Sourcepub fn end_session(&self)
pub fn end_session(&self)
End the current Release Health Session.
See the global end_session
for more documentation.
Sourcepub fn end_session_with_status(&self, status: SessionStatus)
pub fn end_session_with_status(&self, status: SessionStatus)
End the current Release Health Session with the given SessionStatus
.
See the global end_session_with_status
for more documentation.
Sourcepub fn push_scope(&self) -> ScopeGuard
pub fn push_scope(&self) -> ScopeGuard
Pushes a new scope.
This returns a guard that when dropped will pop the scope again.
Sourcepub fn with_scope<C, F, R>(&self, scope_config: C, callback: F) -> R
pub fn with_scope<C, F, R>(&self, scope_config: C, callback: F) -> R
Temporarily pushes a scope for a single call optionally reconfiguring it.
See the global with_scope
for more documentation.
Sourcepub fn configure_scope<F, R>(&self, f: F) -> R
pub fn configure_scope<F, R>(&self, f: F) -> R
Invokes a function that can modify the current scope.
See the global configure_scope
for more documentation.
Adds a new breadcrumb to the current scope.
See the global add_breadcrumb
for more documentation.
Trait Implementations§
Source§impl AnyhowHubExt for Hub
impl AnyhowHubExt for Hub
Source§fn capture_anyhow(&self, e: &Error) -> Uuid
fn capture_anyhow(&self, e: &Error) -> Uuid
anyhow::Error
on a specific hub.Source§impl ErrorChainHubExt for Hub
impl ErrorChainHubExt for Hub
Source§fn capture_error_chain<T>(&self, e: &T) -> Uuid
fn capture_error_chain<T>(&self, e: &T) -> Uuid
error_chain
integration is deprecated and will be removed in the future.Source§impl FailureHubExt for Hub
impl FailureHubExt for Hub
Source§fn capture_error(&self, err: &Error) -> Uuid
fn capture_error(&self, err: &Error) -> Uuid
failure
integration is deprecated and will be removed in the future.failure::Error
).