Skip to content

Commit c635e3e

Browse files
ref(metrics): Deprecate sentry_sdk.metrics (getsentry#3512)
Raise a `DeprecationWarning` on import of the `sentry_sdk.metrics` module. Closes getsentry#3502
1 parent 22f62b0 commit c635e3e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sentry_sdk/metrics.py

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import threading
77
import time
8+
import warnings
89
import zlib
910
from abc import ABC, abstractmethod
1011
from contextlib import contextmanager
@@ -54,6 +55,14 @@
5455
from sentry_sdk._types import MetricValue
5556

5657

58+
warnings.warn(
59+
"The sentry_sdk.metrics module is deprecated and will be removed in the next major release. "
60+
"Sentry will reject all metrics sent after October 7, 2024. "
61+
"Learn more: https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Upcoming-API-Changes-to-Metrics",
62+
DeprecationWarning,
63+
stacklevel=2,
64+
)
65+
5766
_in_metrics = ContextVar("in_metrics", default=False)
5867
_set = set # set is shadowed below
5968

sentry_sdk/tracing.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1298,4 +1298,8 @@ async def my_async_function():
12981298
has_tracing_enabled,
12991299
maybe_create_breadcrumbs_from_span,
13001300
)
1301-
from sentry_sdk.metrics import LocalAggregator
1301+
1302+
with warnings.catch_warnings():
1303+
# The code in this file which uses `LocalAggregator` is only called from the deprecated `metrics` module.
1304+
warnings.simplefilter("ignore", DeprecationWarning)
1305+
from sentry_sdk.metrics import LocalAggregator

0 commit comments

Comments
 (0)