axiomhq / next-axiom

The official Next.js library for Axiom.
https://axiom.co/vercel
MIT License
363 stars 27 forks source link

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

Open GorvGoyl opened 11 months ago

GorvGoyl commented 11 months ago

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

bahlo commented 11 months ago

Hey hey, is this on a production environment?

GorvGoyl commented 11 months ago

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 commented 11 months ago

Hi, any update on this?

josephp27 commented 9 months ago

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

bahlo commented 7 months ago

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

levi commented 7 months ago

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?

cjxe commented 1 month ago

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

@levi how?