Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18849.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch to OpenTracing's `ContextVarsScopeManager` instead of our own custom `LogContextScopeManager`.
9 changes: 1 addition & 8 deletions synapse/logging/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
from twisted.python.threadpool import ThreadPool

if TYPE_CHECKING:
from synapse.logging.scopecontextmanager import _LogContextScope
from synapse.types import ISynapseReactor

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -230,14 +229,13 @@ class ContextRequest:
class _Sentinel:
"""Sentinel to represent the root context"""

__slots__ = ["previous_context", "finished", "request", "scope", "tag"]
__slots__ = ["previous_context", "finished", "request", "tag"]

def __init__(self) -> None:
# Minimal set for compatibility with LoggingContext
self.previous_context = None
self.finished = False
self.request = None
self.scope = None
self.tag = None

def __str__(self) -> str:
Expand Down Expand Up @@ -290,7 +288,6 @@ class LoggingContext:
"finished",
"request",
"tag",
"scope",
]

def __init__(
Expand All @@ -311,7 +308,6 @@ def __init__(
self.main_thread = get_thread_id()
self.request = None
self.tag = ""
self.scope: Optional["_LogContextScope"] = None

# keep track of whether we have hit the __exit__ block for this context
# (suggesting that the the thing that created the context thinks it should
Expand All @@ -324,9 +320,6 @@ def __init__(
# we track the current request_id
self.request = self.parent_context.request

# we also track the current scope:
self.scope = self.parent_context.scope

if request is not None:
# the request param overrides the request from the parent context
self.request = request
Expand Down
7 changes: 3 additions & 4 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,17 @@ class _DummyTagNames:
try:
import opentracing
import opentracing.tags
from opentracing.scope_managers.contextvars import ContextVarsScopeManager

tags = opentracing.tags
except ImportError:
opentracing = None # type: ignore[assignment]
tags = _DummyTagNames # type: ignore[assignment]
ContextVarsScopeManager = None # type: ignore
try:
from jaeger_client import Config as JaegerConfig

from synapse.logging.scopecontextmanager import LogContextScopeManager
except ImportError:
JaegerConfig = None # type: ignore
LogContextScopeManager = None # type: ignore


try:
Expand Down Expand Up @@ -484,7 +483,7 @@ def init_tracer(hs: "HomeServer") -> None:
config = JaegerConfig(
config=jaeger_config,
service_name=f"{hs.config.server.server_name} {instance_name_by_type}",
scope_manager=LogContextScopeManager(),
scope_manager=ContextVarsScopeManager(),
metrics_factory=PrometheusMetricsFactory(),
)

Expand Down
161 changes: 0 additions & 161 deletions synapse/logging/scopecontextmanager.py

This file was deleted.

Loading
Loading