Skip to content

Conversation

@afurche
Copy link
Contributor

@afurche afurche commented Nov 12, 2025

Callback scheduling was based on datetime.now(), which internally is based on time.time(). As it uses real system clock, it is susceptible to time changes (e.g. end of daylight saving time), which introduces scheduling issues on such occurrences.

This PR changes the scheduling mechanism, to use time.monotonic() instead, which is based on a monotonic system clock, and is not affected by time changes, which ensures scheduling stays stable through time changes.

@afurche afurche requested review from DtDamianGrzes, Copilot and dlopes7 and removed request for DtDamianGrzes November 12, 2025 14:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes callback scheduling issues that occur during system time changes (such as daylight saving time transitions) by switching from time.time() to time.monotonic() for internal scheduling. The monotonic clock is unaffected by system time adjustments, ensuring stable and reliable callback execution timing.

Key Changes:

  • Replaced datetime.now() and timedelta with time.monotonic() and numeric seconds for scheduling
  • Updated internal callback intervals to use raw seconds instead of timedelta objects
  • Modified type hints to reflect the change from datetime to float timestamps

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
dynatrace_extension/sdk/extension.py Converted interval constants from timedelta to seconds, updated scheduler to use time.monotonic(), changed internal callback timestamps from datetime to float
dynatrace_extension/sdk/callback.py Added start_timestamp_monotonic using time.monotonic() and updated get_next_execution_timestamp() to use monotonic time
tests/sdk/test_extension.py Updated test to use time.monotonic() instead of datetime.now() for _next_heartbeat
dynatrace_extension/about.py Bumped version from 1.7.2 to 1.7.3

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@afurche afurche force-pushed the bugfix/fix-scheduling-issues-on-local-time-change branch from d4ffd09 to 5baba65 Compare November 12, 2025 16:20
@dlopes7 dlopes7 merged commit 30cf9b5 into main Nov 12, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants