mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-22 12:44:30 +03:00
Create and use a method to get the span context as a dict.
This commit is contained in:
parent
bd0ed7b0c4
commit
4f36a2dfec
2 changed files with 26 additions and 2 deletions
|
@ -527,6 +527,31 @@ def inject_active_span_text_map(carrier, destination=None):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_active_span_text_map(destination=None):
|
||||||
|
"""
|
||||||
|
Gets a span context as a dict. This can be used instead of injecting a span
|
||||||
|
into an empty carrier.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
destination (str): the name of the remote server. The dict will only
|
||||||
|
contain a span context if the destination matches the homeserver_whitelist
|
||||||
|
or if destination is None.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A dict containing the span context.
|
||||||
|
"""
|
||||||
|
|
||||||
|
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():
|
def active_span_context_as_string():
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
|
|
|
@ -828,8 +828,7 @@ class DeviceStore(DeviceWorkerStore, BackgroundUpdateStore):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
context = {"opentracing": {}}
|
context = {"opentracing": opentracing.get_active_span_text_map()}
|
||||||
opentracing.inject_active_span_text_map(context["opentracing"])
|
|
||||||
|
|
||||||
self._simple_insert_many_txn(
|
self._simple_insert_many_txn(
|
||||||
txn,
|
txn,
|
||||||
|
|
Loading…
Reference in a new issue