pragmaticivan / nestjs-otel

OpenTelemetry (Tracing + Metrics) module for Nest framework (node.js) 🔭
Apache License 2.0
562 stars 48 forks source link

fix: fix/metric annotation wrongly typed #484

Closed JulienFauvel closed 6 months ago

JulienFauvel commented 6 months ago

Hello,

following the issue https://github.com/pragmaticivan/nestjs-otel/issues/471, I created this fix

The createParamDecorator didn't returned the right type, so the example code in the Readme can't be compiled. But it does work if you ignore the TS error.

This is the type that was generated in metrics/decorators/counter.d.ts

export declare const OtelCounter: (...dataOrPipes: (string | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;

I reworked a bit the param decorators with the function createMetricParamDecorator, and gather all of them in param.ts as it has become simpler

With the fix this is the d.ts generated:

export type MetricParamDecorator = (name: string, options?: OtelMetricOptions) => ParameterDecorator;
export declare const OtelCounter: MetricParamDecorator;

I also added an assertion in the E2E test for this use case

pragmaticivan commented 6 months ago

Thank you!