diff options
author | Jorik Schellekens <joriks@matrix.org> | 2019-07-11 18:13:28 +0100 |
---|---|---|
committer | Jorik Schellekens <joriks@matrix.org> | 2019-07-17 14:20:22 +0100 |
commit | 4d54425b9dcfdff7c368cffa22a603d9f22d9346 (patch) | |
tree | 1eefb098ab8393818c655ba68bb3153a4741e02f /synapse | |
parent | Typos and errata (diff) | |
download | synapse-4d54425b9dcfdff7c368cffa22a603d9f22d9346.tar.xz |
Move dummy tags
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/logging/opentracing.py | 95 |
1 files changed, 61 insertions, 34 deletions
diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index e253a80043..96d9e157f3 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -49,38 +49,6 @@ logger = logging.getLogger(__name__) import inspect -class _DummyTagNames(object): - """wrapper of opentracings tags. We need to have them if we - want to reference them without opentracing around. Clearly they - should never actually show up in a trace. `set_tags` overwrites - these with the correct ones.""" - - INVALID_TAG = "invalid-tag" - COMPONENT = INVALID_TAG - DATABASE_INSTANCE = INVALID_TAG - DATABASE_STATEMENT = INVALID_TAG - DATABASE_TYPE = INVALID_TAG - DATABASE_USER = INVALID_TAG - ERROR = INVALID_TAG - HTTP_METHOD = INVALID_TAG - HTTP_STATUS_CODE = INVALID_TAG - HTTP_URL = INVALID_TAG - MESSAGE_BUS_DESTINATION = INVALID_TAG - PEER_ADDRESS = INVALID_TAG - PEER_HOSTNAME = INVALID_TAG - PEER_HOST_IPV4 = INVALID_TAG - PEER_HOST_IPV6 = INVALID_TAG - PEER_PORT = INVALID_TAG - PEER_SERVICE = INVALID_TAG - SAMPLING_PRIORITY = INVALID_TAG - SERVICE = INVALID_TAG - SPAN_KIND = INVALID_TAG - SPAN_KIND_CONSUMER = INVALID_TAG - SPAN_KIND_PRODUCER = INVALID_TAG - SPAN_KIND_RPC_CLIENT = INVALID_TAG - SPAN_KIND_RPC_SERVER = INVALID_TAG - - def only_if_tracing(func): """Executes the function only if we're tracing. Otherwise return. Assumes the function wrapped may return None""" @@ -98,8 +66,6 @@ def only_if_tracing(func): # Block everything by default _homeserver_whitelist = None -tags = _DummyTagNames - def init_tracer(config): """Set the whitelists and initialise the JaegerClient tracer @@ -544,3 +510,64 @@ def wrap_in_span(func): span.finish() return _wrap_in_span_inner + + +def trace_servlet(servlet_name, func): + """Decorator to trace a servlet""" + if not opentracing: + return func + + @wraps(func) + @defer.inlineCallbacks + def _trace_servlet_inner(request, *args, **kwargs): + with start_active_span_from_context( + request.requestHeaders, + "incoming-client-request", + tags={ + "request_id": request.get_request_id(), + tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER, + tags.HTTP_METHOD: request.get_method(), + tags.HTTP_URL: request.get_redacted_uri(), + tags.PEER_HOST_IPV6: request.getClientIP(), + "servlet_name": servlet_name, + }, + ): + result = yield defer.maybeDeferred(func, request, *args, **kwargs) + defer.returnValue(result) + + return _trace_servlet_inner + + +class _DummyTagNames(object): + """wrapper of opentracings tags. We need to have them if we + want to reference them without opentracing around. Clearly they + should never actually show up in a trace. `set_tags` overwrites + these with the correct ones.""" + + INVALID_TAG = "invalid-tag" + COMPONENT = INVALID_TAG + DATABASE_INSTANCE = INVALID_TAG + DATABASE_STATEMENT = INVALID_TAG + DATABASE_TYPE = INVALID_TAG + DATABASE_USER = INVALID_TAG + ERROR = INVALID_TAG + HTTP_METHOD = INVALID_TAG + HTTP_STATUS_CODE = INVALID_TAG + HTTP_URL = INVALID_TAG + MESSAGE_BUS_DESTINATION = INVALID_TAG + PEER_ADDRESS = INVALID_TAG + PEER_HOSTNAME = INVALID_TAG + PEER_HOST_IPV4 = INVALID_TAG + PEER_HOST_IPV6 = INVALID_TAG + PEER_PORT = INVALID_TAG + PEER_SERVICE = INVALID_TAG + SAMPLING_PRIORITY = INVALID_TAG + SERVICE = INVALID_TAG + SPAN_KIND = INVALID_TAG + SPAN_KIND_CONSUMER = INVALID_TAG + SPAN_KIND_PRODUCER = INVALID_TAG + SPAN_KIND_RPC_CLIENT = INVALID_TAG + SPAN_KIND_RPC_SERVER = INVALID_TAG + + +tags = _DummyTagNames |