Skip to content

Commit 2397b15

Browse files
chore: Remove enable_metrics option (#5046)
Remove the `enable_metrics` option. Users can capture metrics with `sentry_sdk.metrics` functions without further opt-in. Closes #5048
1 parent 2d49b74 commit 2397b15

File tree

3 files changed

+9
-37
lines changed

3 files changed

+9
-37
lines changed

sentry_sdk/client.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import sentry_sdk
1212
from sentry_sdk._compat import PY37, check_uwsgi_thread_support
13+
from sentry_sdk._metrics_batcher import MetricsBatcher
1314
from sentry_sdk.utils import (
1415
AnnotatedValue,
1516
ContextVar,
@@ -26,7 +27,6 @@
2627
get_before_send_log,
2728
get_before_send_metric,
2829
has_logs_enabled,
29-
has_metrics_enabled,
3030
)
3131
from sentry_sdk.serializer import serialize
3232
from sentry_sdk.tracing import trace
@@ -374,12 +374,7 @@ def _capture_envelope(envelope):
374374

375375
self.log_batcher = LogBatcher(capture_func=_capture_envelope)
376376

377-
self.metrics_batcher = None
378-
379-
if has_metrics_enabled(self.options):
380-
from sentry_sdk._metrics_batcher import MetricsBatcher
381-
382-
self.metrics_batcher = MetricsBatcher(capture_func=_capture_envelope)
377+
self.metrics_batcher = MetricsBatcher(capture_func=_capture_envelope)
383378

384379
max_request_body_size = ("always", "never", "small", "medium")
385380
if self.options["max_request_body_size"] not in max_request_body_size:
@@ -979,7 +974,7 @@ def _capture_log(self, log):
979974

980975
def _capture_metric(self, metric):
981976
# type: (Optional[Metric]) -> None
982-
if not has_metrics_enabled(self.options) or metric is None:
977+
if metric is None:
983978
return
984979

985980
isolation_scope = sentry_sdk.get_isolation_scope()

sentry_sdk/utils.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,14 +2047,6 @@ def get_before_send_log(options):
20472047
)
20482048

20492049

2050-
def has_metrics_enabled(options):
2051-
# type: (Optional[dict[str, Any]]) -> bool
2052-
if options is None:
2053-
return False
2054-
2055-
return bool(options["_experiments"].get("enable_metrics", False))
2056-
2057-
20582050
def get_before_send_metric(options):
20592051
# type: (Optional[dict[str, Any]]) -> Optional[Callable[[Metric, Hint], Optional[Metric]]]
20602052
if options is None:

tests/test_metrics.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,8 @@ def envelopes_to_metrics(envelopes):
3333
return res
3434

3535

36-
def test_metrics_disabled_by_default(sentry_init, capture_envelopes):
37-
sentry_init()
38-
39-
envelopes = capture_envelopes()
40-
41-
sentry_sdk.metrics.count("test.counter", 1)
42-
sentry_sdk.metrics.gauge("test.gauge", 42)
43-
sentry_sdk.metrics.distribution("test.distribution", 200)
44-
45-
assert len(envelopes) == 0
46-
47-
4836
def test_metrics_basics(sentry_init, capture_envelopes):
49-
sentry_init(_experiments={"enable_metrics": True})
37+
sentry_init()
5038
envelopes = capture_envelopes()
5139

5240
sentry_sdk.metrics.count("test.counter", 1)
@@ -77,7 +65,7 @@ def test_metrics_basics(sentry_init, capture_envelopes):
7765

7866

7967
def test_metrics_experimental_option(sentry_init, capture_envelopes):
80-
sentry_init(_experiments={"enable_metrics": True})
68+
sentry_init()
8169
envelopes = capture_envelopes()
8270

8371
sentry_sdk.metrics.count("test.counter", 5)
@@ -93,9 +81,7 @@ def test_metrics_experimental_option(sentry_init, capture_envelopes):
9381

9482

9583
def test_metrics_with_attributes(sentry_init, capture_envelopes):
96-
sentry_init(
97-
_experiments={"enable_metrics": True}, release="1.0.0", environment="test"
98-
)
84+
sentry_init(release="1.0.0", environment="test")
9985
envelopes = capture_envelopes()
10086

10187
sentry_sdk.metrics.count(
@@ -114,7 +100,7 @@ def test_metrics_with_attributes(sentry_init, capture_envelopes):
114100

115101

116102
def test_metrics_with_user(sentry_init, capture_envelopes):
117-
sentry_init(_experiments={"enable_metrics": True})
103+
sentry_init()
118104
envelopes = capture_envelopes()
119105

120106
sentry_sdk.set_user(
@@ -133,7 +119,7 @@ def test_metrics_with_user(sentry_init, capture_envelopes):
133119

134120

135121
def test_metrics_with_span(sentry_init, capture_envelopes):
136-
sentry_init(_experiments={"enable_metrics": True}, traces_sample_rate=1.0)
122+
sentry_init(traces_sample_rate=1.0)
137123
envelopes = capture_envelopes()
138124

139125
with sentry_sdk.start_transaction(op="test", name="test-span"):
@@ -150,7 +136,7 @@ def test_metrics_with_span(sentry_init, capture_envelopes):
150136

151137

152138
def test_metrics_tracing_without_performance(sentry_init, capture_envelopes):
153-
sentry_init(_experiments={"enable_metrics": True})
139+
sentry_init()
154140
envelopes = capture_envelopes()
155141

156142
sentry_sdk.metrics.count("test.span.counter", 1)
@@ -190,7 +176,6 @@ def _before_metric(record, hint):
190176

191177
sentry_init(
192178
_experiments={
193-
"enable_metrics": True,
194179
"before_send_metric": _before_metric,
195180
},
196181
)

0 commit comments

Comments
 (0)