axiomhq/next-axiom

Failed to send logs to Axiom: TypeError: fetch failed

jsw opened this issue · 8 comments

jsw commented

Screen Shot 2022-12-22 at 7 37 55 PM

Any idea what could be causing this, or how I should troubleshoot?

  • can you check if there is any console logs in the frontend?
  • did you use withAxiom in nuxt.config.js as mentioned in the README?
jsw commented

I am using this page to test client-side and server-side logging

import { log } from 'next-axiom';

export default function Page() {
  log.debug('client debug');
  log.info('client info');
  log.warn('client warn');
  log.error('client error');
  return 'axiom';
}

export function getServerSideProps() {
  log.debug('server debug');
  log.info('server info');
  log.warn('server warn');
  log.error('server error');
  try {
    throw new Error('bad');
  } catch (e) {
    if (e instanceof Error) log.error(e.message, e);
    else log.error('error: ' + e);
  }
  return {
    props: {},
  };
}

I do have withAxiom in next.config.js.

I do see the client logs in the browser, but nothing else relevant, and I have seen both server and client logs in Axiom, but happened to also notice this error in Axiom.

  • next 12.3.4 on vercel
  • next-axiom 0.16.0
jsw commented

Not sure if related, but I notice the logger depends on AXIOM_DATASET and AXIOM_TOKEN. Is it possible these need to be prefixed with NEXT_PUBLIC_?

@jsw If you are using this with vercel integration then AXIOM_DATASET and AXIOM_TOKEN are not needed. Vercel sets up another env variable NEXT_PUBLIC_AXIOM_INGEST_ENDPOINT which next-axiom detects and use to send the logs.

I do see the client logs in the browser

you mean in the browser console? this probably means something is wrong with the env variable.

jsw commented

@schehata I was running the app locally to test Axiom behavior, and therefore setting env vars in my .env.local, which I guess would not normally be done. I will close this until I see the original issue again.

NEXT_PUBLIC_AXIOM_INGEST_ENDPOINT

Sorry, for hooking into this already closed thread. I have trouble sending anything with log.error, log.info, etc. to Vercel (being logged only to console). And the cited env var was only added for production environment, and apparently only for web-vitals(?).

image

  • Am I right, that logging would only work in production then?

Which I find confusing because all (preview, dev, and prod) the vercel builds are logged also. I will experiment with the env vars to see, if something will be sent...

Hi @ohager, the build logs are shipped through axiom log drain (vercel integration), but next-axiom logger works based on the existence of the environment variable.

You can make the env variable available for the other environments and you will be able to send the logs to axiom. (the variable is used for both the logs and web-vitals, next-axiom manages that internally).

Thanks for fast response...I just added the Ingestion Env var to the Preview environment also... and works.