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

Commit

Permalink
Merge pull request #6195 from matrix-org/erikj/opentracing_preview_url
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Feb 26, 2020
2 parents 23f22d8 + 6f5c6c8 commit 1b032df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/6195.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix tracing of non-JSON APIs, /media, /key etc.
2 changes: 1 addition & 1 deletion synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def render(self, request):
if not callback:
return super().render(request)

resp = callback(request)
resp = trace_servlet(self.__class__.__name__)(callback)(request)

# If it's a coroutine, turn it into a Deferred
if isinstance(resp, types.CoroutineType):
Expand Down
14 changes: 10 additions & 4 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def set_fates(clotho, lachesis, atropos, father="Zues", mother="Themis"):
import inspect
import logging
import re
import types
from functools import wraps
from typing import Dict

Expand Down Expand Up @@ -778,8 +779,7 @@ def _trace_servlet_inner_1(func):
return func

@wraps(func)
@defer.inlineCallbacks
def _trace_servlet_inner(request, *args, **kwargs):
async def _trace_servlet_inner(request, *args, **kwargs):
request_tags = {
"request_id": request.get_request_id(),
tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER,
Expand All @@ -796,8 +796,14 @@ def _trace_servlet_inner(request, *args, **kwargs):
scope = start_active_span(servlet_name, tags=request_tags)

with scope:
result = yield defer.maybeDeferred(func, request, *args, **kwargs)
return result
result = func(request, *args, **kwargs)

if not isinstance(result, (types.CoroutineType, defer.Deferred)):
# Some servlets aren't async and just return results
# directly, so we handle that here.
return result

return await result

return _trace_servlet_inner

Expand Down

0 comments on commit 1b032df

Please sign in to comment.