Function sentry::with_scope

source ·
pub fn with_scope<C, F, R>(scope_config: C, callback: F) -> Rwhere
    C: FnOnce(&mut Scope),
    F: FnOnce() -> R,
Expand description

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

This function takes two arguments: the first is a callback that is passed a scope and can reconfigure it. The second is callback that then executes in the context of that scope.

This is useful when extra data should be send with a single capture call for instance a different level or tags:

use sentry::{with_scope, Level};
use sentry::integrations::failure::capture_error;

with_scope(
    |scope| scope.set_level(Level::Warning),
    || capture_error(err)
);