Skip to content

Commit

Permalink
Replace deprecated datetime functions (#2502)
Browse files Browse the repository at this point in the history
`datetime.utcfromtimestamp` and `datetime.utcnow` are deprecated in Python 3.12.
  • Loading branch information
sentrivana committed Nov 13, 2023
1 parent 338acda commit 9cae5f2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sentry_sdk/tracing.py
Expand Up @@ -6,7 +6,7 @@
import sentry_sdk
from sentry_sdk.consts import INSTRUMENTER
from sentry_sdk.utils import is_valid_sample_rate, logger, nanosecond_time
from sentry_sdk._compat import datetime_utcnow, PY2
from sentry_sdk._compat import datetime_utcnow, utc_from_timestamp, PY2
from sentry_sdk.consts import SPANDATA
from sentry_sdk._types import TYPE_CHECKING

Expand Down Expand Up @@ -147,9 +147,9 @@ def __init__(
self._data = {} # type: Dict[str, Any]
self._containing_transaction = containing_transaction
if start_timestamp is None:
start_timestamp = datetime.utcnow()
start_timestamp = datetime_utcnow()
elif isinstance(start_timestamp, float):
start_timestamp = datetime.utcfromtimestamp(start_timestamp)
start_timestamp = utc_from_timestamp(start_timestamp)
self.start_timestamp = start_timestamp
try:
# profiling depends on this value and requires that
Expand Down Expand Up @@ -468,7 +468,7 @@ def finish(self, hub=None, end_timestamp=None):
try:
if end_timestamp:
if isinstance(end_timestamp, float):
end_timestamp = datetime.utcfromtimestamp(end_timestamp)
end_timestamp = utc_from_timestamp(end_timestamp)
self.timestamp = end_timestamp
else:
elapsed = nanosecond_time() - self._start_timestamp_monotonic_ns
Expand Down

0 comments on commit 9cae5f2

Please sign in to comment.