Compare commits

...

6 Commits

Author SHA1 Message Date
Eric Eastwood
9d18ca7931 Remove OpenTracing changes
These changes are being introduced in https://github.com/element-hq/synapse/pull/18849
instead.
2025-08-20 16:09:01 -05:00
Eric Eastwood
704f7a2f38 Merge branch 'develop' into madlittlemods/17722-trace-byte-producer 2025-08-20 16:08:27 -05:00
Eric Eastwood
69a45c320c Add changelog 2025-08-20 15:47:45 -05:00
Eric Eastwood
acb096741e Add test for run_in_background losing the active scope
See https://github.com/element-hq/synapse/pull/18804#discussion_r2271246647
2025-08-12 19:28:02 -05:00
Eric Eastwood
3298e3d78b Add better context for why we clear scope 2025-08-12 17:01:56 -05:00
Eric Eastwood
9c2d9ab19a Intrument _ByteProducer with tracing
Spawning from https://github.com/element-hq/synapse/issues/17722
2025-08-11 17:24:48 -05:00
2 changed files with 14 additions and 1 deletions

1
changelog.d/18804.misc Normal file
View File

@@ -0,0 +1 @@
Instrument `_ByteProducer` with tracing to measure potential dead time while writing bytes to the request.

View File

@@ -702,6 +702,10 @@ class _ByteProducer:
self._request: Optional[Request] = request
self._iterator = iterator
self._paused = False
self.tracing_scope = start_active_span(
"write_bytes_to_request",
)
self.tracing_scope.__enter__()
try:
self._request.registerProducer(self, True)
@@ -712,8 +716,8 @@ class _ByteProducer:
logger.info("Connection disconnected before response was written: %r", e)
# We drop our references to data we'll not use.
self._request = None
self._iterator = iter(())
self.tracing_scope.__exit__(type(e), None, e.__traceback__)
else:
# Start producing if `registerProducer` was successful
self.resumeProducing()
@@ -727,6 +731,9 @@ class _ByteProducer:
self._request.write(b"".join(data))
def pauseProducing(self) -> None:
opentracing_span = active_span()
if opentracing_span is not None:
opentracing_span.log_kv({"event": "producer_paused"})
self._paused = True
def resumeProducing(self) -> None:
@@ -737,6 +744,10 @@ class _ByteProducer:
self._paused = False
opentracing_span = active_span()
if opentracing_span is not None:
opentracing_span.log_kv({"event": "producer_resumed"})
# Write until there's backpressure telling us to stop.
while not self._paused:
# Get the next chunk and write it to the request.
@@ -771,6 +782,7 @@ class _ByteProducer:
def stopProducing(self) -> None:
# Clear a circular reference.
self._request = None
self.tracing_scope.__exit__(None, None, None)
def _encode_json_bytes(json_object: object) -> bytes: