synapse/synapse
Eric Eastwood d05f44a1c6
Introduce Clock.add_system_event_trigger(...) to include logcontext by default (#18945)
Introduce `Clock.add_system_event_trigger(...)` to wrap system event
callback code in a logcontext, ensuring we can identify which server
generated the logs.

Background:

>  Ideally, nothing from the Synapse homeserver would be logged against the `sentinel` 
>  logcontext as we want to know which server the logs came from. In practice, this is not 
>  always the case yet especially outside of request handling. 
>   
>  Global things outside of Synapse (e.g. Twisted reactor code) should run in the 
>  `sentinel` logcontext. It's only when it calls into application code that a logcontext 
>  gets activated. This means the reactor should be started in the `sentinel` logcontext, 
>  and any time an awaitable yields control back to the reactor, it should reset the 
>  logcontext to be the `sentinel` logcontext. This is important to avoid leaking the 
>  current logcontext to the reactor (which would then get picked up and associated with 
>  the next thing the reactor does). 
>
> *-- `docs/log_contexts.md`

Also adds a lint to prefer `Clock.add_system_event_trigger(...)` over
`reactor.addSystemEventTrigger(...)`

Part of https://github.com/element-hq/synapse/issues/18905
2025-09-22 11:47:22 -05:00
..
_scripts Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
api Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
app Introduce Clock.add_system_event_trigger(...) to include logcontext by default (#18945) 2025-09-22 11:47:22 -05:00
appservice Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
config Implement MSC4169: backwards-compatible redaction sending for rooms < v11 using the /send endpoint (#18898) 2025-09-22 14:50:52 +01:00
crypto Support for room version 12 2025-08-11 16:43:45 +01:00
events Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
federation Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
handlers Introduce Clock.add_system_event_trigger(...) to include logcontext by default (#18945) 2025-09-22 11:47:22 -05:00
http Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
logging Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
media Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
metrics Better explain which context the task is run in when using run_in_background(...) or run_as_background_process(...) (#18906) 2025-09-12 09:29:35 -05:00
module_api Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
push Configure Synapse to run MSC4306: Thread Subscriptions Complement tests. (#18819) 2025-09-09 11:40:10 +01:00
replication Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
res Send an email if the address is already bound to an user account (#16819) 2024-04-23 16:45:24 +01:00
rest Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
server_notices Refactor cache metrics to be homeserver-scoped (#18604) 2025-07-16 16:04:57 -05:00
spam_checker_api
state Support for room version 12 2025-08-11 16:43:45 +01:00
static
storage Introduce Clock.add_system_event_trigger(...) to include logcontext by default (#18945) 2025-09-22 11:47:22 -05:00
streams Add experimental support for MSC4308: Thread Subscriptions extension to Sliding Sync when MSC4306 and MSC4186 are enabled. (#18695) 2025-09-11 14:45:04 +01:00
synapse_rust Implement the push rules for experimental MSC4306: Thread Subscriptions. (#18762) 2025-08-06 15:33:52 +01:00
types Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
util Introduce Clock.add_system_event_trigger(...) to include logcontext by default (#18945) 2025-09-22 11:47:22 -05:00
__init__.py Remove some obsolete Twisted version checks. (#18729) 2025-07-30 12:31:55 +01:00
_pydantic_compat.py Stabilise MAS integration (#18759) 2025-08-04 15:48:45 +02:00
event_auth.py Support for room version 12 2025-08-11 16:43:45 +01:00
notifier.py Add experimental support for MSC4308: Thread Subscriptions extension to Sliding Sync when MSC4306 and MSC4186 are enabled. (#18695) 2025-09-11 14:45:04 +01:00
py.typed
server.py Introduce Clock.add_system_event_trigger(...) to include logcontext by default (#18945) 2025-09-22 11:47:22 -05:00
visibility.py Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00