nestjs-otel icon indicating copy to clipboard operation
nestjs-otel copied to clipboard

How can I import OpenTelemetryModuleOptions, OpenTelemetryOptionsFactory interfaces?

Open posquit0 opened this issue 1 year ago • 2 comments

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).

posquit0 avatar Sep 18 '24 18:09 posquit0

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

pragmaticivan avatar Sep 18 '24 19:09 pragmaticivan

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. 😂

posquit0 avatar Sep 19 '24 04:09 posquit0