[][src]Struct sentry::Hub

pub struct Hub { /* fields omitted */ }

The central object that can manages scopes and clients.

This can be used to capture events and manage the scope. This object is Send and Sync so it can be used from multiple threads if needed.

Each thread has its own thread-local ( see 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 Arcs can be bound to the current thread with the run static method.

Most common operations:

  • Hub::new: creates a brand new hub
  • Hub::current: returns the thread local hub
  • Hub::with: invoke a callback with the thread local hub
  • Hub::with_active: like Hub::with but does not invoke the callback if the client is not in a supported state or not bound
  • Hub::new_from_top: creates a new hub with just the top scope of another hub.


impl Hub[src]

pub fn capture_error<E>(&self, error: &E) -> Uuid where
    E: Error + ?Sized

Capture any std::error::Error.

See the global capture_error for more documentation.

impl Hub[src]

pub fn new(client: Option<Arc<Client>>, scope: Arc<Scope>) -> Hub[src]

Creates a new hub from the given client and scope.

pub fn new_from_top<H>(other: H) -> Hub where
    H: AsRef<Hub>, 

Creates a new hub based on the top scope of the given hub.

pub fn current() -> Arc<Hub>[src]

Returns the current, thread-local hub.

Invoking this will return the current thread-local hub. The first time it is called on a thread, a new thread-local hub will be created based on the topmost scope of the hub on the main thread as returned by Hub::main. If the main thread did not yet have a hub it will be created when invoking this function.

To have control over which hub is installed as the current thread-local hub, use Hub::run.

This method is unavailable if the client implementation is disabled. When using the minimal API set use Hub::with_active instead.

pub fn main() -> Arc<Hub>[src]

Returns the main thread's hub.

This is similar to Hub::current but instead of picking the current thread's hub it returns the main thread's hub instead.

pub fn with<F, R>(f: F) -> R where
    F: FnOnce(&Arc<Hub>) -> R, 

Invokes the callback with the default hub.

This is a slightly more efficient version than Hub::current and also unavailable in minimal mode.

pub fn with_active<F, R>(f: F) -> R where
    R: Default,
    F: FnOnce(&Arc<Hub>) -> 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.

pub fn run<F, R>(hub: Arc<Hub>, f: F) -> R where
    F: FnOnce() -> R, 

Binds a hub to the current thread for the duration of the call.

During the execution of f the given hub will be installed as the thread-local hub. So any call to Hub::current during this time will return the provided hub.

Once the function is finished executing, including after it paniced, the original hub is re-installed if one was present.

pub fn with_integration<I, F, R>(&self, f: F) -> R where
    R: Default,
    F: FnOnce(&I) -> R,
    I: Integration

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.

pub fn last_event_id(&self) -> Option<Uuid>[src]

Returns the last event id.

pub fn capture_event(&self, event: Event<'static>) -> Uuid[src]

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.

pub fn capture_message(&self, msg: &str, level: Level) -> Uuid[src]

Captures an arbitrary message.

See the global capture_message for more documentation.

pub fn client(&self) -> Option<Arc<Client>>[src]

Returns the currently bound client.

pub fn bind_client(&self, client: Option<Arc<Client>>)[src]

Binds a new client to the hub.

pub fn start_session(&self)[src]

Start a new session for Release Health.

See the global start_session for more documentation.

pub fn end_session(&self)[src]

End the current Release Health Session.

See the global sentry::end_session for more documentation.

pub fn end_session_with_status(&self, status: SessionStatus)[src]

End the current Release Health Session with the given SessionStatus.

See the global end_session_with_status for more documentation.

pub fn push_scope(&self) -> ScopeGuard[src]

Pushes a new scope.

This returns a guard that when dropped will pop the scope again.

pub fn with_scope<C, F, R>(&self, scope_config: C, callback: F) -> R where
    C: FnOnce(&mut Scope),
    F: FnOnce() -> R, 

Temporarily pushes a scope for a single call optionally reconfiguring it.

See the global with_scope for more documentation.

pub fn configure_scope<F, R>(&self, f: F) -> R where
    R: Default,
    F: FnOnce(&mut Scope) -> R, 

Invokes a function that can modify the current scope.

See the global configure_scope for more documentation.

pub fn add_breadcrumb<B>(&self, breadcrumb: B) where
    B: IntoBreadcrumbs

Adds a new breadcrumb to the current scope.

See the global add_breadcrumb for more documentation.

Trait Implementations

impl AnyhowHubExt for Hub[src]

impl Debug for Hub[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SendSyncUnwindSafe for T where
    T: Send + Sync + UnwindSafe + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]