mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Merge pull request #6195 from matrix-org/erikj/opentracing_preview_url
Trace non-JSON APIs, /media, /key etc
This commit is contained in:
commit
6f5c6c8f60
1
changelog.d/6195.bugfix
Normal file
1
changelog.d/6195.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix tracing of non-JSON APIs, /media, /key etc.
|
@ -388,7 +388,7 @@ class DirectServeResource(resource.Resource):
|
|||||||
if not callback:
|
if not callback:
|
||||||
return super().render(request)
|
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 it's a coroutine, turn it into a Deferred
|
||||||
if isinstance(resp, types.CoroutineType):
|
if isinstance(resp, types.CoroutineType):
|
||||||
|
@ -169,6 +169,7 @@ import contextlib
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import types
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
@ -778,8 +779,7 @@ def trace_servlet(servlet_name, extract_context=False):
|
|||||||
return func
|
return func
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
@defer.inlineCallbacks
|
async def _trace_servlet_inner(request, *args, **kwargs):
|
||||||
def _trace_servlet_inner(request, *args, **kwargs):
|
|
||||||
request_tags = {
|
request_tags = {
|
||||||
"request_id": request.get_request_id(),
|
"request_id": request.get_request_id(),
|
||||||
tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER,
|
tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER,
|
||||||
@ -796,9 +796,15 @@ def trace_servlet(servlet_name, extract_context=False):
|
|||||||
scope = start_active_span(servlet_name, tags=request_tags)
|
scope = start_active_span(servlet_name, tags=request_tags)
|
||||||
|
|
||||||
with scope:
|
with scope:
|
||||||
result = yield defer.maybeDeferred(func, request, *args, **kwargs)
|
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 result
|
||||||
|
|
||||||
|
return await result
|
||||||
|
|
||||||
return _trace_servlet_inner
|
return _trace_servlet_inner
|
||||||
|
|
||||||
return _trace_servlet_inner_1
|
return _trace_servlet_inner_1
|
||||||
|
Loading…
Reference in New Issue
Block a user