Skip to content

Commit

Permalink
Fix empty flushed=True request for forced flushes (#1628)
Browse files Browse the repository at this point in the history
* Fix empty flushed=True request for forced flushes

* CHANGELOG

* Use an empty string instead of an empty dict
  • Loading branch information
Colton Myers authored Sep 7, 2022
1 parent 45abe97 commit ccb99e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ endif::[]
* Restrict length of Starlette request bodies {pull}1549[#1549]
* Fix error when using elasticsearch(sniff_on_start=True) {pull}1618[#1618]
* Improve handling of ignored URLs and capture_body=off for Starlette {pull}1549[#1549]
* Fix possible error in the transport flush for Lambda functions {pull}1628[#1628]
Expand Down
4 changes: 2 additions & 2 deletions elasticapm/transport/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ def _process_queue(self):
if flush:
if buffer_written:
self._flush(buffer, forced_flush=forced_flush)
elif forced_flush and "/localhost:" in self.client.config.server_url:
elif forced_flush and any(x in self.client.config.server_url for x in ("/localhost:", "/127.0.0.1:")):
# No data on buffer, but due to manual flush we should send
# an empty payload with flushed=true query param, but only
# to a local APM server (or lambda extension)
self.send(None, flushed=True)
self.send("", forced_flush=True)
self._last_flush = timeit.default_timer()
buffer = self._init_buffer()
buffer_written = False
Expand Down
10 changes: 10 additions & 0 deletions tests/transports/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,13 @@ def test_flushed_arg(sending_elasticapm_client):
sending_elasticapm_client._transport.flush()

assert sending_elasticapm_client.httpserver.requests[0].args["flushed"] == "true"


@pytest.mark.parametrize("sending_elasticapm_client", [{"api_request_time": "100ms"}], indirect=True)
def test_flushed_arg_with_wait(sending_elasticapm_client):
sending_elasticapm_client.begin_transaction("test_type")
sending_elasticapm_client.end_transaction("test")
time.sleep(0.2)
sending_elasticapm_client._transport.flush()

assert sending_elasticapm_client.httpserver.requests[1].args["flushed"] == "true"

0 comments on commit ccb99e5

Please sign in to comment.