Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Deprecations

- Deprecated `ClientOptions::enable_logs`. The option is now a no-op; logs are always enabled. To stop sending logs, stop calling the logging APIs or disable the log-capturing integrations (`tracing`, `log`, or `slog`) ([#1299](https://github.com/getsentry/sentry-rust/pull/1299)).
- Deprecated `ClientOptions::enable_metrics`. The option is now a no-op; metrics are always enabled. To stop sending metrics, stop calling the metrics APIs ([#1300](https://github.com/getsentry/sentry-rust/pull/1300)).

## 0.49.1

Expand Down
25 changes: 9 additions & 16 deletions sentry-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@
let logs_batcher = RwLock::new(Some(Batcher::new(envelope_sender.clone())));

#[cfg(feature = "metrics")]
let metrics_batcher = RwLock::new(
self.options
.enable_metrics
.then(|| Batcher::new(envelope_sender.clone())),
);
let metrics_batcher = RwLock::new(Some(Batcher::new(envelope_sender.clone())));

Client {
options: self.options.clone(),
Expand Down Expand Up @@ -174,16 +170,22 @@
///
/// # Panics
///
/// Panics in debug builds if the deprecated no-op field

Check warning on line 173 in sentry-core/src/client/mod.rs

View check run for this annotation

@sentry/warden / warden: docs-review

with_options docs omit new enable_metrics panic

The `# Panics` docs for `with_options` were not updated to mention the new `enable_metrics` debug assertion. Update the panic documentation to include `enable_metrics`.
/// [`enable_logs`](field@ClientOptions::enable_logs) is set to `false`.
pub fn with_options(mut options: ClientOptions) -> Client {
Comment on lines 173 to 175

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client::with_options docs omit new enable_metrics panic

The # Panics docs for with_options were not updated to mention the new enable_metrics debug_assert!, so users are only warned about the enable_logs panic condition.

Evidence
  • The with_options rustdoc (lines 173-174) says: "Panics in debug builds if the deprecated no-op field enable_logs is set to false."
  • The hunk adds debug_assert!(options.enable_metrics) inside with_options at lines 184-188.
  • The #[expect(deprecated)] block comment was updated from singular "field" to plural "fields" to cover both assertions, confirming the docs were not kept in sync.
Also found at 1 additional location
  • sentry-core/src/clientoptions.rs:256

Identified by Warden · docs-review · D8M-MS5

#[expect(deprecated, reason = "need to check deprecated field")]
#[expect(deprecated, reason = "need to check deprecated fields")]
{
debug_assert!(
options.enable_logs,
"invalid initialization options: the Sentry SDK no longer supports disabling logs \
via the `enable_logs` field: {options:?}"
);

debug_assert!(
options.enable_metrics,
"invalid initialization options: the Sentry SDK no longer supports disabling \
metrics via the `enable_metrics` field: {options:?}"
)
}

// Create the main hub eagerly to avoid problems with the background thread
Expand Down Expand Up @@ -216,11 +218,7 @@
let logs_batcher = RwLock::new(Some(Batcher::new(envelope_sender.clone())));

#[cfg(feature = "metrics")]
let metrics_batcher = RwLock::new(
options
.enable_metrics
.then(|| Batcher::new(envelope_sender.clone())),
);
let metrics_batcher = RwLock::new(Some(Batcher::new(envelope_sender.clone())));

let client = Client {
options,
Expand Down Expand Up @@ -601,11 +599,6 @@
/// Captures a metric and sends it to Sentry.
#[cfg(feature = "metrics")]
pub fn capture_metric<M: IntoProtocolMetric>(&self, metric: M, scope: &Scope) {
if !self.options.enable_metrics {
// Skip preparing the metric if we don't send it anyways.
return;
}

if let Some(metric) = self.prepare_metric(metric, scope) {
if let Some(batcher) = self
.metrics_batcher
Expand Down
24 changes: 19 additions & 5 deletions sentry-core/src/clientoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ pub struct ClientOptions {
/// `false`. The panic occurs at initialization-time.
#[deprecated = "this option is a deprecated no-op"]
pub enable_logs: bool,
/// Whether metric capture APIs should capture metrics.
/// Deprecated no-op.
///
/// See [`enable_metrics`](method@ClientOptions::enable_metrics) for details.
/// In debug builds, we panic if the Sentry client is initialized with this option set to
/// `false`. The panic occurs at initialization-time.
#[deprecated = "this option is a deprecated no-op"]
pub enable_metrics: bool,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_metrics builder docs copy-paste typo

The updated docs for the ClientOptions::enable_metrics builder method incorrectly say "We only capture logs" instead of "metrics". Fix the sentence to refer to metrics APIs.

Evidence
  • sentry-core/src/clientoptions.rs:705-706 in the enable_metrics builder docs read: "We only capture logs if you explicitly call the relevant APIs."
  • The preceding enable_logs builder at clientoptions.rs:690 correctly says "We only capture logs if you explicitly call the relevant APIs or if you enable an integration that captures logs."
  • The enable_metrics builder docs immediately above the typo correctly say "To stop sending metrics, simply remove any calls to our metrics APIs."
  • The enable_metrics method is public and deprecated in this change set, so its rustdoc is user-facing.
Also found at 3 additional locations
  • sentry-core/src/client/mod.rs:120
  • sentry-core/src/clientoptions.rs:707
  • sentry-core/src/clientoptions.rs:845-848

Identified by Warden · docs-review · CN8-BFY

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix attempt detected (commit 469f7a8)

The commit directly updates the enable_metrics documentation but leaves the sentence incorrectly saying that only logs are captured instead of metrics.

The original issue appears unresolved. Please review and try again.

Evaluated by Warden

/// Callback that is executed for each [`Metric`] before sending.
///
Expand Down Expand Up @@ -698,12 +700,19 @@ impl ClientOptions {
}
}

/// Enables or disables [metric capture APIs](field@ClientOptions::enable_metrics).
/// This function is effectively a no-op, as it sets the deprecated, no-op field
/// [`enable_metrics`](field@ClientOptions::enable_metrics).
///
/// To stop sending metrics, simply remove any calls to our metrics APIs. We only capture
/// logs if you explicitly call the relevant APIs.
///
/// The `metrics` feature is required to capture metrics. Defaults to `true`.
/// In debug builds, we panic if the Sentry client is initialized with this option set to
/// `false`. The panic occurs at initialization-time.
#[deprecated = "this function sets a no-op option"]
#[inline]
pub fn enable_metrics(self, enable_metrics: bool) -> Self {
Self {
#[expect(deprecated, reason = "need to set deprecated field")]
enable_metrics,
..self
}
Expand Down Expand Up @@ -832,7 +841,11 @@ impl fmt::Debug for ClientOptions {
&self.enable_logs,
)
.field("before_send_log", &before_send_log)
.field("enable_metrics", &self.enable_metrics)
.field(
"enable_metrics",
#[expect(deprecated, reason = "still need to debug-log this field")]
&self.enable_metrics,
)
.field("before_send_metric", &before_send_metric)
.field("org_id", &self.org_id)
.field("strict_trace_continuation", &self.strict_trace_continuation)
Expand Down Expand Up @@ -874,6 +887,7 @@ impl Default for ClientOptions {
#[expect(deprecated, reason = "still need to set deprecated fields")]
enable_logs: true,
before_send_log: None,
#[expect(deprecated, reason = "still need to set deprecated fields")]
enable_metrics: true,
before_send_metric: None,
}
Expand Down
62 changes: 0 additions & 62 deletions sentry-core/tests/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,6 @@ use sentry_core::{metrics, test};
use sentry_core::{ClientOptions, TransactionContext};
use sentry_types::protocol::v7::{Envelope, LogAttribute, Metric, User};

/// Test that metrics are sent when metrics are enabled.
#[test]
fn sent_when_enabled() {
let options = ClientOptions::new().enable_metrics(true);

let mut envelopes =
test::with_captured_envelopes_options(|| metrics::counter("test", 1).capture(), options);

assert_eq!(envelopes.len(), 1, "expected exactly one envelope");

let envelope = envelopes.pop().unwrap();

let mut items = envelope.into_items();
let Some(item) = items.next() else {
panic!("Expected at least one item");
};

assert!(items.next().is_none(), "Expected only one item");

let EnvelopeItem::ItemContainer(ItemContainer::Metrics(mut metrics)) = item else {
panic!("Envelope item has unexpected structure");
};

assert_eq!(metrics.len(), 1, "Expected exactly one metric");

let metric = metrics.pop().unwrap();
assert!(matches!(metric, Metric {
r#type: MetricType::Counter,
name,
value: 1.0,
..
} if name == "test"));
}

/// Test that metrics are sent by default.
#[test]
fn metrics_enabled_by_default() {
let options = ClientOptions::default();

let envelopes =
test::with_captured_envelopes_options(|| metrics::counter("test", 1).capture(), options);
assert_eq!(
envelopes.len(),
1,
"expected exactly one envelope when metrics are enabled by default"
)
}

/// Test that metrics are disabled (not sent) when disabled in the
/// [`ClientOptions`].
#[test]
fn metrics_disabled_when_configured() {
let options = ClientOptions::new().enable_metrics(false);

let envelopes =
test::with_captured_envelopes_options(|| metrics::counter("test", 1).capture(), options);
assert!(
envelopes.is_empty(),
"no envelopes should be captured when metrics disabled"
)
}

/// Test that no metrics are captured by a no-op call with
/// metrics enabled
#[test]
Expand Down
Loading