-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Various opentracing enhancements #11619
Changes from all commits
9aee261
0891776
68cd102
41fab2a
c95b8ef
5676701
aaf59c8
fd7b6a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A number of improvements to opentracing support. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,12 +58,14 @@ | |
) | ||
from synapse.http.site import SynapseRequest | ||
from synapse.logging.context import defer_to_thread, preserve_fn, run_in_background | ||
from synapse.logging.opentracing import trace_servlet | ||
from synapse.logging.opentracing import active_span, start_active_span, trace_servlet | ||
from synapse.util import json_encoder | ||
from synapse.util.caches import intern_dict | ||
from synapse.util.iterutils import chunk_seq | ||
|
||
if TYPE_CHECKING: | ||
import opentracing | ||
|
||
from synapse.server import HomeServer | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -759,7 +761,20 @@ async def _async_write_json_to_request_in_thread( | |
expensive. | ||
""" | ||
|
||
json_str = await defer_to_thread(request.reactor, json_encoder, json_object) | ||
def encode(opentracing_span: "Optional[opentracing.Span]") -> bytes: | ||
# it might take a while for the threadpool to schedule us, so we write | ||
# opentracing logs once we actually get scheduled, so that we can see how | ||
# much that contributed. | ||
if opentracing_span: | ||
opentracing_span.log_kv({"event": "scheduled"}) | ||
res = json_encoder(json_object) | ||
if opentracing_span: | ||
opentracing_span.log_kv({"event": "encoded"}) | ||
return res | ||
|
||
with start_active_span("encode_json_response"): | ||
span = active_span() | ||
Comment on lines
+775
to
+776
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We seem to be using this same logic in a bunch of places, it looks similar to the (I guess in this case we need the span itself so we can call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, it's less opentracing, and more our wrappers for opentracing (which make opentracing itself an optional dependency). If you have a real opentracing, you can do:
... but with our wrappers, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, OK! That makes a bit more sense! |
||
json_str = await defer_to_thread(request.reactor, encode, span) | ||
|
||
_write_bytes_to_request(request, json_str) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to convince myself that
authenticated_entity
was the same here:authenticated_entity
isn't set during creation of the requester and we report the tag asuser_id
; this was essentially inlined logic fromcreate_requester
user_info.token_owner
, which is the same thing that is passed as theauthenticated_entity
increate_requester
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, yes, I must have gone through that same thought process, but forgot to write it down here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! Definitely better to put all this logic in one place though!