Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Make the fields of ClientOptions private #266

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<S: 'static> Middleware<S> for SentryMiddleware {
if cached_data.is_none() && req.is_valid() {
let with_pii = client
.as_ref()
.map_or(false, |x| x.options().send_default_pii);
.map_or(false, |x| x.options().send_default_pii());
*cached_data = Some(extract_request(&req.get(), with_pii));
}

Expand Down
2 changes: 1 addition & 1 deletion sentry-anyhow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Integration for AnyhowIntegration {
}

fn setup(&self, cfg: &mut ClientOptions) {
cfg.in_app_exclude.push("anyhow::");
cfg.add_in_app_exclude(&["anyhow::"]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion sentry-backtrace/src/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Integration for AttachStacktraceIntegration {
mut event: Event<'static>,
options: &ClientOptions,
) -> Option<Event<'static>> {
if options.attach_stacktrace && event.exception.is_empty() {
if options.attach_stacktrace() && event.exception.is_empty() {
let thread = current_thread(true);
if thread.stacktrace.is_some() {
event.threads.values.push(thread);
Expand Down
8 changes: 4 additions & 4 deletions sentry-backtrace/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use crate::{Frame, Stacktrace};
/// `ClientOptions`.
pub fn process_event_stacktrace(stacktrace: &mut Stacktrace, options: &ClientOptions) {
// automatically trim backtraces
if options.trim_backtraces {
if options.trim_backtraces() {
trim_stacktrace(stacktrace, |frame, _| {
if let Some(ref func) = frame.function {
options.extra_border_frames.contains(&func.as_str())
options.extra_border_frames().contains(&func.as_str())
} else {
false
}
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn process_event_stacktrace(stacktrace: &mut Stacktrace, options: &ClientOpt
None => {}
}

for m in &options.in_app_exclude {
for m in options.in_app_exclude() {
if function_starts_with(func_name, m) {
frame.in_app = Some(false);
break;
Expand All @@ -60,7 +60,7 @@ pub fn process_event_stacktrace(stacktrace: &mut Stacktrace, options: &ClientOpt
continue;
}

for m in &options.in_app_include {
for m in options.in_app_include() {
if function_starts_with(func_name, m) {
frame.in_app = Some(true);
any_in_app = true;
Expand Down
4 changes: 2 additions & 2 deletions sentry-contexts/src/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ impl Integration for ContextIntegration {
}

fn setup(&self, options: &mut ClientOptions) {
if options.server_name.is_none() {
options.server_name = server_name().map(Cow::Owned);
if options.server_name().is_none() {
options.set_server_name(server_name().map(Cow::Owned));
}
}

Expand Down
27 changes: 15 additions & 12 deletions sentry-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ impl Client {
/// If the DSN on the options is set to `None` the client will be entirely
/// disabled.
pub fn with_options(mut options: ClientOptions) -> Client {
#![allow(deprecated)]

// Create the main hub eagerly to avoid problems with the background thread
// See https://github.com/getsentry/sentry-rust/issues/237
Hub::with(|_| {});

let create_transport = || {
options.dsn.as_ref()?;
options.dsn()?;
let factory = options.transport.as_ref()?;
Some(factory.create_transport(&options))
};
Expand Down Expand Up @@ -142,6 +144,8 @@ impl Client {
mut event: Event<'static>,
scope: Option<&Scope>,
) -> Option<Event<'static>> {
#![allow(deprecated)]

if let Some(scope) = scope {
scope.update_session_from_event(&event);
}
Expand Down Expand Up @@ -180,13 +184,13 @@ impl Client {
}

if event.release.is_none() {
event.release = self.options.release.clone();
event.release = self.options.release();
}
if event.environment.is_none() {
event.environment = self.options.environment.clone();
event.environment = self.options.environment();
}
if event.server_name.is_none() {
event.server_name = self.options.server_name.clone();
event.server_name = self.options.server_name();
}
if &event.platform == "other" {
event.platform = "native".into();
Expand All @@ -211,7 +215,7 @@ impl Client {

/// Returns the DSN that constructed this client.
pub fn dsn(&self) -> Option<&Dsn> {
self.options.dsn.as_ref()
self.options.dsn()
}

/// Quick check to see if the client is enabled.
Expand All @@ -230,15 +234,14 @@ impl Client {
/// let transport = sentry::test::TestTransport::new();
/// let client = sentry::Client::from((
/// dsn,
/// sentry::ClientOptions {
/// transport: Some(Arc::new(transport)),
/// ..Default::default()
/// },
/// sentry::ClientOptions::configure(|o| {
/// o.set_transport(Arc::new(transport))
/// }),
/// ));
/// assert!(client.is_enabled());
/// ```
pub fn is_enabled(&self) -> bool {
self.options.dsn.is_some() && self.transport.read().unwrap().is_some()
self.options.dsn().is_some() && self.transport.read().unwrap().is_some()
}

/// Captures an event and sends it to sentry.
Expand Down Expand Up @@ -282,15 +285,15 @@ impl Client {
let transport_opt = self.transport.write().unwrap().take();
if let Some(transport) = transport_opt {
sentry_debug!("client close; request transport to shut down");
transport.shutdown(timeout.unwrap_or(self.options.shutdown_timeout))
transport.shutdown(timeout.unwrap_or_else(|| self.options.shutdown_timeout()))
} else {
sentry_debug!("client close; no transport to shut down");
true
}
}

fn sample_should_send(&self) -> bool {
let rate = self.options.sample_rate;
let rate = self.options.sample_rate();
if rate >= 1.0 {
true
} else {
Expand Down
Loading