-
Notifications
You must be signed in to change notification settings - Fork 29
feat: add support for Lambda data flushing #178
Conversation
This adds 'Client#lambdaStart()' and the 'lambdaEnd: true' option to 'Client#flush([opts,] [cb])' to support for flushing Lambda invocation tracing data and signaling the Elastic Lambda extension per spec. https://github.com/elastic/apm/blob/main/specs/agents/tracing-instrumentation-aws-lambda.md#data-flushing Refs: elastic/apm-agent-nodejs#2485
…t' due to this socket unref Given that we now ensure the intake request and flush completes before calling the Lambda handler callback, we *want* to keep that socket ref'd.
This fixes an issue with corking when events come after a client.flush({lambdaEnd: true}) in *the same tick*. Before this those events could slip into the stream and result in a subsequent intake request starting after the `lambdaEnd`... which would often result in those events being lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really have a good mental model for how this client, particularly the flushing, works anymore so I can't really give a canonical 👍 or 👎 on what overall effect this new code will have.
However -- I've reviewed the new branching and from what I see the new Lambda flushing features appear to be gated correctly and leaves the non-lambda functionality intact. In the few places where the mainline functionality has been altered (ex. addition of the flush marker to _writeFlush
) the changes are minor enough that it shouldn't effect the overall behavior of the client when operating in non-lambda mode.
Also, for what it's worth, this is another example where a separate/different HTTP client (that implements the same defacto-public interface) for Lambda would make this sort of functionality less-risky/less-difficult to implement. It may make sense in the future to take advantage of the Agent's architecture around it's transport object. Not recommending this change be made now, just dinging that bell again.
Approving.
[email protected] is published |
This adds 'Client#lambdaStart()' and the 'lambdaEnd: true' option to
'Client#flush([opts,] [cb])' to support for flushing Lambda invocation
tracing data and signaling the Elastic Lambda extension per spec.
https://github.com/elastic/apm/blob/main/specs/agents/tracing-instrumentation-aws-lambda.md#data-flushing
Refs: elastic/apm-agent-nodejs#2485
Checklist