Conversation
…e). If set to true register the application as internal extension which allows quarkus to do post response stuff (otel flushes, still needs to be added).
brunobat
left a comment
There was a problem hiding this comment.
Thanks @hamburml.
If I understood well, the Idea is to register the lambda with an internal aws extension and allow an extra 500ms to flush all telemetry.
The lambda extension registration process seems complex. Don't they provide some utility for it?
| invocationCompletion.computeIfAbsent(requestId, ignored -> new CompletableFuture<>()).complete(null); | ||
| } | ||
|
|
||
| private static void runLoop(String runtimeApi, String extensionName, String extensionId) { |
There was a problem hiding this comment.
Sorry, I'm not familiar with this AWS API... Why do you need this runLoop?
There was a problem hiding this comment.
We need the runLoop because the Extensions API is blocking. One call to /2020-01-01/extension/event/next waits for one lifecycle event, and after the extension finishes handling that event it must call Next again to signal completion and wait for the next event (or is shutdown if AWS Lambda decides this environment is not necessary anymore and scales down).
| private LambdaInternalExtension() { | ||
| } | ||
|
|
||
| public static void startIfEnabled() { |
There was a problem hiding this comment.
Does this needs to run as a static code?
There was a problem hiding this comment.
I don’t think so. We mainly need a single coordinator, since the internal extension thread and the invocation tracking are runtime-wide in a Lambda execution environment. I used static state because it was the simplest way to get that i guess. We can change that.
Yeah, that’s the general idea. We register an internal extension and use it to keep the invoke lifecycle open so post-response work, such as telemetry flushing, can complete before AWS Lambda freezes the environment. As I understood it, Lambda considers the invoke phase finished only after both the runtime and all registered extensions have signaled completion. For an internal extension, that effectively means sending a request to The runtime thread signals completion for a given request id to the internal extension thread via invocationFinished once the post-response work is done. If flushing completes before the 500 ms cap, the extension thread can proceed earlier and return to /2020-01-01/extension/event/next, which signals to Lambda that the internal extension is also done for that invoke. So the function response may already have been sent, but Lambda still waits for the internal extension to finish before closing the invoke lifecycle.
I couldn’t find an official AWS Java helper specifically for the Extensions API - considering that almost all AWS APIs are Rest APIs i am not sure if there is a need for it. AWS documents the extension flow as direct calls to /2020-01-01/extension/register and /2020-01-01/extension/event/next using AWS_LAMBDA_RUNTIME_API. I did find this repo https://github.com/aws-samples/aws-lambda-extensions/blob/main/java-example-extension/src/main/java/example/ExtensionClient.java but yeah... |
quarkus.lambda.internal-extension.enabled=trueWhat still needs to be done: Only call invocationFInished when all otel flushes are done in a correct way.
Log examples from AWS which show that registration works.