Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I import OpenTelemetryModuleOptions, OpenTelemetryOptionsFactory interfaces? #498

Open
posquit0 opened this issue Sep 18, 2024 · 2 comments

Comments

@posquit0
Copy link

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
Copy link
Author

posquit0 commented Sep 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants