Skip to content

Commit 24b8f15

Browse files
alexander-alderman-webbshellmayr
authored andcommitted
chore(metrics): Rename _metrics to metrics (#5035)
Moves metrics code from `_metrics.py` to `metrics.py`, and updates metrics tests to account for the namespace change.
1 parent b43ad35 commit 24b8f15

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

sentry_sdk/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from sentry_sdk import profiler
2+
from sentry_sdk import metrics
23
from sentry_sdk.scope import Scope
34
from sentry_sdk.transport import Transport, HttpTransport
45
from sentry_sdk.client import Client
@@ -48,6 +49,7 @@
4849
"trace",
4950
"monitor",
5051
"logger",
52+
"metrics",
5153
"profiler",
5254
"start_session",
5355
"end_session",
File renamed without changes.

tests/test_metrics.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
import sentry_sdk
7-
from sentry_sdk import _metrics
87
from sentry_sdk import get_client
98
from sentry_sdk.envelope import Envelope
109
from sentry_sdk.types import Metric
@@ -39,9 +38,9 @@ def test_metrics_disabled_by_default(sentry_init, capture_envelopes):
3938

4039
envelopes = capture_envelopes()
4140

42-
_metrics.count("test.counter", 1)
43-
_metrics.gauge("test.gauge", 42)
44-
_metrics.distribution("test.distribution", 200)
41+
sentry_sdk.metrics.count("test.counter", 1)
42+
sentry_sdk.metrics.gauge("test.gauge", 42)
43+
sentry_sdk.metrics.distribution("test.distribution", 200)
4544

4645
assert len(envelopes) == 0
4746

@@ -50,9 +49,9 @@ def test_metrics_basics(sentry_init, capture_envelopes):
5049
sentry_init(_experiments={"enable_metrics": True})
5150
envelopes = capture_envelopes()
5251

53-
_metrics.count("test.counter", 1)
54-
_metrics.gauge("test.gauge", 42, unit="millisecond")
55-
_metrics.distribution("test.distribution", 200, unit="second")
52+
sentry_sdk.metrics.count("test.counter", 1)
53+
sentry_sdk.metrics.gauge("test.gauge", 42, unit="millisecond")
54+
sentry_sdk.metrics.distribution("test.distribution", 200, unit="second")
5655

5756
get_client().flush()
5857
metrics = envelopes_to_metrics(envelopes)
@@ -81,7 +80,7 @@ def test_metrics_experimental_option(sentry_init, capture_envelopes):
8180
sentry_init(_experiments={"enable_metrics": True})
8281
envelopes = capture_envelopes()
8382

84-
_metrics.count("test.counter", 5)
83+
sentry_sdk.metrics.count("test.counter", 5)
8584

8685
get_client().flush()
8786

@@ -99,7 +98,7 @@ def test_metrics_with_attributes(sentry_init, capture_envelopes):
9998
)
10099
envelopes = capture_envelopes()
101100

102-
_metrics.count(
101+
sentry_sdk.metrics.count(
103102
"test.counter", 1, attributes={"endpoint": "/api/test", "status": "success"}
104103
)
105104

@@ -121,7 +120,7 @@ def test_metrics_with_user(sentry_init, capture_envelopes):
121120
sentry_sdk.set_user(
122121
{"id": "user-123", "email": "test@example.com", "username": "testuser"}
123122
)
124-
_metrics.count("test.user.counter", 1)
123+
sentry_sdk.metrics.count("test.user.counter", 1)
125124

126125
get_client().flush()
127126

@@ -138,7 +137,7 @@ def test_metrics_with_span(sentry_init, capture_envelopes):
138137
envelopes = capture_envelopes()
139138

140139
with sentry_sdk.start_transaction(op="test", name="test-span"):
141-
_metrics.count("test.span.counter", 1)
140+
sentry_sdk.metrics.count("test.span.counter", 1)
142141

143142
get_client().flush()
144143

@@ -154,7 +153,7 @@ def test_metrics_tracing_without_performance(sentry_init, capture_envelopes):
154153
sentry_init(_experiments={"enable_metrics": True})
155154
envelopes = capture_envelopes()
156155

157-
_metrics.count("test.span.counter", 1)
156+
sentry_sdk.metrics.count("test.span.counter", 1)
158157

159158
get_client().flush()
160159

@@ -197,8 +196,8 @@ def _before_metric(record, hint):
197196
)
198197
envelopes = capture_envelopes()
199198

200-
_metrics.count("test.skip", 1)
201-
_metrics.count("test.keep", 1)
199+
sentry_sdk.metrics.count("test.skip", 1)
200+
sentry_sdk.metrics.count("test.keep", 1)
202201

203202
get_client().flush()
204203

0 commit comments

Comments
 (0)