Skip to content

Commit 70d152b

Browse files
committed
Revert "elasticapm: rework buffering of apm data"
This reverts commit af8499d.
1 parent 8f52ea6 commit 70d152b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

elasticapm/transport/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _process_queue(self) -> None:
153153
buffer_written = True
154154
self._counts[event_type] += 1
155155

156-
queue_size = 0 if buffer is None else buffer.tell()
156+
queue_size = 0 if buffer.fileobj is None else buffer.fileobj.tell()
157157

158158
forced_flush = flush
159159
if forced_flush:
@@ -219,7 +219,7 @@ def _process_event(self, event_type, data):
219219
return data
220220

221221
def _init_buffer(self):
222-
buffer = io.BytesIO()
222+
buffer = gzip.GzipFile(fileobj=io.BytesIO(), mode="w", compresslevel=self._compress_level)
223223
return buffer
224224

225225
def _write_metadata(self, buffer) -> None:
@@ -251,7 +251,10 @@ def _flush(self, buffer, forced_flush=False) -> None:
251251
if not self.state.should_try():
252252
logger.error("dropping flushed data due to transport failure back-off")
253253
else:
254-
data = gzip.compress(buffer.getvalue(), compresslevel=self._compress_level)
254+
fileobj = buffer.fileobj # get a reference to the fileobj before closing the gzip file
255+
buffer.close()
256+
257+
data = fileobj.getbuffer()
255258
try:
256259
self.send(data, forced_flush=forced_flush)
257260
self.handle_transport_success()

0 commit comments

Comments
 (0)