Skip to content

Commit ccb99e5

Browse files
author
Colton Myers
authored
Fix empty flushed=True request for forced flushes (#1628)
* Fix empty flushed=True request for forced flushes * CHANGELOG * Use an empty string instead of an empty dict
1 parent 45abe97 commit ccb99e5

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ endif::[]
4848
* Restrict length of Starlette request bodies {pull}1549[#1549]
4949
* Fix error when using elasticsearch(sniff_on_start=True) {pull}1618[#1618]
5050
* Improve handling of ignored URLs and capture_body=off for Starlette {pull}1549[#1549]
51+
* Fix possible error in the transport flush for Lambda functions {pull}1628[#1628]
5152
5253
5354

elasticapm/transport/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ def _process_queue(self):
176176
if flush:
177177
if buffer_written:
178178
self._flush(buffer, forced_flush=forced_flush)
179-
elif forced_flush and "/localhost:" in self.client.config.server_url:
179+
elif forced_flush and any(x in self.client.config.server_url for x in ("/localhost:", "/127.0.0.1:")):
180180
# No data on buffer, but due to manual flush we should send
181181
# an empty payload with flushed=true query param, but only
182182
# to a local APM server (or lambda extension)
183-
self.send(None, flushed=True)
183+
self.send("", forced_flush=True)
184184
self._last_flush = timeit.default_timer()
185185
buffer = self._init_buffer()
186186
buffer_written = False

tests/transports/test_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,13 @@ def test_flushed_arg(sending_elasticapm_client):
264264
sending_elasticapm_client._transport.flush()
265265

266266
assert sending_elasticapm_client.httpserver.requests[0].args["flushed"] == "true"
267+
268+
269+
@pytest.mark.parametrize("sending_elasticapm_client", [{"api_request_time": "100ms"}], indirect=True)
270+
def test_flushed_arg_with_wait(sending_elasticapm_client):
271+
sending_elasticapm_client.begin_transaction("test_type")
272+
sending_elasticapm_client.end_transaction("test")
273+
time.sleep(0.2)
274+
sending_elasticapm_client._transport.flush()
275+
276+
assert sending_elasticapm_client.httpserver.requests[1].args["flushed"] == "true"

0 commit comments

Comments
 (0)