Introduce Clock.call_when_running(...) to include logcontext by default#18944
Merged
MadLittleMods merged 12 commits intodevelopfrom Sep 22, 2025
Merged
Introduce Clock.call_when_running(...) to include logcontext by default#18944MadLittleMods merged 12 commits intodevelopfrom
Clock.call_when_running(...) to include logcontext by default#18944MadLittleMods merged 12 commits intodevelopfrom
Conversation
MadLittleMods
commented
Sep 19, 2025
| @@ -0,0 +1 @@ | |||
| Introduce `Clock.call_when_running(...)` to wrap startup code in a logcontext, ensuring we can identify which server generated the logs. | |||
Contributor
Author
There was a problem hiding this comment.
This PR can be reviewed commit-by-commit. There are lots of changes because I split out JSON and Clock utilities to avoid circular imports.
MadLittleMods
commented
Sep 19, 2025
| return None | ||
|
|
||
|
|
||
| def check_call_when_running(ctx: MethodSigContext) -> CallableType: |
Contributor
Author
There was a problem hiding this comment.
This lint pattern is coming from #18828 where we're also going to lint call_later and looping_call in the future.
MadLittleMods
commented
Sep 19, 2025
| if not ignore_errs: | ||
| raise | ||
|
|
||
| def call_when_running( |
Contributor
Author
There was a problem hiding this comment.
The new function is here Clock.call_when_running
We're wrapping reactor.callWhenRunning so there is always a logcontext active and therefore know which server generated the logs
MadLittleMods
commented
Sep 19, 2025
| d.addErrback(log_failure, "Looping call died", consumeErrors=False) | ||
| return call | ||
|
|
||
| def call_later( |
Contributor
Author
There was a problem hiding this comment.
The other functions like looping_call and call_later are getting their own logcontext wrappers in #18944
Merged
3 tasks
4 tasks
reivilibre
approved these changes
Sep 22, 2025
Contributor
Author
|
Thanks for the review @reivilibre 🐩 |
MadLittleMods
added a commit
that referenced
this pull request
Sep 22, 2025
…ooping_call_now`, `call_later`) (#18907) Part of #18905 Lints for ensuring we use `Clock.call_later` instead of `reactor.callLater`, etc are coming in #18944 ### Testing strategy 1. Configure Synapse to log at the `DEBUG` level 1. Start Synapse: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Wait 10 seconds for the [database profiling loop](https://github.com/element-hq/synapse/blob/9cc400177822805e2a08d4d934daad6f3bc2a4df/synapse/storage/database.py#L711) to execute 1. Notice the logcontext being used for the `Total database time` log line Before (`sentinel`): ``` 2025-09-10 16:36:58,651 - synapse.storage.TIME - 707 - DEBUG - sentinel - Total database time: 0.646% {room_forgetter_stream_pos(2): 0.131%, reap_monthly_active_users(1): 0.083%, get_device_change_last_converted_pos(1): 0.078%} ``` After (`looping_call`): ``` 2025-09-10 16:36:58,651 - synapse.storage.TIME - 707 - DEBUG - looping_call - Total database time: 0.646% {room_forgetter_stream_pos(2): 0.131%, reap_monthly_active_users(1): 0.083%, get_device_change_last_converted_pos(1): 0.078%} ```
itsoyou
pushed a commit
to famedly/synapse
that referenced
this pull request
Oct 13, 2025
…ooping_call_now`, `call_later`) (#18907) Part of element-hq/synapse#18905 Lints for ensuring we use `Clock.call_later` instead of `reactor.callLater`, etc are coming in element-hq/synapse#18944 ### Testing strategy 1. Configure Synapse to log at the `DEBUG` level 1. Start Synapse: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Wait 10 seconds for the [database profiling loop](https://github.com/element-hq/synapse/blob/9cc400177822805e2a08d4d934daad6f3bc2a4df/synapse/storage/database.py#L711) to execute 1. Notice the logcontext being used for the `Total database time` log line Before (`sentinel`): ``` 2025-09-10 16:36:58,651 - synapse.storage.TIME - 707 - DEBUG - sentinel - Total database time: 0.646% {room_forgetter_stream_pos(2): 0.131%, reap_monthly_active_users(1): 0.083%, get_device_change_last_converted_pos(1): 0.078%} ``` After (`looping_call`): ``` 2025-09-10 16:36:58,651 - synapse.storage.TIME - 707 - DEBUG - looping_call - Total database time: 0.646% {room_forgetter_stream_pos(2): 0.131%, reap_monthly_active_users(1): 0.083%, get_device_change_last_converted_pos(1): 0.078%} ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR can be reviewed commit-by-commit.
Introduce
Clock.call_when_running(...)to wrap startup code in a logcontext, ensuring we can identify which server generated the logs.Background:
synapse/docs/log_contexts.md
Lines 71 to 81 in 9cc4001
Also adds a lint to prefer
Clock.call_when_running(...)overreactor.callWhenRunning(...)Part of #18905
Dev notes
Originally, we covered Synapse startup by manually adding a logcontext, see #18870
Adding logcontext to
looping_callandcall_laterin #18907Mypy lint pattern came from #18828
Pull Request Checklist
EventStoretoEventWorkerStore.".code blocks.