Skip to content

Commit 876a82f

Browse files
ref(utils): Remove unused to_timestamp helper and epoch constant (#8147)
### Description Removes `to_timestamp()` and the module-level `epoch` constant from `sentry_sdk/utils.py`. Nothing uses either of them. #4899 (removing the old metrics code) deleted the last three callers of `to_timestamp`, all in `sentry_sdk/metrics.py`, plus its import there. `epoch` was only ever used inside `to_timestamp`. **Evidence** - `grep -rnw to_timestamp sentry_sdk tests scripts` only matches the definition. - `grep -rnw epoch sentry_sdk tests` only matches the definition and its use in `to_timestamp`. The other match is the `(?P<epoch>...)` regex group in the version parser, which isn't related. - `git log -S "to_timestamp(" -- sentry_sdk tests` shows #4899 as the last change to touch a call site. - No open PR diff in this repo mentions `to_timestamp` or `epoch`. **Why it's safe** - `sentry_sdk.utils` is an internal module. Neither name is re-exported from `sentry_sdk` or listed in `docs/`, and neither appears in `CHANGELOG.md` or `MIGRATION_GUIDE.md`. - The helper had a latent bug: it subtracted from a naive `datetime(1970, 1, 1)`, so passing it a timezone-aware datetime (the SDK uses aware UTC datetimes everywhere) raised `TypeError`. Leaving it around invites someone to reuse it by mistake. - `datetime` is still imported and used elsewhere in the module. - No runtime behavior changes. **Checks** - `uv run ruff check sentry_sdk tests` and `ruff format --check` pass. - `uv run --group typing mypy sentry_sdk` passes with no issues. - `TESTPATH="tests/test_utils.py tests/test_basics.py tests/test_client.py" uv run tox -e py3.14-common`: 587 passed, 3 skipped. #### Issues None. Found by a dead-code sweep. <!-- junior-request-attribution:start --> via [automation `sched_65eed06cc199036c2b13411096f412d4`](https://junior-prod.sentry.dev/automations/sched_65eed06cc199036c2b13411096f412d4) · Run ID `sched_65eed06cc199036c2b13411096f412d4:1793267961442`. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent-dispatch%3Adispatch_de360d426db36e075f636e5b35173292 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/agent-dispatch%3Adispatch_de360d426db36e075f636e5b35173292) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent-dispatch%3Adispatch_de360d426db36e075f636e5b35173292/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
1 parent c44f1f2 commit 876a82f

1 file changed

Lines changed: 0 additions & 6 deletions

File tree

‎sentry_sdk/utils.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979
R = TypeVar("R")
8080

8181

82-
epoch = datetime(1970, 1, 1)
83-
8482
# The logger is created here but initialized in the debug support module
8583
logger = logging.getLogger("sentry_sdk.errors")
8684

@@ -248,10 +246,6 @@ def capture_internal_exception(exc_info: "ExcInfo") -> None:
248246
logger.error("Internal error in sentry_sdk", exc_info=exc_info)
249247

250248

251-
def to_timestamp(value: "datetime") -> float:
252-
return (value - epoch).total_seconds()
253-
254-
255249
def format_timestamp(value: "datetime") -> str:
256250
"""Formats a timestamp in RFC 3339 format.
257251

0 commit comments

Comments
 (0)