-
Notifications
You must be signed in to change notification settings - Fork 361
Add the possibility to flush traces/metrics after a handler loop has finished #691
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
Comments
I patched the runtime with this to fix tracing in our lambdas:
|
Can you open a PR so we can review it with more context? |
Sure thing. |
Cross-posting what I said in the PR here: See MetricsService in https://github.com/BMorinDrifter/metrics-cloudwatch-embedded/blob/main/src/lambda.rs for how I did this for the embedded metrics crate. |
Internal extension could be the solution. You could create a library to start a background thread to interact with Lambda Extension API, register for invoke events. The extension will get a notification event when an invoke happens and can perform all kinds of tasks. It could even continue running after the handler returns. It is a good place to flush logs/traces. |
I added an example in #744 that uses an internal extension to flush telemetry after the handler finishes (once there's a new release of As OP mentioned, handlers sometimes panic, so for a production use case I would wrap the bulk of the handler in something like |
Internal extensions are an option, but I think we can make something simpler for this use case. I'm working on an RFC that I think will benefit the runtime in general providing a simpler solution. |
This is what I had in mind #747 |
The layering system that I described in #747 has landed in the main branch. Look at this example on how to flush traces/metrics after the handler loop has finished: https://github.com/awslabs/aws-lambda-rust-runtime/blob/main/examples/opentelemetry-tracing/src/main.rs I'm marking this as resolved. I'll release a new version with those improvements next week after adding some extra documentation. I'm closing this issue as resolved since it's possible to implement what you explained in this issue now. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
The problem I currently have is that there is no good way to flush traces/logs/metrics/errors once the runtime has finished handling a message.
Currently the handling code is structured something like this:
There are a couple of issues with this approach:
request_span
span can not be flushed since it's finished after the user provided handler is provided.I think it would be very valuable that the runtime would provide a hook for the end user so that they can do cleanup after each invocation.
The text was updated successfully, but these errors were encountered: