[][src]Function sentry::configure_scope

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

Invokes a function that can modify the current scope.

The function is passed a mutable reference to the Scope so that modifications can be performed. Because there might currently not be a scope or client active it's possible that the callback might not be called at all. As a result of this the return value of this closure must have a default that is returned in such cases.

Examples

use sentry::protocol::{Level, User};

let user = Some(User {
    username: Some("john_doe".into()),
    ..Default::default()
});

sentry::configure_scope(|scope| {
    scope.set_user(user.clone());
});

sentry::capture_message("some message", Level::Info);

assert_eq!(captured_event.user, user);

Panics

While the scope is being configured accessing scope related functionality is not permitted. In this case a wide range of panics will be raised. It's unsafe to call into sentry::bind_client or similar functions from within the callback as a result of this.