Struct sentry_contrib_native::Options
source · [−]pub struct Options { /* private fields */ }
Expand description
Implementations
sourceimpl Options
impl Options
sourcepub fn set_transport<S: FnOnce(&Self) -> Result<T, ()> + 'static + Send + Sync, T: Into<Box<T>> + Transport>(
&mut self,
startup: S
)
pub fn set_transport<S: FnOnce(&Self) -> Result<T, ()> + 'static + Send + Sync, T: Into<Box<T>> + Transport>(
&mut self,
startup: S
)
Sets a custom transport. This only affects events sent through
Event::capture
, not the crash handler.
The startup
parameter is a function that serves as a one-time
initialization event for your Transport
, it takes a
&Options
and has to return an Result<Transport, ()>
, an Err
will cause Options::init
to fail.
Notes
Unwinding panics of functions in startup
will be cought and
abort
will be called if any occured.
Examples
let mut options = Options::new();
options.set_transport(|_| {
Ok(|envelope: RawEnvelope| println!("Event to be sent: {:?}", envelope.event()))
});
See Transport
for a more detailed documentation.
sourcepub fn set_before_send<B: Into<Box<B>> + BeforeSend>(&mut self, before_send: B)
pub fn set_before_send<B: Into<Box<B>> + BeforeSend>(&mut self, before_send: B)
Sets a callback that is triggered before sending an event through
Event::capture
.
Notes
Unwinding panics of functions in before_send
will be cought and
abort
will be called if any occured.
Examples
let mut options = Options::new();
options.set_before_send(|mut value| {
// do something with the value and then return it
value
});
sourcepub fn dsn(&self) -> Option<&str>
pub fn dsn(&self) -> Option<&str>
Gets the DSN.
Examples
let mut options = Options::new();
options.set_dsn("yourdsn.com");
assert_eq!(Some("yourdsn.com"), options.dsn());
sourcepub fn set_sample_rate(&mut self, sample_rate: f64) -> Result<(), Error>
pub fn set_sample_rate(&mut self, sample_rate: f64) -> Result<(), Error>
Sets the sample rate, which should be a f64
between 0.0
and 1.0
.
Sentry will randomly discard any event that is captured using Event
when a sample rate < 1.0 is set.
Errors
Fails with Error::SampleRateRange
if sample_rate
is smaller than
0.0
or bigger than 1.0
.
Examples
let mut options = Options::new();
options.set_sample_rate(0.5);
sourcepub fn sample_rate(&self) -> f64
pub fn sample_rate(&self) -> f64
Gets the sample rate.
Examples
let mut options = Options::new();
options.set_sample_rate(0.5)?;
assert_eq!(0.5, options.sample_rate());
sourcepub fn set_release<S: Into<String>>(&mut self, release: S)
pub fn set_release<S: Into<String>>(&mut self, release: S)
sourcepub fn release(&self) -> Option<&str>
pub fn release(&self) -> Option<&str>
Gets the release.
Examples
let mut options = Options::new();
options.set_release("1.0");
assert_eq!(Some("1.0"), options.release());
sourcepub fn set_environment<S: Into<String>>(&mut self, environment: S)
pub fn set_environment<S: Into<String>>(&mut self, environment: S)
Sets the environment.
Examples
let mut options = Options::new();
options.set_environment("production");
sourcepub fn environment(&self) -> Option<&str>
pub fn environment(&self) -> Option<&str>
Gets the environment.
Examples
let mut options = Options::new();
options.set_environment("production");
assert_eq!(Some("production"), options.environment());
sourcepub fn set_distribution<S: Into<String>>(&mut self, distribution: S)
pub fn set_distribution<S: Into<String>>(&mut self, distribution: S)
Sets the distribution.
Examples
let mut options = Options::new();
options.set_distribution("release-pgo");
sourcepub fn distribution(&self) -> Option<&str>
pub fn distribution(&self) -> Option<&str>
Gets the distribution.
Examples
let mut options = Options::new();
options.set_distribution("release-pgo");
assert_eq!(Some("release-pgo"), options.distribution());
sourcepub fn set_http_proxy<S: Into<String>>(&mut self, proxy: S)
pub fn set_http_proxy<S: Into<String>>(&mut self, proxy: S)
Configures the http proxy.
The given proxy has to include the full scheme, eg. http://some.proxy/
.
Examples
let mut options = Options::new();
options.set_http_proxy("http://some.proxy/");
sourcepub fn http_proxy(&self) -> Option<&str>
pub fn http_proxy(&self) -> Option<&str>
Returns the configured http proxy.
Examples
let mut options = Options::new();
options.set_http_proxy("http://some.proxy/");
assert_eq!(Some("http://some.proxy/"), options.http_proxy());
sourcepub fn set_ca_certs<S: Into<String>>(&mut self, path: S)
pub fn set_ca_certs<S: Into<String>>(&mut self, path: S)
Configures the path to a file containing SSL certificates for verification.
Examples
let mut options = Options::new();
options.set_ca_certs("certs.pem");
sourcepub fn ca_certs(&self) -> Option<&str>
pub fn ca_certs(&self) -> Option<&str>
Returns the configured path for CA certificates.
Examples
let mut options = Options::new();
options.set_ca_certs("certs.pem");
assert_eq!(Some("certs.pem"), options.ca_certs());
sourcepub fn set_transport_thread_name<S: Into<String>>(&mut self, name: S)
pub fn set_transport_thread_name<S: Into<String>>(&mut self, name: S)
Configures the name of the default transport thread. Has no effect when using a custom transport.
Examples
let mut options = Options::new();
options.set_transport_thread_name("sentry transport");
sourcepub fn transport_thread_name(&self) -> Option<&str>
pub fn transport_thread_name(&self) -> Option<&str>
Returns the configured default transport thread name.
Examples
let mut options = Options::new();
options.set_transport_thread_name("sentry transport");
assert_eq!(Some("sentry transport"), options.transport_thread_name());
sourcepub fn set_debug(&mut self, debug: bool)
pub fn set_debug(&mut self, debug: bool)
Enables or disables debug printing mode.
Examples
let mut options = Options::new();
options.set_debug(true);
sourcepub fn debug(&self) -> bool
pub fn debug(&self) -> bool
Returns the current value of the debug flag.
Examples
let mut options = Options::new();
options.set_debug(true);
assert!(options.debug());
Sets the number of breadcrumbs being tracked and attached to events. Defaults to 100.
Examples
let mut options = Options::new();
options.set_max_breadcrumbs(10);
Gets the number of breadcrumbs being tracked and attached to events.
Examples
let mut options = Options::new();
options.set_max_breadcrumbs(10);
assert_eq!(options.max_breadcrumbs(), 10);
sourcepub fn set_logger<L: Into<Box<L>> + Logger>(&mut self, logger: L)
pub fn set_logger<L: Into<Box<L>> + Logger>(&mut self, logger: L)
Sets a callback that is used for logging purposes when
Options::debug
is true
.
Notes
Unwinding panics in logger
will be cought and abort
will be called if any occured.
Examples
let mut options = Options::new();
options.set_debug(true);
options.set_logger(|level, message| {
println!("[{}]: {}", level, message);
});
sourcepub fn set_auto_session_tracking(&mut self, val: bool)
pub fn set_auto_session_tracking(&mut self, val: bool)
Enables or disables automatic session tracking.
Automatic session tracking is enabled by default and is equivalent to
calling start_session
after startup.
There can only be one running session, and the current session will
always be closed implicitly by shutdown
, when starting a new session
with start_session
, or manually by calling end_session
.
Examples
let mut options = Options::new();
options.set_auto_session_tracking(false);
let _shutdown = options.init()?;
// code to run before starting the session
start_session();
sourcepub fn auto_session_tracking(&self) -> bool
pub fn auto_session_tracking(&self) -> bool
Returns true
if automatic session tracking is enabled.
Examples
let mut options = Options::new();
options.set_auto_session_tracking(false);
assert!(!options.auto_session_tracking());
sourcepub fn set_require_user_consent(&mut self, val: bool)
pub fn set_require_user_consent(&mut self, val: bool)
Enables or disabled user consent requirements for uploads.
This disables uploads until the user has given the consent to the SDK.
Consent itself is given with set_user_consent
and Consent::Given
or revoked with Consent::Revoked
.
Examples
let mut options = Options::new();
options.set_require_user_consent(true);
sourcepub fn require_user_consent(&self) -> bool
pub fn require_user_consent(&self) -> bool
Returns true
if user consent is required.
Examples
let mut options = Options::new();
options.set_require_user_consent(true);
assert!(options.require_user_consent());
sourcepub fn set_symbolize_stacktraces(&mut self, val: bool)
pub fn set_symbolize_stacktraces(&mut self, val: bool)
Enables or disables on-device symbolication of stack traces.
This feature can have a performance impact, and is enabled by default on Android. It is usually only needed when it is not possible to provide debug information files for system libraries which are needed for serverside symbolication.
Examples
let mut options = Options::new();
options.set_symbolize_stacktraces(true);
sourcepub fn symbolize_stacktraces(&self) -> bool
pub fn symbolize_stacktraces(&self) -> bool
Returns true
if on-device symbolication of stack traces is enabled.
Examples
let mut options = Options::new();
options.set_symbolize_stacktraces(true);
assert!(options.symbolize_stacktraces());
sourcepub fn add_attachment<P: Into<PathBuf>>(&mut self, path: P)
pub fn add_attachment<P: Into<PathBuf>>(&mut self, path: P)
Adds a new attachment to be sent along.
Examples
let mut options = Options::new();
options.add_attachment("server.log");
sourcepub fn set_handler_path<P: Into<PathBuf>>(&mut self, path: P)
pub fn set_handler_path<P: Into<PathBuf>>(&mut self, path: P)
Sets the path to the crashpad handler if the crashpad backend is used.
The path defaults to the crashpad_handler
/crashpad_handler.exe
executable, depending on platform, which is expected to be present in
the same directory as the app executable.
It is recommended that library users set an explicit handler path, depending on the directory/executable structure of their app.
Examples
let mut options = Options::new();
options.set_handler_path("crashpad_handler");
sourcepub fn set_database_path<P: Into<PathBuf>>(&mut self, path: P)
pub fn set_database_path<P: Into<PathBuf>>(&mut self, path: P)
Sets the path to the Sentry database directory.
Sentry will use this path to persist user consent, sessions, and other artifacts in case of a crash. This will also be used by the crashpad backend if it is configured.
The path defaults to .sentry-native
in the current working directory,
will be created if it does not exist, and will be resolved to an
absolute path inside of Options::init
.
It is recommended that library users set an explicit absolute path, depending on their apps runtime directory.
The directory should not be shared with other application data/configuration, as Sentry will enumerate and possibly delete files in that directory.
Examples
let mut options = Options::new();
options.set_database_path(".sentry-native");
sourcepub fn set_system_crash_reporter(&mut self, enabled: bool)
pub fn set_system_crash_reporter(&mut self, enabled: bool)
Enables forwarding to the system crash reporter. Disabled by default.
This setting only has an effect when using Crashpad on macOS. If enabled, Crashpad forwards crashes to the macOS system crash reporter. Depending on the crash, this may impact the crash time. Even if enabled, Crashpad may choose not to forward certain crashes.
Examples
let mut options = Options::new();
options.set_system_crash_reporter(true);
sourcepub fn init(self) -> Result<Shutdown, Error>
pub fn init(self) -> Result<Shutdown, Error>
Initializes the Sentry SDK with the specified options. Make sure to
capture the resulting Shutdown
, this makes sure to automatically
call shutdown
when it drops.
Errors
Fails with Error::Init
if Sentry couldn’t initialize - should only
occur in these situations:
- Fails to create database directory.
- Fails to lock database directory.
Examples
let _shutdown = Options::new().init()?;
Trait Implementations
impl Eq for Options
impl Send for Options
impl Sync for Options
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