autotelic / fastify-opentelemetry

A Fastify plugin that utilizes the OpenTelemetry API to provide request tracing.
MIT License
76 stars 12 forks source link

Unable to register plugin since migrating to esmodules #70

Closed Wazbat closed 1 month ago

Wazbat commented 2 months ago

Hi there,

I'm trying to migrate my application to ESM, however I now get the following error with this package.

This is the code:

import Fastify from 'fastify';
import openTelemertryPlugin from '@autotelic/fastify-opentelemetry';

export default async function makeApp() {
    const fastify = Fastify({
        logger: false
    });

    await fastify.register(openTelemertryPlugin, {
        wrapRoutes: ['/v3/search/merchant'],
        formatSpanName: (req) => (req.routeOptions?.url ? `${req.method} ${req.routeOptions.url}` : req.method)
    });
    return fastify;
}

And this is the error:

No overload matches this call.
  Overload 1 of 3, '(plugin: FastifyPluginCallback<FastifyPluginOptions, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'typeof fastifyOpenTelemetry' is not assignable to parameter of type 'FastifyPluginCallback<FastifyPluginOptions, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
      Type 'typeof fastifyOpenTelemetry' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: FastifyPluginOptions, done: (err?: Error | undefined) => void): void'.
  Overload 2 of 3, '(plugin: FastifyPluginAsync<FastifyPluginOptions, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'typeof fastifyOpenTelemetry' is not assignable to parameter of type 'FastifyPluginAsync<FastifyPluginOptions, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
      Type 'typeof fastifyOpenTelemetry' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: FastifyPluginOptions): Promise<...>'.
  Overload 3 of 3, '(plugin: FastifyPluginCallback<FastifyPluginOptions, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger> | FastifyPluginAsync<...> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'typeof fastifyOpenTelemetry' is not assignable to parameter of type 'FastifyPluginCallback<FastifyPluginOptions, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger> | FastifyPluginAsync<...> | Promise<...> | Promise<...>'.

image

I'm using @autotelic/fastify-opentelemetry version ^0.21.0 and version ^4.28.0 of fastify

HW13 commented 2 months ago

Hi @Wazbat, I'm not able to reproduce the error using the provided code example. Based on that error message and the screenshot, it looks like a TypeScript error. But I'm also unable to reproduce the error in a minimal TypeScript app. Without knowing more about your app setup there's limited help I can provide. Would you be able to provide a minimal example app that can reproduce this error?

HW13 commented 1 month ago

Closing this, as we are unable to reproduce