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

Asynchronous configuration not working #39

Open
finikm opened this issue May 11, 2022 · 2 comments
Open

Asynchronous configuration not working #39

finikm opened this issue May 11, 2022 · 2 comments

Comments

@finikm
Copy link

finikm commented May 11, 2022

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
@Informatic
Copy link

Informatic commented May 18, 2022

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 :/

@finikm
Copy link
Author

finikm commented May 18, 2022

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.

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

No branches or pull requests

3 participants