Skip to content

Commit cf6fbf2

Browse files
authored
elasticapm: introduce ELASTIC_APM_SKIP_SERVER_INFO (#2516)
Introduce this option in order to avoid fetch the apm server info to get its version, off by default. Calling that endpoint with the aws lambda extension incurs in a measurable latency on AWS Lambda. Enabling this issue requires the receiving APM server version to be greater than 8.7.0. Option is still in technical preview.
1 parent 43f4deb commit cf6fbf2

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

docs/reference/configuration.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,23 @@ If set to `True`, the agent will intercept the default `sys.excepthook`, which a
969969
Whether each transaction should have the process arguments attached. Disabled by default to save disk space.
970970

971971

972+
### `skip_server_info` [config-skip-server-info]
973+
974+
| Environment | Django/Flask | Default |
975+
| --- | --- | --- |
976+
| `ELASTIC_APM_SKIP_SERVER_INFO` | `SKIP_SERVER_INFO` | `False` |
977+
978+
Whether we should skip the server info check to save some latency on constrained environments like AWS Lambda. Disabled by default.
979+
980+
::::{warning}
981+
This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.
982+
::::
983+
984+
::::{warning}
985+
This requires sending data to an APM Server newer than 8.7.0 in order to work properly.
986+
::::
987+
988+
972989
## Django-specific configuration [config-django-specific]
973990

974991

elasticapm/conf/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ class Config(_ConfigBase):
743743
default=TRACE_CONTINUATION_STRATEGY.CONTINUE,
744744
)
745745
include_process_args = _BoolConfigValue("INCLUDE_PROCESS_ARGS", default=False)
746+
skip_server_info = _BoolConfigValue("SKIP_SERVER_INFO", default=False)
746747

747748
@property
748749
def is_recording(self):

elasticapm/transport/http.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ def _get_cache_control_max_age(self, response_headers):
203203

204204
def _process_queue(self) -> None:
205205
if not self.client.server_version:
206-
self.fetch_server_info()
206+
# this is useful on aws lambda environments where this call incurs in unwanted latency
207+
if self.client.config.skip_server_info:
208+
logger.debug("Skipping to fetch server info")
209+
else:
210+
self.fetch_server_info()
207211
super()._process_queue()
208212

209213
def fetch_server_info(self) -> None:

tests/transports/test_urllib3.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,23 @@ def test_fetch_server_info_flat_string(waiting_httpserver, caplog, elasticapm_cl
520520
assert_any_record_contains(caplog.records, "No version key found in server response")
521521

522522

523+
def test_skip_server_info(waiting_httpserver, elasticapm_client):
524+
elasticapm_client.config.update(version="1", skip_server_info=True)
525+
waiting_httpserver.serve_content(code=202, content="", headers={"Location": "http://example.com/foo"})
526+
transport = Transport(
527+
waiting_httpserver.url, client=elasticapm_client, headers=elasticapm_client._transport._headers
528+
)
529+
transport.start_thread()
530+
try:
531+
url = transport.send("x".encode("latin-1"))
532+
assert url == "http://example.com/foo"
533+
finally:
534+
transport.close()
535+
536+
assert elasticapm_client.server_version is None
537+
assert elasticapm_client.check_server_version(gte=(8, 7, 1))
538+
539+
523540
def test_close(waiting_httpserver, elasticapm_client):
524541
elasticapm_client.server_version = (8, 0, 0) # avoid making server_info request
525542
waiting_httpserver.serve_content(code=202, content="", headers={"Location": "http://example.com/foo"})

0 commit comments

Comments
 (0)