Skip to content

Missing await on defaultRouteHandlerOnSuccess causes log loss in serverless environments #339

@hamflx

Description

@hamflx

Hey team,

I'm hitting a bug that's causing log loss in my Vercel serverless functions.

The issue is that calls to the async function defaultRouteHandlerOnSuccess are missing an await. This means the serverless function can finish executing before logger.flush() completes, so the logs never get sent. I saw this happening specifically in my /api/webhook/stripe endpoint.

The Problematic Code:

https://github.com/axiomhq/axiom-js/blob/main/packages/nextjs/src/routeHandler.ts#L196

const callbackFn = async () => {
  // ...
  // No await here, so it's a "fire-and-forget" call
  defaultRouteHandlerOnSuccess(logger, httpData); 
};

The Fix:

The fix is to simply add await to the call:

const callbackFn = async () => {
  // ...
  // Adding await fixes the issue
  await defaultRouteHandlerOnSuccess(logger, httpData);
};

Thanks for the great library, hope this helps

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions