Skip to content

Commit 9cae5f2

Browse files
authored
Replace deprecated datetime functions (#2502)
`datetime.utcfromtimestamp` and `datetime.utcnow` are deprecated in Python 3.12.
1 parent 338acda commit 9cae5f2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sentry_sdk/tracing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sentry_sdk
77
from sentry_sdk.consts import INSTRUMENTER
88
from sentry_sdk.utils import is_valid_sample_rate, logger, nanosecond_time
9-
from sentry_sdk._compat import datetime_utcnow, PY2
9+
from sentry_sdk._compat import datetime_utcnow, utc_from_timestamp, PY2
1010
from sentry_sdk.consts import SPANDATA
1111
from sentry_sdk._types import TYPE_CHECKING
1212

@@ -147,9 +147,9 @@ def __init__(
147147
self._data = {} # type: Dict[str, Any]
148148
self._containing_transaction = containing_transaction
149149
if start_timestamp is None:
150-
start_timestamp = datetime.utcnow()
150+
start_timestamp = datetime_utcnow()
151151
elif isinstance(start_timestamp, float):
152-
start_timestamp = datetime.utcfromtimestamp(start_timestamp)
152+
start_timestamp = utc_from_timestamp(start_timestamp)
153153
self.start_timestamp = start_timestamp
154154
try:
155155
# profiling depends on this value and requires that
@@ -468,7 +468,7 @@ def finish(self, hub=None, end_timestamp=None):
468468
try:
469469
if end_timestamp:
470470
if isinstance(end_timestamp, float):
471-
end_timestamp = datetime.utcfromtimestamp(end_timestamp)
471+
end_timestamp = utc_from_timestamp(end_timestamp)
472472
self.timestamp = end_timestamp
473473
else:
474474
elapsed = nanosecond_time() - self._start_timestamp_monotonic_ns

0 commit comments

Comments
 (0)