Struct sentry_core::Client
source · [−]pub struct Client { /* private fields */ }
Expand description
The Sentry Client.
The Client is responsible for event processing and sending events to the
sentry server via the configured Transport
. It can be created from a
ClientOptions
.
See the Unified API document for more details.
Examples
sentry::Client::from(sentry::ClientOptions::default());
Implementations
sourceimpl Client
impl Client
sourcepub fn from_config<O: Into<ClientOptions>>(opts: O) -> Client
pub fn from_config<O: Into<ClientOptions>>(opts: O) -> Client
Creates a new Sentry client from a config.
Supported Configs
The following common values are supported for the client config:
ClientOptions
: configure the client with the given client options.()
or empty string: Disable the client.&str
/String
/&OsStr
/String
: configure the client with the given DSN.Dsn
/&Dsn
: configure the client with a given DSN.(Dsn, ClientOptions)
: configure the client from the given DSN and optional options.
The Default
implementation of ClientOptions
pulls in the DSN from the
SENTRY_DSN
environment variable.
Panics
The Into<ClientOptions>
implementations can panic for the forms where a DSN needs to be
parsed. If you want to handle invalid DSNs you need to parse them manually by calling
parse on it and handle the error.
sourcepub fn with_options(options: ClientOptions) -> Client
pub fn with_options(options: ClientOptions) -> Client
Creates a new sentry client for the given options.
If the DSN on the options is set to None
the client will be entirely
disabled.
sourcepub fn options(&self) -> &ClientOptions
pub fn options(&self) -> &ClientOptions
Returns the options of this client.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Quick check to see if the client is enabled.
The Client is enabled if it has a valid DSN and Transport configured.
Examples
use std::sync::Arc;
let client = sentry::Client::from(sentry::ClientOptions::default());
assert!(!client.is_enabled());
let dsn = "https://public@example.com/1";
let transport = sentry::test::TestTransport::new();
let client = sentry::Client::from((
dsn,
sentry::ClientOptions {
transport: Some(Arc::new(transport)),
..Default::default()
},
));
assert!(client.is_enabled());
sourcepub fn capture_event(
&self,
event: Event<'static>,
scope: Option<&Scope>
) -> Uuid
pub fn capture_event(
&self,
event: Event<'static>,
scope: Option<&Scope>
) -> Uuid
Captures an event and sends it to sentry.
sourcepub fn send_envelope(&self, envelope: Envelope)
pub fn send_envelope(&self, envelope: Envelope)
Sends the specified Envelope
to sentry.
sourcepub fn flush(&self, timeout: Option<Duration>) -> bool
pub fn flush(&self, timeout: Option<Duration>) -> bool
Drains all pending events without shutting down.
sourcepub fn close(&self, timeout: Option<Duration>) -> bool
pub fn close(&self, timeout: Option<Duration>) -> bool
Drains all pending events and shuts down the transport behind the client. After shutting down the transport is removed.
This returns true
if the queue was successfully drained in the
given time or false
if not (for instance because of a timeout).
If no timeout is provided the client will wait for as long a
shutdown_timeout
in the client options.
sourcepub fn sample_traces_should_send(&self) -> bool
pub fn sample_traces_should_send(&self) -> bool
Returns a random boolean with a probability defined
by the ClientOptions
’s traces_sample_rate
Trait Implementations
sourceimpl<T: Into<ClientOptions>> From<T> for Client
impl<T: Into<ClientOptions>> From<T> for Client
impl RefUnwindSafe for Client
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more