Hub

Struct Hub 

Source
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 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.

Implementations§

Source§

impl Hub

Source

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.

Source§

impl Hub

Source

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

Creates a new hub from the given client and scope.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

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.

Source

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.

Source

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

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.

Source

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

Returns the last event id.

Source

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.

Source

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

Captures an arbitrary message.

See the global capture_message for more documentation.

Source

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

Returns the currently bound client.

Source

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

Binds a new client to the hub.

Source

pub fn start_session(&self)

Start a new session for Release Health.

See the global start_session for more documentation.

Source

pub fn end_session(&self)

End the current Release Health Session.

See the global end_session for more documentation.

Source

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.

Source

pub fn push_scope(&self) -> ScopeGuard

Pushes a new scope.

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

Source

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.

Source

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.

Source

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§

Source§

impl AnyhowHubExt for Hub

Source§

fn capture_anyhow(&self, e: &Error) -> Uuid

Captures an anyhow::Error on a specific hub.
Source§

impl Debug for Hub

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl ErrorChainHubExt for Hub

Source§

fn capture_error_chain<T>(&self, e: &T) -> Uuid

👎Deprecated: The error_chain integration is deprecated and will be removed in the future.
Captures an error chain on a specific hub.
Source§

impl FailureHubExt for Hub

Source§

fn capture_error(&self, err: &Error) -> Uuid

👎Deprecated: The failure integration is deprecated and will be removed in the future.
Captures a boxed failure (failure::Error).
Source§

fn capture_fail<F>(&self, fail: &F) -> Uuid
where F: Fail + ?Sized,

👎Deprecated: The failure integration is deprecated and will be removed in the future.
Captures a failure::Fail.

Auto Trait Implementations§

§

impl !Freeze for Hub

§

impl RefUnwindSafe for Hub

§

impl Send for Hub

§

impl Sync for Hub

§

impl Unpin for Hub

§

impl UnwindSafe for Hub

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

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