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

Expose opentracing trace id in response headers #10199

Merged
merged 2 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10199.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expose opentracing trace id in response headers.
6 changes: 6 additions & 0 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ async def new_func(request, *args, **kwargs):
"incoming-federation-request", tags=request_tags
)

if hasattr(scope, "span"):
# include the trace id in the response headers.
request.responseHeaders.addRawHeader(
"Synapse-Trace-Id", f"{scope.span.context.trace_id:x}"
)

with scope:
if origin and self.RATELIMIT:
with ratelimiter.ratelimit(origin) as d:
Expand Down
5 changes: 5 additions & 0 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,11 @@ def trace_servlet(request: "SynapseRequest", extract_context: bool = False):
else:
scope = start_active_span(request_name)

# include the trace id in the response headers.
request.responseHeaders.addRawHeader(
"Synapse-Trace-Id", f"{scope.span.context.trace_id:x}"
)

with scope:
try:
yield
Expand Down