axiomhq / axiom-js

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

Internal error in @axiomhq/winston causing npx tsc to fail #180

Closed ayushyadav468 closed 2 months ago

ayushyadav468 commented 4 months ago

I am using @axiomhq/winston to integrate winston and axiom. But this fails to build(build script: npx tsc)

Error by tsc: node_modules/@axiomhq/js/dist/esm/types/fetchClient.d.ts - error TS2314: Generic type 'RequestInitWithRetry' requires 1 type argument(s).

These lines: doReq<T>(endpoint: string, method: string, init?: RequestInitWithRetry, searchParams?: { post<T>(url: string, init?: RequestInitWithRetry, searchParams?: any): Promise<T>; get<T>(url: string, init?: RequestInitWithRetry, searchParams?: any): Promise<T>; put<T>(url: string, init?: RequestInitWithRetry, searchParams?: any): Promise<T>; delete<T>(url: string, init?: RequestInitWithRetry, searchParams?: any): Promise<T>;

My logger file:

import { WinstonTransport as AxiomTransport } from '@axiomhq/winston';
import winston from 'winston';

const { combine, errors, json } = winston.format;
const NODE_ENV = process.env.NODE_ENV ?? 'development';
let logger: winston.Logger;
if (NODE_ENV === 'production') {
    // Create a new Axiom transport instance
    const axiomTransport = new AxiomTransport({
        dataset: process.env.AXIOM_DATASET ?? '',
        token: process.env.AXIOM_TOKEN ?? '',
        orgId: process.env.AXIOM_ORG_ID ?? ''
    });
    logger = winston.createLogger({
        level: 'http',
        format: combine(errors({ stack: true }), json()),
        transports: [axiomTransport],
        exceptionHandlers: [axiomTransport],
        rejectionHandlers: [axiomTransport]
    });
} else {
    logger = winston.createLogger({
        level: 'http',
        format: combine(errors({ stack: true }), json()),
        transports: [new winston.transports.Console()],
        exceptionHandlers: [new winston.transports.Console()],
        rejectionHandlers: [new winston.transports.Console()]
    });
}
// Wrapper for the logger
export const log = (level: string, message: string, meta?: any) => {
    return logger.log({
        level,
        message,
        meta
    });
};

node: 20.11.1 npm: 10.2.4 typescript: 5.2.2 @axiomhq/winston: 1.0.0-rc.3 @axiomhq/js: 1.0.0-rc.3

SollyzDev commented 4 months ago

hi @ayushyadav468 thanks for brining this up, I've created a PR to test a change for fixing this. If all goes will, it will be part of the next release.

SollyzDev commented 4 months ago

waiting for #189 to include these together in the next release.