next-axiom icon indicating copy to clipboard operation
next-axiom copied to clipboard

[bug] logs are not showing up sometimes for Vercel edge function (pages router)

Open GorvGoyl opened this issue 2 years ago • 7 comments

Sometimes logs do not show up and I'd like to know if this is a known bug or if am I doing something wrong. I'm on pages router and followed this guide: https://github.com/axiomhq/next-axiom/blob/v0.x/README.md

//  "next-axiom": "0.18.1",
import { AxiomRequest, withAxiom } from "next-axiom";

export const config = {
  runtime: "edge",
};

async function handler(req: AxiomRequest) {
  const console = req.log.with({ traceId: "xxx" });

  console.info("inside model api");

  console.info("model data", {
    model: "text-davinci-002-render",
  });

  return new Response(
    JSON.stringify({
      model: "text-davinci-002-render",
    }),
    {
      status: 200,
      headers: {
        "content-type": "application/json",
      },
    }
  );
}
export default withAxiom(handler);

other event logs are always shown, it's the console.info logs that are missing.

screenshot 2023-11-29 at 18 37 58@2x

GorvGoyl avatar Nov 29 '23 11:11 GorvGoyl

Hey hey, is this on a production environment?

bahlo avatar Nov 29 '23 11:11 bahlo

Hey hey, is this on a production environment?

for the preview environment but I have enabled the AXIOM env variable for all environments in case that's what you were wondering.

Also, I tried adding await console.flush(); in the api but still logs get missed in some function calls. As shown below, API was called 2 times but the info logs showed up only once.

image

GorvGoyl avatar Nov 29 '23 11:11 GorvGoyl

Hi, any update on this?

GorvGoyl avatar Nov 30 '23 12:11 GorvGoyl

same issue. when i do it locally no issues. When i deploy, this is happening on cloudflare pages. did you ever resolve?

josephp27 avatar Jan 16 '24 00:01 josephp27

does the same thing happen when you use the logger directly, without creating a child-logger using with?

bahlo avatar Mar 26 '24 11:03 bahlo

I dug into this and was able to get logging working fine with @cloudflare/next-on-pages.

What didn't work fine, which is what made me think there was an issue in the first place, is that isEdgeRuntime is false on Cloudflare workers and the logEdgeReport never gets called. @bahlo I'm not deeply familiar with the cloudflare worker runtime, is there a way we could easily identify it and include it in the isEdgeRuntime calculation?

levi avatar Mar 27 '24 17:03 levi