-
Notifications
You must be signed in to change notification settings - Fork 393
Introduce Clock.call_when_running(...)
to include logcontext by default
#18944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Clock.call_when_running(...)
to include logcontext by default
#18944
Conversation
@@ -0,0 +1 @@ | |||
Introduce `Clock.call_when_running(...)` to wrap startup code in a logcontext, ensuring we can identify which server generated the logs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
return None | ||
|
||
|
||
def check_call_when_running(ctx: MethodSigContext) -> CallableType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lint pattern is coming from #18828 where we're also going to lint call_later
and looping_call
in the future.
if not ignore_errs: | ||
raise | ||
|
||
def call_when_running( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
d.addErrback(log_failure, "Looping call died", consumeErrors=False) | ||
return call | ||
|
||
def call_later( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other functions like looping_call
and call_later
are getting their own logcontext wrappers in #18944
Thanks for the review @reivilibre 🐩 |
…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%} ```
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_call
andcall_later
in #18907Mypy lint pattern came from #18828
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.