Skip to content

fix(nodejs): flush logs before invocation completion - #2724

Closed
adityareddy-dev wants to merge 1 commit into
open-telemetry:mainfrom
adityareddy-dev:nodejs/flush-invocation-logs
Closed

adityareddy-dev wants to merge 1 commit into
open-telemetry:mainfrom
adityareddy-dev:nodejs/flush-invocation-logs

Conversation

@adityareddy-dev

Copy link
Copy Markdown
Member

I made Lambda instrumentation wait for the layer's log provider to flush before completing an invocation. This covers promise, callback and streaming handlers. Shutdown handling is outside this change.

Refs #2537.

@adityareddy-dev
adityareddy-dev requested a review from a team as a code owner November 5, 2026 09:24
@github-actions github-actions Bot added the javascript Pull requests that update Javascript code label Nov 5, 2026

@thompson-tomo thompson-tomo left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pr @adityareddy-dev i have taken a look at this pr & more broadly at the layer. I am wondering if we were to instead switch the layer to being a wrapper of the node-sdk package, would the flush issue be automatically solved? If it doesn't could it be solved there instead?

Would it be possible for you to have a test of this, my ask would be that additions are kept to a minimum, pr is focussed on just switching the providers/sdk & we can follow with additional pr's for improving instrumentation handling.

Copy link
Copy Markdown
Member Author

I tried NodeSDK 0.223.0 locally with an async handler and the layer's package versions. Logs stayed buffered at completion. Re-registering Lambda instrumentation after SDK startup flushed spans, but logs waited for shutdown.

NodeSDK has no invocation-end hook, so switching SDKs alone won't fix the log flush. The existing logger-provider flush PR covers that path and is still open. I'll keep this PR focused on the provider/SDK switch and handle instrumentation separately.

@thompson-tomo

Copy link
Copy Markdown
Contributor

Ok, just to confirm if we switch to node-sdk & the linked pr lands here the issue will be fixed? If so that is great news.

@adityareddy-dev

Copy link
Copy Markdown
Member Author

Yes, as long as the layer keeps re-registering the instrumentations after sdk.start(). I tried NodeSDK with the logger-provider flush change locally using a CommonJS async handler. Without the re-register nothing flushed at invocation end, with it all spans and logs flushed before the wrapped handler returned.

That PR targets SDK 3 and Node 22.15+ though, so we can't take that version as-is while the layer still supports nodejs20.x.

@thompson-tomo

Copy link
Copy Markdown
Contributor

Perfect, as we are dropping node 20 anyway as per #2709 i don't see an issue.

If you could open a pr with the switch to node sdk & otel v3 that would be appreciated. That way we can close the failing v3 upgrade pr's and look to merge your pr after #2709.

@adityareddy-dev

Copy link
Copy Markdown
Member Author

Closing this, the NodeSDK switch replaces it.

@github-project-automation github-project-automation Bot moved this from Todo to Done in Lambda Triage Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update Javascript code

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants