Remove scope from logcontext if logcontext is top level

pull/5544/head
Jorik Schellekens 2019-06-24 16:01:33 +01:00
parent 227447dc7e
commit f35bde3892
2 changed files with 9 additions and 3 deletions

View File

@ -238,7 +238,7 @@ class SynapseRequest(Request):
# Start a span
span_context = extract_span_context(self.requestHeaders)
opentracing.tracer.start_active_span(
span = opentracing.tracer.start_active_span(
"incoming-federation-request",
tags={
"request_id": self.get_request_id(),
@ -327,7 +327,7 @@ class SynapseRequest(Request):
assert(tags['request_id'] == self.get_request_id())
# finish the span if it's there.
scope.span.set_tag("peer.address", authenticated_entity)
scope.close()
scope.__exit__(None, None, None)
try:
self.request_metrics.stop(self.finish_time, self.code, self.sentLength)

View File

@ -50,13 +50,17 @@ class LogContextScopeManager(ScopeManager):
enter_logcontext = False
ctx = LoggingContext.current_context()
if ctx is LoggingContext.sentinel:
# We don't want this scope to affect.
logger.warning("Tried to activate scope outside of loggingcontext")
return Scope(None, span)
elif ctx.scope is not None:
ctx = nested_logging_context("scope")
# We want the logging scope to look exactly the same so we give it
# a blank suffix
ctx = nested_logging_context("")
enter_logcontext = True
scope = _LogContextScope(self, span, ctx, enter_logcontext, finish_on_close)
ctx.scope = scope
return scope
@ -82,6 +86,8 @@ class _LogContextScope(Scope):
super(_LogContextScope, self).__exit__(type, value, traceback)
if self._enter_logcontext:
self.logcontext.__exit__(type, value, traceback)
else: # the logcontext existed before the creation of the scope
self.logcontext.scope = None
def close(self):
if self.manager.active is not self: