Skip to content

Commit a1137c9

Browse files
committed
feat: Added support for unbinding clients
1 parent 08ebb36 commit a1137c9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/api.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub use sentry_types::protocol::v7::{Level, User};
1313
pub use client::Client;
1414
#[cfg(feature = "with_client_implementation")]
1515
pub use client::{init, ClientInitGuard, ClientOptions, IntoClientConfig};
16-
pub use scope::{bind_client, current_client, push_scope, with_client_and_scope, Scope, ScopeGuard};
16+
pub use scope::{bind_client, current_client, push_scope, unbind_client, with_client_and_scope,
17+
Scope, ScopeGuard};
1718

1819
/// Captures an event on the currently active client if any.
1920
///

src/scope/noop.rs

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ pub fn bind_client(client: Arc<Client>) {
6262
shim_unreachable!();
6363
}
6464

65+
/// Unbinds a client.
66+
///
67+
/// In the shim only mode this function doesn't do anything.
68+
pub fn unbind_client() {}
69+
6570
impl Scope {
6671
pub fn clear(&mut self) {
6772
shim_unreachable!();

src/scope/real.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ impl Stack {
131131
self.layers.pop().unwrap();
132132
}
133133

134-
pub fn bind_client(&mut self, client: Arc<Client>) {
134+
pub fn bind_client(&mut self, client: Option<Arc<Client>>) {
135135
let depth = self.layers.len() - 1;
136-
self.layers[depth].client = Some(client);
136+
self.layers[depth].client = client;
137137
}
138138

139139
pub fn client(&self) -> Option<Arc<Client>> {
@@ -304,7 +304,16 @@ pub fn current_client() -> Option<Arc<Client>> {
304304
/// process.
305305
pub fn bind_client(client: Arc<Client>) {
306306
with_client_impl! {{
307-
with_stack_mut(|stack| stack.bind_client(client));
307+
with_stack_mut(|stack| stack.bind_client(Some(client)));
308+
}}
309+
}
310+
311+
/// Unbinds the client on the current scope.
312+
///
313+
/// This effectively prevents data collection and reporting on the current scope.
314+
pub fn unbind_client() {
315+
with_client_impl! {{
316+
with_stack_mut(|stack| stack.bind_client(None));
308317
}}
309318
}
310319

0 commit comments

Comments
 (0)