Skip to content

Commit

Permalink
Merge pull request #224 from axiomhq/expose-on-error-in-winston
Browse files Browse the repository at this point in the history
feat(winston): expose onError method and pass it down to Axiom client
  • Loading branch information
dasfmi authored Nov 4, 2024
2 parents a2bab68 + 196baca commit 1fbaab3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 12 additions & 8 deletions integration/src/winston.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,27 @@ describe('WinstonTransport', () => {
logger.log({
level: 'info',
message: 'Hello from winston',
callback: (err: Error) => {
console.error("winston failed to send logs", err)
}
});

logger.end()

logger.on('finish', () => {
console.log('All logs have been sent');
})

// Wait for the log to be sent
await new Promise((resolve) => setTimeout(resolve, 1500));

const startTime = new Date(new Date().getTime() - 1000 * 60 * 60 * 24).toISOString();
const endTime = new Date(new Date().getTime() + 1000 * 60 * 60 * 24).toISOString();

// const res = await axiom.datasets.query(`['${datasetName}']`, {
// startTime, endTime, streamingDuration: 'auto', noCache: false,
// });

const res = await axiom.queryLegacy(datasetName, {
resolution: 'auto',
startTime,
endTime,
const res = await axiom.query(`['${datasetName}']`, {
startTime, endTime, streamingDuration: 'auto', noCache: false,
});

expect(res.matches).toHaveLength(1);
});
});
3 changes: 2 additions & 1 deletion packages/winston/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export interface WinstonOptions extends TransportStreamOptions {
token: string;
orgId?: string;
url?: string;
onError?: (err: Error) => void;
}

// TODO: @arne get the error handling changes from axiom-node package
export class WinstonTransport extends Transport {
client: AxiomWithoutBatching;
dataset: string;
Expand All @@ -23,6 +23,7 @@ export class WinstonTransport extends Transport {
token: opts.token,
orgId: opts.orgId,
url: opts.url,
onError: opts.onError,
});
this.dataset = opts?.dataset || process.env.AXIOM_DATASET || '';
}
Expand Down

0 comments on commit 1fbaab3

Please sign in to comment.