axiomhq / axiom-js

Official language bindings and library extensions for Axiom
https://axiom.co
MIT License
87 stars 14 forks source link

Catch fetch errors or allow overwrite fetch #131

Closed bkniffler closed 5 months ago

bkniffler commented 7 months ago

Getting this error during log ingestion:

FetchError: request to https://api.axiom.co/v1/datasets/..../ingest failed, reason: getaddrinfo ENOTFOUND api.axiom.co

This is causing unhandled promise rejection with the automatic flushing.

I'd suggest we get some option to capture this, e.g.

const axiom = new Axiom({
  token: '...',
  orgId: '...',
  fetch: async (a, b) => fetch(a, b).catch(() => ..)
  // or
  handleError: () => ....
});
schehata commented 6 months ago

I am working on handling those exception now, finalizing the PR.

schehata commented 6 months ago

we have a released a new version of axiom-js and axiom-pino that would solve the exceptions handling in axiom-js. on Monday we will continue investigating Pino package and add some tests to ensure that doesn't happen again. let us know if this works our for you, and if there is any thing we can improve on the new onError() method.

bkniffler commented 5 months ago

Hey, thanks @schehata, it did indeed solve my problem, I'm using onError to suppress errors, thanks!