synapse/tests
Eric Eastwood 06a84f4fe0
Revert "Switch to OpenTracing's ContextVarsScopeManager (#18849)" (#19007)
Revert https://github.com/element-hq/synapse/pull/18849

Go back to our custom `LogContextScopeManager` after trying
OpenTracing's `ContextVarsScopeManager`.

Fix https://github.com/element-hq/synapse/issues/19004

### Why revert?

For reference, with the normal reactor, `ContextVarsScopeManager` worked
just as good as our custom `LogContextScopeManager` as far as I can tell
(and even better in some cases). But since Twisted appears to not fully
support `ContextVar`'s, it doesn't work as expected in all cases.
Compounding things, `ContextVarsScopeManager` was causing errors with
the experimental `SYNAPSE_ASYNC_IO_REACTOR` option.

Since we're not getting the full benefit that we originally desired, we
might as well revert and figure out alternatives for extending the
logcontext lifetimes to support the use case we were trying to unlock
(c.f. https://github.com/element-hq/synapse/pull/18804).

See
https://github.com/element-hq/synapse/issues/19004#issuecomment-3358052171
for more info.


### Does this require backporting and patch releases?

No. Since `ContextVarsScopeManager` operates just as good with the
normal reactor and was only causing actual errors with the experimental
`SYNAPSE_ASYNC_IO_REACTOR` option, I don't think this requires us to
backport and make patch releases at all.



### Maintain cross-links between main trace and background process work

In order to maintain the functionality introduced in https://github.com/element-hq/synapse/pull/18932 (cross-links between the background process trace and currently active trace), we also needed a small change.

Previously, when we were using `ContextVarsScopeManager`, it tracked the tracing scope across the logcontext changes without issue. Now that we're using our own custom `LogContextScopeManager` again, we need to capture the active span from the logcontext before we reset to the sentinel context because of the `PreserveLoggingContext()` below.

Added some tests to ensure we maintain the `run_as_background` tracing behavior regardless of the tracing scope manager we use.
2025-10-02 11:27:26 -05:00
..
api Update MSC4326 error code (#18947) 2025-09-24 11:57:24 +01:00
app Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
appservice Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
config Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
crypto Fix server_name in logging context for multiple Synapse instances in one process (#18868) 2025-09-26 17:10:48 -05:00
events Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
federation Fix server_name in logging context for multiple Synapse instances in one process (#18868) 2025-09-26 17:10:48 -05:00
handlers Merge branch 'develop' of github.com:element-hq/synapse into develop 2025-10-01 09:40:38 +01:00
http Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
logging Revert "Switch to OpenTracing's ContextVarsScopeManager (#18849)" (#19007) 2025-10-02 11:27:26 -05:00
media Remove MockClock() (#18992) 2025-09-30 11:27:29 -05:00
metrics Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
module_api Document and fix room_config param when user_may_create_room callback is invoked for a room upgrade (#18721) 2025-09-24 21:42:19 +00:00
push Remove sentinel logcontext in Clock utilities (looping_call, looping_call_now, call_later) (#18907) 2025-09-22 14:51:13 -05:00
replication Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
rest Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
scripts Update license headers 2023-11-21 15:29:58 -05:00
server_notices Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
state Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
storage Remove MockClock() (#18992) 2025-09-30 11:27:29 -05:00
test_utils Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
types Support for room version 12 2025-08-11 16:43:45 +01:00
util Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
__init__.py Correctly mention previous copyright (#16820) 2024-01-23 11:26:48 +00:00
server.py Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
test_distributor.py Cleanly shutdown SynapseHomeServer object (#18828) 2025-10-01 02:42:09 +00:00
test_event_auth.py Format files with Ruff (#17643) 2024-09-02 12:39:04 +01:00
test_mau.py Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
test_phone_home.py Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
test_rust.py Add missing type hints to tests. (#15027) 2023-02-08 19:52:37 +00:00
test_server.py Remove MockClock() (#18992) 2025-09-30 11:27:29 -05:00
test_state.py Remove MockClock() (#18992) 2025-09-30 11:27:29 -05:00
test_terms_auth.py Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
test_types.py Format files with Ruff (#17643) 2024-09-02 12:39:04 +01:00
test_visibility.py Introduce Clock.call_when_running(...) to include logcontext by default (#18944) 2025-09-22 10:27:59 -05:00
unittest.py Remove MockClock() (#18992) 2025-09-30 11:27:29 -05:00
utils.py Remove MockClock() (#18992) 2025-09-30 11:27:29 -05:00