axiomhq/next-axiom

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

Opened this issue · 6 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

Hey hey, is this on a production environment?

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

Hi, any update on this?

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

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

levi commented

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?