Nestjs-OpenTelemetry icon indicating copy to clipboard operation
Nestjs-OpenTelemetry copied to clipboard

Asynchronous configuration not working

Open finikm opened this issue 2 years ago • 2 comments

Configuring the module using OpenTelemetryModule.forRoot works without any issues (thanks for your work), trying to configure it using OpenTelemetryModule.forRootAsync so that I can provide a configuration service (@nestjs/config to be exact, but the problem persists even without anything) I get the following error:

TypeError: (intermediate value) is not iterable
    at Function.forRootAsync (/data/test-otel/node_modules/@metinseylan/nestjs-opentelemetry/dist/OpenTelemetryModule.js:1:1)
    at Object.<anonymous> (/data/test-otel/src/app.module.ts:8:25)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/data/test-otel/src/main.ts:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)

Also tried:

  • with or without webpack (in a monorepo environment)
  • a brand new Nest project (using both yarn and npm) and installing just the module (not even the configuration module)

problem remains, and is always the same.

Environment

  • MacOS 12.3.1
  • node 16.14.2
  • yarn 1.22.15

finikm avatar May 11 '22 15:05 finikm

That is caused by missing imports key in forRootAsync call - the following instantiation of OpenTelemetryModule succeeds without said error:

    OpenTelemetryModule.forRootAsync({
      imports: [],
      useFactory: () => ({
        applicationName: 'nestjs-opentelemetry-example',
        metricExporter: new PrometheusExporter({
          endpoint: 'metrics',
          port: 9100,
        }),
        metricInterval: 100,
      }),
    }),

The error is coming from this line: https://github.com/MetinSeylan/Nestjs-OpenTelemetry/blob/main/src/OpenTelemetryModule.ts#L114 (imports falls back to undefined which is indeed not iterable)

Adding that key, however, is not enough to make request metrics work (none are reported), so this issue still stands :/

Informatic avatar May 18 '22 09:05 Informatic

Thanks @Informatic.

It works when I add an empty array as imports. Traces (which is what I use this library for) are reported correctly. I leave the issue open though, so @MetinSeylan can look into it further.

finikm avatar May 18 '22 12:05 finikm