-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AWS lambda - process is killed before the span is being exported #1295
Comments
@open-telemetry/javascript-maintainers && @open-telemetry/javascript-approvers |
I think this can be solved by adding a callback to the |
FWIW, when I was working on something similar to this it was required to have a synchronous export pathway for the data to escape through. Lambda will freeze execution of the process after the lambda has been marked as complete (i.e. the response callback was called, the promise returned by the handler settles, or the process attempts to exit due to inactivity). In the case where the response callback is called, the async work that was pending will start back up the next time the process is unfrozen, which will result in unpredictable export timings. @michaelgoin or @astorm might also have more context to add to this. |
The behavior when the callback is called is dictated by the When using an In both cases, if the user calls force flush in their handler code and only finishes the handler after the force flush is complete, then this is fixed. note: it may be tempting to call the handler callback early and have the force flush continue in the background, but the lambda runtime actually doesn't return the response to the user until the whole function invocation is complete. This is a very frustrating situation, but it is true. For instance, the following handler for an API gateway request will return the response to the user in ~500ms rather than ~0ms as you would expect: module.exports.handler = (event, context, cb) => {
cb(); // return immediately
setTimeout(() => {}, 500); // keep tasks on the event loop for 500ms
}; time curl ...
curl ... 0.00s user 0.01s system 2% cpu 0.621 total |
@dyladan do you know if there is a way to get access to this |
or maybe we can patch the whole |
@obecny
This does potentially modify the execution semantics for the lambda from under the user, but it would be roughly what we would want to do. |
In an autoinstrumentation I would suggest you either:
For this issue, I think it is sufficient to give the user a way to manually flush and not worry about wrapping handler or patching anything. |
Actually I have already been working on this and will have a PR shortly. |
@obecny if you have not started working on this, i actually already have an implementation of forceFlush callbacks that I can open a PR with |
I'll just open the PR, let me know if i should close it. |
@dyladan great, no I haven't started working on that. I think the final fix / solution will need to do probably several things so I will wait until you make PR to see what you have discovered and done :) . |
Ok. Here it is #1296 All this PR does is provide a mechanism to wait for the flush to complete. The lambda plugin PR will be coming later. Probably early next week. |
@dyladan Do you have a reference to this lambda plugin or guidance on aws lambda implementation? I'm noticing that my lambda is not exporting the spans. |
Actually someone else ended up writing the lambda plugin so I never had to :) You can find it in the contrib repo. |
Weird, I have that in there but something isn't working still. Let me see if I can dig deeper. Feel free to share any debug techniques or what to look for in the logs. |
I would open an issue on the contrib repo and ping @willarmiros or @anuraaga since they maintain that instrumentation |
This is a simple scenario of lambda function
The span is not exported correctly as lambda seems to kill the process before it gets exported
When adding some timeout before the process get killed the span iss exported
So the idea is to implement some async method either on tracer or exporter or change the exporter method
shutdown
to be a promise and to be resolved when the last exports is sent successfullyWDYT ?
The text was updated successfully, but these errors were encountered: