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

Commit 3986f4b

Browse files
committed
Tag trace with instance name
As suggested in: - #13729 (comment) - #13729 (comment)
1 parent 5261d2e commit 3986f4b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

synapse/api/auth.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from synapse.http import get_request_user_agent
3333
from synapse.http.site import SynapseRequest
3434
from synapse.logging.opentracing import (
35+
SynapseTags,
3536
active_span,
3637
force_tracing,
3738
start_active_span,
@@ -161,6 +162,12 @@ async def get_user_by_req(
161162
parent_span.set_tag(
162163
"authenticated_entity", requester.authenticated_entity
163164
)
165+
# We tag the Synapse instance name so that it's an easy jumping
166+
# off point into the logs. Can also be used to filter for an
167+
# instance that is under load.
168+
parent_span.set_tag(
169+
SynapseTags.INSTANCE_NAME, self.hs.get_instance_name()
170+
)
164171
parent_span.set_tag("user_id", requester.user.to_string())
165172
if requester.device_id is not None:
166173
parent_span.set_tag("device_id", requester.device_id)

synapse/logging/opentracing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ class SynapseTags:
295295
# Whether the sync response has new data to be returned to the client.
296296
SYNC_RESULT = "sync.new_data"
297297

298+
INSTANCE_NAME = "instance_name"
299+
298300
# incoming HTTP request ID (as written in the logs)
299301
REQUEST_ID = "request_id"
300302

@@ -1032,11 +1034,11 @@ def trace_servlet(
10321034
# with JsonResource).
10331035
scope.span.set_operation_name(request.request_metrics.name)
10341036

1035-
# set the tags *after* the servlet completes, in case it decided to
1036-
# prioritise the span (tags will get dropped on unprioritised spans)
10371037
request_tags[
10381038
SynapseTags.REQUEST_TAG
10391039
] = request.request_metrics.start_context.tag
10401040

1041+
# set the tags *after* the servlet completes, in case it decided to
1042+
# prioritise the span (tags will get dropped on unprioritised spans)
10411043
for k, v in request_tags.items():
10421044
scope.span.set_tag(k, v)

0 commit comments

Comments
 (0)