pub fn with_scope<C, F, R>(scope_config: C, callback: F) -> RExpand 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:
ยงExamples
use sentry::protocol::Level;
sentry::with_scope(
|scope| scope.set_level(Some(Level::Warning)),
|| sentry::capture_message("some message", Level::Info),
);
assert_eq!(captured_event.level, Level::Warning);Examples found in repository?
examples/send-with-extra.rs (lines 10-19)
3fn main() {
4 let _sentry = sentry::init(
5 sentry::ClientOptions::new()
6 .maybe_release(sentry::release_name!())
7 .debug(true),
8 );
9
10 sentry::with_scope(
11 |scope| {
12 scope.set_level(Some(sentry::Level::Warning));
13 scope.set_fingerprint(Some(["a-message"].as_ref()));
14 scope.set_tag("foo", "bar");
15 },
16 || {
17 panic!("Shit's on fire yo. ๐ฅ ๐");
18 },
19 );
20}