use std::sync::Arc;
use std::time::Duration;
use uuid::Uuid;
use api::protocol::{Breadcrumb, Event};
pub use sentry_types::{Dsn, DsnParseError, ProjectId, ProjectIdParseError};
pub use sentry_types::protocol::v7 as protocol;
pub use sentry_types::protocol::v7::{Level, User};
pub use client::Client;
#[cfg(feature = "with_client_implementation")]
pub use client::{init, ClientInitGuard, ClientOptions, IntoClientConfig};
pub use scope::{bind_client, current_client, push_scope, with_client_and_scope, Scope, ScopeGuard};
#[allow(unused_variables)]
pub fn capture_event(event: Event<'static>) -> Uuid {
with_client_impl! {{
with_client_and_scope(|client, scope| client.capture_event(event, Some(scope)))
}}
}
#[allow(unused_variables)]
pub fn capture_exception(ty: &str, value: Option<String>) -> Uuid {
with_client_impl! {{
use api::protocol::Exception;
use utils::current_stacktrace;
with_client_and_scope(|client, scope| {
let event = Event {
exceptions: vec![
Exception {
ty: ty.to_string(),
value: value,
stacktrace: current_stacktrace(),
..Default::default()
},
],
..Default::default()
};
client.capture_event(event, Some(scope))
})
}}
}
#[allow(unused_variables)]
pub fn capture_message(msg: &str, level: Level) -> Uuid {
with_client_impl! {{
with_client_and_scope(|client, scope| {
let event = Event {
message: Some(msg.to_string()),
level: level,
..Default::default()
};
client.capture_event(event, Some(scope))
})
}}
}
#[allow(unused_variables)]
pub fn add_breadcrumb<F: FnOnce() -> Breadcrumb>(f: F) {
with_client_impl! {{
use scope::with_client_and_scope_mut;
with_client_and_scope_mut(|client, scope| {
let limit = client.options().max_breadcrumbs;
if limit > 0 {
scope.breadcrumbs = scope.breadcrumbs.push_back(f());
while scope.breadcrumbs.len() > limit {
if let Some((_, new)) = scope.breadcrumbs.pop_front() {
scope.breadcrumbs = new;
}
}
}
})
}}
}
#[allow(unused_variables)]
pub fn drain_events(timeout: Option<Duration>) {
with_client_impl! {{
with_client_and_scope(|client, _| {
client.drain_events(timeout);
});
}}
}
#[allow(unused_variables)]
pub fn configure_scope<F, R>(f: F) -> R
where
R: Default,
F: FnOnce(&mut Scope) -> R,
{
with_client_impl! {{
use scope::with_client_and_scope_mut;
if let Some((new_scope, rv)) = with_client_and_scope(|_, scope| {
let mut new_scope = scope.clone();
let rv = f(&mut new_scope);
Some((new_scope, rv))
}) {
with_client_and_scope_mut(|_, scope| *scope = new_scope);
rv
} else {
Default::default()
}
}}
}
#[allow(unused_variables)]
pub fn with_scope<F, R>(f: F) -> R
where
F: FnOnce() -> R,
{
let _guard = push_scope();
f()
}
#[derive(Default, Clone)]
pub struct ScopeHandle(Option<(Arc<Client>, Arc<Scope>)>);
pub fn scope_handle() -> ScopeHandle {
with_client_impl! {{
with_client_and_scope(|client, scope| {
ScopeHandle(Some((client, Arc::new(scope.clone()))))
})
}}
}
impl ScopeHandle {
pub fn bind(self) {
with_client_impl! {{
use scope::with_client_and_scope_mut;
if let Some((src_client, src_scope)) = self.0 {
bind_client(src_client);
with_client_and_scope_mut(|_, scope| {
*scope = Arc::try_unwrap(src_scope)
.unwrap_or_else(|arc| (*arc).clone());
})
}
}}
}
}