pragmaticivan / nestjs-otel

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

How can I import OpenTelemetryModuleOptions, OpenTelemetryOptionsFactory interfaces? #498

Open posquit0 opened 2 days ago

posquit0 commented 2 days ago

Expecting Behaviors

I want to configure OpenTelemetryModule with forRootAsync({ useClass: ... }) method by utilizing nestjs/config. But, it seems that nestjs-otel package is not exporting OpenTelemetryModuleOptions, OpenTelemetryOptionsFactory interfaces.

    OpenTelemetryModule.forRootAsync({
      useClass: OtelConfigService
    }),
import { Injectable, Logger } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { OpenTelemetryOptionsFactory, OpenTelemetryModuleOptions } from 'nestjs-otel';

@Injectable()
export class OtelConfigService implements OpenTelemetryOptionsFactory {
  private readonly logger = new Logger(OtelConfigService.name)

  constructor(private configService: ConfigService) {}

  createOpenTelemetryOptions(): Promise<OpenTelemetryModuleOptions> | OpenTelemetryModuleOptions {
    const { hostMetrics, apiMetrics } = this.configService.get('otel')

    return {
      metrics: {
        hostMetrics: hostMetrics.enabled,
        apiMetrics: {
          enable: apiMetrics.enabled,
        },
      },
    };
  }
}

Errors

0.145 yarn run v1.22.22
0.156 $ nest build
2.123 src/otel/otel-config.service.ts:3:10 - error TS2305: Module '"nestjs-otel"' has no exported member 'OpenTelemetryOptionsFactory'.
2.123
2.123 3 import { OpenTelemetryOptionsFactory, OpenTelemetryModuleOptions } from 'nestjs-otel';
2.123            ~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.123 src/otel/otel-config.service.ts:3:39 - error TS2724: '"nestjs-otel"' has no exported member named 'OpenTelemetryModuleOptions'. Did you mean 'OPENTELEMETRY_MODULE_OPTIONS'?
2.123
2.123 3 import { OpenTelemetryOptionsFactory, OpenTelemetryModuleOptions } from 'nestjs-otel';
2.123                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~
2.123
2.123   node_modules/nestjs-otel/lib/opentelemetry.constants.d.ts:1:22
2.123     1 export declare const OPENTELEMETRY_MODULE_OPTIONS = "OpenTelemetryModuleOptions";
2.123                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.123     'OPENTELEMETRY_MODULE_OPTIONS' is declared here.
2.123
2.125 Found 2 error(s).
pragmaticivan commented 2 days ago

Which version are you using?

https://github.com/pragmaticivan/nestjs-otel/blob/main/src/index.ts#L7 https://github.com/pragmaticivan/nestjs-otel/blob/main/src/opentelemetry.constants.ts#L1

posquit0 commented 2 days ago

Version is 6.1.1. How can I use forRootAsync({ useClass: ... }) with your suggested constant value? Is there any example code?

I'm working on my first Nest.js project, so I don't know much about it yet. 😂