mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-06-17 09:59:16 -04:00
Start fewer opentracing spans (#8640)
#8567 started a span for every background process. This is good as it means all Synapse code that gets run should be in a span (unless in the sentinel logging context), but it means we generate about 15x the number of spans as we did previously. This PR attempts to reduce that number by a) not starting one for send commands to Redis, and b) deferring starting background processes until after we're sure they're necessary. I don't really know how much this will help.
This commit is contained in:
parent
34a5696f93
commit
2b7c180879
8 changed files with 96 additions and 53 deletions
|
@ -24,7 +24,7 @@ from prometheus_client.core import REGISTRY, Counter, Gauge
|
|||
from twisted.internet import defer
|
||||
|
||||
from synapse.logging.context import LoggingContext, PreserveLoggingContext
|
||||
from synapse.logging.opentracing import start_active_span
|
||||
from synapse.logging.opentracing import noop_context_manager, start_active_span
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import resource
|
||||
|
@ -167,7 +167,7 @@ class _BackgroundProcess:
|
|||
)
|
||||
|
||||
|
||||
def run_as_background_process(desc: str, func, *args, **kwargs):
|
||||
def run_as_background_process(desc: str, func, *args, bg_start_span=True, **kwargs):
|
||||
"""Run the given function in its own logcontext, with resource metrics
|
||||
|
||||
This should be used to wrap processes which are fired off to run in the
|
||||
|
@ -181,6 +181,9 @@ def run_as_background_process(desc: str, func, *args, **kwargs):
|
|||
Args:
|
||||
desc: a description for this background process type
|
||||
func: a function, which may return a Deferred or a coroutine
|
||||
bg_start_span: Whether to start an opentracing span. Defaults to True.
|
||||
Should only be disabled for processes that will not log to or tag
|
||||
a span.
|
||||
args: positional args for func
|
||||
kwargs: keyword args for func
|
||||
|
||||
|
@ -199,7 +202,10 @@ def run_as_background_process(desc: str, func, *args, **kwargs):
|
|||
with BackgroundProcessLoggingContext(desc) as context:
|
||||
context.request = "%s-%i" % (desc, count)
|
||||
try:
|
||||
with start_active_span(desc, tags={"request_id": context.request}):
|
||||
ctx = noop_context_manager()
|
||||
if bg_start_span:
|
||||
ctx = start_active_span(desc, tags={"request_id": context.request})
|
||||
with ctx:
|
||||
result = func(*args, **kwargs)
|
||||
|
||||
if inspect.isawaitable(result):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue