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

Commit a911ffb

Browse files
Tag trace with instance name (#13761)
We tag the Synapse instance name so that it's an easy jumping off point into the logs. Can also be used to filter for an instance that is under load. As suggested by @clokep and @reivilibre in, - #13729 (comment) - #13729 (comment)
1 parent f694bb7 commit a911ffb

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

changelog.d/13761.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tag traces with the instance name to be able to easily jump into the right logs and filter traces by instance.

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
@@ -298,6 +298,8 @@ class SynapseTags:
298298
# Whether the sync response has new data to be returned to the client.
299299
SYNC_RESULT = "sync.new_data"
300300

301+
INSTANCE_NAME = "instance_name"
302+
301303
# incoming HTTP request ID (as written in the logs)
302304
REQUEST_ID = "request_id"
303305

@@ -1043,11 +1045,11 @@ def trace_servlet(
10431045
# with JsonResource).
10441046
scope.span.set_operation_name(request.request_metrics.name)
10451047

1046-
# set the tags *after* the servlet completes, in case it decided to
1047-
# prioritise the span (tags will get dropped on unprioritised spans)
10481048
request_tags[
10491049
SynapseTags.REQUEST_TAG
10501050
] = request.request_metrics.start_context.tag
10511051

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

0 commit comments

Comments
 (0)