Struct sentry::Hub [−][src]
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 internally synchronized so it can be used from multiple threads if needed. The default hub that is available automatically is thread local.
In most situations developers do not need to interface the hub. Instead
toplevel convenience functions are expose tht will automatically dispatch
to global (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.
Methods
impl Hub
[src]
impl Hub
pub fn new(client: Option<Arc<Client>>, scope: Arc<Scope>) -> Hub
[src]
pub fn new(client: Option<Arc<Client>>, scope: Arc<Scope>) -> Hub
Creates a new hub from the given client and scope.
pub fn new_from_top<H: AsRef<Hub>>(other: H) -> Hub
[src]
pub fn new_from_top<H: AsRef<Hub>>(other: H) -> Hub
Creates a new hub based on the top scope of the given hub.
pub fn current() -> Arc<Hub>
[src]
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.
pub fn main() -> Arc<Hub>
[src]
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.
pub fn with<F, R>(f: F) -> R where
F: FnOnce(&Arc<Hub>) -> R,
[src]
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
F: FnOnce(&Arc<Hub>) -> R,
R: Default,
[src]
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.
pub fn run<F: FnOnce() -> R, R>(hub: Arc<Hub>, f: F) -> R
[src]
pub fn run<F: FnOnce() -> R, R>(hub: Arc<Hub>, f: F) -> R
Binds a hub to the current thread for the duration of the call.
pub fn capture_event(&self, event: Event<'static>) -> Uuid
[src]
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.
pub fn capture_message(&self, msg: &str, level: Level) -> Uuid
[src]
pub fn capture_message(&self, msg: &str, level: Level) -> Uuid
Captures an arbitrary message.
pub fn drain_events(&self, timeout: Option<Duration>)
[src]
pub fn drain_events(&self, timeout: Option<Duration>)
Drains the currently pending events.
pub fn client(&self) -> Option<Arc<Client>>
[src]
pub fn client(&self) -> Option<Arc<Client>>
Returns the currently bound client.
pub fn bind_client(&self, client: Option<Arc<Client>>)
[src]
pub fn bind_client(&self, client: Option<Arc<Client>>)
Binds a new client to the hub.
pub fn push_scope(&self) -> ScopeGuard
[src]
pub fn push_scope(&self) -> ScopeGuard
Pushes a new scope.
This returns a guard that when dropped will pop the scope again.
pub fn configure_scope<F, R>(&self, f: F) -> R where
R: Default,
F: FnOnce(&mut Scope) -> R,
[src]
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.
Adds a new breadcrumb to the current scope.
This is equivalent to the global sentry::add_breadcrumb
but
sends the breadcrumb into the hub instead.
pub fn add_event_processor<F: FnOnce() -> Box<Fn(&mut Event) + Send + Sync> + 'static>(
&self,
f: F
)
[src]
pub fn add_event_processor<F: FnOnce() -> Box<Fn(&mut Event) + Send + Sync> + 'static>(
&self,
f: F
)
Registers an event processor with the topmost scope.
An event processor here is returned by an FnOnce()
function that returns a
function taking an Event that needs to be Send + Sync
. By having the
function be a factory for the actual event processor the outer function does
not have to be Sync
as sentry will execute it before a hub crosses a thread
boundary.
Threading
If a hub is used from multiple threads event processors might not be executed
if another thread triggers an event processor first. For such cases
add_send_event_processor
must be used instead. This means that if thread 1
will add the processor but thread 2 will send the next event, then processors
are not run until thread 1 sends an event. Processors are also triggered
if a scope is pushed or a hub is created from this hub via Hub::new_from_top
.
pub fn add_send_event_processor<F: FnOnce() -> Box<Fn(&mut Event) + Send + Sync> + Send + Sync + 'static>(
&self,
f: F
)
[src]
pub fn add_send_event_processor<F: FnOnce() -> Box<Fn(&mut Event) + Send + Sync> + Send + Sync + 'static>(
&self,
f: F
)
Registers a sendable event processor with the topmost scope.
This works like add_event_processor
but registers functions that are Send
which permits them to be used from multiple threads. If a hub is used from
multiple threads at once then only sendable event processors will be guaranteed
to run.
Trait Implementations
impl FailureHubExt for Hub
[src]
impl FailureHubExt for Hub
fn capture_error(&self, err: &Error) -> Uuid
[src]
fn capture_error(&self, err: &Error) -> Uuid
Captures a boxed failure (failure::Error
).
fn capture_fail<F: Fail + ?Sized>(&self, fail: &F) -> Uuid
[src]
fn capture_fail<F: Fail + ?Sized>(&self, fail: &F) -> Uuid
Captures a failure::Fail
.
impl ErrorChainHubExt for Hub
[src]
impl ErrorChainHubExt for Hub
fn capture_error_chain<T>(&self, e: &T) -> Uuid where
T: ChainedError,
T::ErrorKind: Debug + Display,
[src]
fn capture_error_chain<T>(&self, e: &T) -> Uuid where
T: ChainedError,
T::ErrorKind: Debug + Display,
Captures an error chain on a specific hub.