Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix error reporting when using opentracing.trace #7961

Merged
merged 3 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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/7961.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sometimes returning 500 instead of the actual error response when using opentracing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fix sometimes returning 500 instead of the actual error response when using opentracing.
Fix a bug which could cause `500 Internal Server Error` to be returned instead of the actual response when an error was returned from REST APIs and opentracing was enabled..

13 changes: 1 addition & 12 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,24 +737,14 @@ def decorator(func):

@wraps(func)
async def _trace_inner(*args, **kwargs):
if opentracing is None:
with start_active_span(_opname):
return await func(*args, **kwargs)
Comment on lines -740 to 741
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to remove this earlier and it caused issues: #7872

I think the case this protects against is having opentracing installed, but disabled via the config.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you also remove the explicit scope.span.set_tag(...)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no. That makes sense. 👍


with start_active_span(_opname) as scope:
try:
return await func(*args, **kwargs)
except Exception:
scope.span.set_tag(tags.ERROR, True)
raise

else:
# The other case here handles both sync functions and those
# decorated with inlineDeferred.
@wraps(func)
def _trace_inner(*args, **kwargs):
if opentracing is None:
return func(*args, **kwargs)

scope = start_active_span(_opname)
scope.__enter__()

Expand All @@ -767,7 +757,6 @@ def call_back(result):
return result

def err_back(result):
scope.span.set_tag(tags.ERROR, True)
scope.__exit__(None, None, None)
return result

Expand Down
2 changes: 2 additions & 0 deletions synapse/logging/scopecontextmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def __enter__(self):
if self._enter_logcontext:
self.logcontext.__enter__()

return self

def __exit__(self, type, value, traceback):
if type == twisted.internet.defer._DefGen_Return:
super(_LogContextScope, self).__exit__(None, None, None)
Expand Down