Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 59a9d93

Browse files
authored
fix: do not back-off on intake req errors in Lambda env (#180)
This ensures that the APM agent instrumentation in a Lambda function will not cause a `null` response from the user's handler if the agent cannot talk to the extension. Note that the spec at elastic/apm#613 related to this might yet change. Refs: elastic/apm-agent-nodejs#1831 Refs: elastic/apm#613
1 parent 0073c43 commit 59a9d93

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# elastic-apm-http-client changelog
22

3+
## Unreleased
4+
5+
- Fix an issue when running in a Lambda function, where a missing or erroring
6+
APM Lambda extension could result in apmclient back-off such that (a) the
7+
end-of-lambda-invocation signaling (`?flushed=true`) would not happen and
8+
(b) premature "beforeExit" event could result in the Lambda Runtime
9+
responding `null` before the Lambda function could respond
10+
(https://github.com/elastic/apm-agent-nodejs/issues/1831).
11+
312
## v11.0.0
413

514
- Add support for coordinating data flushing in an AWS Lambda environment. The

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,18 @@ Client.prototype._destroy = function (err, cb) {
781781
// Return the appropriate backoff delay (in milliseconds) before a next possible
782782
// request to APM server.
783783
// Spec: https://github.com/elastic/apm/blob/main/specs/agents/transport.md#transport-errors
784+
//
785+
// In a Lambda environment, a backoff delay can be harmful: The backoff
786+
// setTimeout is unref'd, to not hold the process open. A subsequent Lambda
787+
// function invocation during that timer will result in no active handles and
788+
// a process "beforeExit" event. That event is interpreted by the Lambda Runtime
789+
// as "the Lambda function callback was never called", and it terminates the
790+
// function and responds with `null`. The solution is to never backoff in a
791+
// Lambda environment -- we expect and assume the Lambda extension is working,
792+
// and pass responsibility for backoff to the extension.
784793
Client.prototype._getBackoffDelay = function (isErr) {
785794
let reconnectCount = this._backoffReconnectCount
786-
if (isErr) {
795+
if (isErr && !isLambdaExecutionEnvironment) {
787796
this._backoffReconnectCount++
788797
} else {
789798
this._backoffReconnectCount = 0

0 commit comments

Comments
 (0)