diff options
author | Jorik Schellekens <joriksch@gmail.com> | 2019-08-22 18:21:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-22 18:21:10 +0100 |
commit | 8767b63a821eb8612e2ab830534fd6f40eb1aaaa (patch) | |
tree | 43eb1604f1251cd36a1e394a3421cf8f850d0312 /synapse/logging/opentracing.py | |
parent | Merge pull request #5877 from Awesome-Technologies/remove_shared_secret_regis... (diff) | |
download | synapse-8767b63a821eb8612e2ab830534fd6f40eb1aaaa.tar.xz |
Propagate opentracing contexts through EDUs (#5852)
Propagate opentracing contexts through EDUs Co-Authored-By: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Diffstat (limited to 'synapse/logging/opentracing.py')
-rw-r--r-- | synapse/logging/opentracing.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index 4abea4474b..dd296027a1 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -149,6 +149,9 @@ unchartered waters will require the enforcement of the whitelist. ``logging/opentracing.py`` has a ``whitelisted_homeserver`` method which takes in a destination and compares it to the whitelist. +Most injection methods take a 'destination' arg. The context will only be injected +if the destination matches the whitelist or the destination is None. + ======= Gotchas ======= @@ -576,6 +579,29 @@ def inject_active_span_text_map(carrier, destination, check_destination=True): ) +def get_active_span_text_map(destination=None): + """ + Gets a span context as a dict. This can be used instead of manually + injecting a span into an empty carrier. + + Args: + destination (str): the name of the remote server. + + Returns: + dict: the active span's context if opentracing is enabled, otherwise empty. + """ + + if not opentracing or (destination and not whitelisted_homeserver(destination)): + return {} + + carrier = {} + opentracing.tracer.inject( + opentracing.tracer.active_span, opentracing.Format.TEXT_MAP, carrier + ) + + return carrier + + def active_span_context_as_string(): """ Returns: |