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

Package broken with newest opentelemetry dependencies #151

Closed
MarcStdt opened this issue Nov 22, 2021 · 18 comments
Closed

Package broken with newest opentelemetry dependencies #151

MarcStdt opened this issue Nov 22, 2021 · 18 comments

Comments

@MarcStdt
Copy link

When using the latest opentelementy packages (0.27.0), the Nest application fails to start with the following error:

/home/node/app/node_modules/nestjs-otel/src/metrics/metric-data.ts:27
      const valueRecorder = meter.createValueRecorder(name, options);
                                  ^
TypeError: meter.createValueRecorder is not a function
    at getOrCreateValueRecorder (/home/node/app/node_modules/nestjs-otel/src/metrics/metric-data.ts:27:35)
    at MetricService.getOrCreateValueRecorder (/home/node/app/node_modules/nestjs-otel/src/metrics/metric.service.ts:26:36)
    at MetricService.getValueRecorder (/home/node/app/node_modules/nestjs-otel/src/metrics/metric.service.ts:20:17)
    at new ApiMetricsMiddleware (/home/node/app/node_modules/nestjs-otel/src/middleware/api-metrics.middleware.ts:90:47)
    at Injector.instantiateClass (/home/node/app/node_modules/@nestjs/core/injector/injector.js:301:19)
    at callback (/home/node/app/node_modules/@nestjs/core/injector/injector.js:48:41)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Injector.resolveConstructorParams (/home/node/app/node_modules/@nestjs/core/injector/injector.js:124:24)
    at async Injector.loadInstance (/home/node/app/node_modules/@nestjs/core/injector/injector.js:52:9)
    at async Injector.loadMiddleware (/home/node/app/node_modules/@nestjs/core/injector/injector.js:61:9)
@pragmaticivan
Copy link
Owner

That's actually great news 😂 I will try to patch that up this weekend, It will require a major version though. I've been keeping track of this release for a while but some packages might be moved somewhere else FYI.

Ref: open-telemetry/opentelemetry-js#2480

@elbasan
Copy link

elbasan commented Dec 3, 2021

any news?

@pragmaticivan
Copy link
Owner

pragmaticivan commented Dec 3, 2021

howdy @elbasan there's a WIP Pr coming up to fix that. Unfortunately since metrics API was experimental, there is no major version bumps.

@elbasan
Copy link

elbasan commented Dec 3, 2021

howdy @elbasan there's a WIP Pr coming up to fix that. Unfortunately since metrics API was experimental, there is no major version bumps.

Hey there, thanks for the quick response. Could you maybe tell me about to which versions i should downgrade the otel libaries so it still works

@pragmaticivan
Copy link
Owner

@elbasan I need to check again but my current project is running 0.24.0.

@marcbachmann
Copy link

marcbachmann commented Dec 14, 2021

I've fixed the compatibility with opentelemetry 0.27 in marcbachmann/opentelemetry-node-metrics#3

For the metrics, it should be straight forward to migrate and even keep the compatibility: https://github.com/marcbachmann/opentelemetry-node-metrics/blob/master/index.js#L9-L16

@MattGson
Copy link

MattGson commented May 1, 2022

This still seems to be broken:

opentelemetry-node-metrics@1.1.0/node_modules/opentelemetry-node-metrics/metrics/version.js:17
  }).bind(version).add(1)
     ^
TypeError: meter.createUpDownCounter(...).bind is not a function

@marcbachmann
Copy link

The dependencies got updated on the branch main: c2f8b7b#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R42

@pragmaticivan
Copy link
Owner

@MattGson could you share which packages you are using? (versions)

I have it working here https://github.com/pragmaticivan/nestjs-otel-prom-grafana-tempo (latest released version)

@simakwm
Copy link

simakwm commented May 4, 2022

This still seems to be broken:

opentelemetry-node-metrics@1.1.0/node_modules/opentelemetry-node-metrics/metrics/version.js:17
  }).bind(version).add(1)
     ^
TypeError: meter.createUpDownCounter(...).bind is not a function

@MattGson Maybe you forgot to do await otelSDK.start() ?

@dkrylovdotcom
Copy link

The same problem:

TypeError: meter.createUpDownCounter(...).bind is not a function
    at module.exports (/Users/macos/Documents/work/projects/js/nodejs/nest-third-telemetry/node_modules/opentelemetry-node-metrics/metrics/version.js:17:6)
    at setupNodeMetrics (/Users/macos/Documents/work/projects/js/nodejs/nest-third-telemetry/node_modules/opentelemetry-node-metrics/index.js:18:31)
    at OpenTelemetryCoreModule.onApplicationBootstrap (/Users/macos/Documents/work/projects/js/nodejs/nest-third-telemetry/node_modules/nestjs-otel/src/opentelemetry-core.module.ts:110:44)
    at callModuleBootstrapHook (/Users/macos/Documents/work/projects/js/nodejs/nest-third-telemetry/node_modules/@nestjs/core/hooks/on-app-bootstrap.hook.js:51:35)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at NestApplication.callBootstrapHook (/Users/macos/Documents/work/projects/js/nodejs/nest-third-telemetry/node_modules/@nestjs/core/nest-application-context.js:198:13)
    at NestApplication.init (/Users/macos/Documents/work/projects/js/nodejs/nest-third-telemetry/node_modules/@nestjs/core/nest-application.js:98:9)
    at NestApplication.listen (/Users/macos/Documents/work/projects/js/nodejs/nest-third-telemetry/node_modules/@nestjs/core/nest-application.js:155:33)
    at bootstrap (/Users/macos/Documents/work/projects/js/nodejs/nest-third-telemetry/src/main.ts:26:3)

package.json:

"dependencies": {
    "@nestjs/common": "^8.1.1",
    "@nestjs/core": "^8.1.1",
    "@nestjs/platform-express": "^8.1.1",
    "@opentelemetry/auto-instrumentations-node": "0.27.1",
    "@opentelemetry/sdk-node": "0.27.0",
    "nestjs-otel": "^3.0.4",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.4.0"
  },

await otelSDK.start(); in place, but it seems like problem happens when NodeSDK constructs

@schoenbergerb
Copy link

same problem, but if I set metrics.defautMetrics to false in the module options the service comes up

@fuergaosi233
Copy link

same problem, but if I set metrics.defautMetrics to false in the module options the service comes up

It works for me, and I have to turn off this switch to use it

@pragmaticivan
Copy link
Owner

pragmaticivan commented May 29, 2022

Investigating the changes, be aware that metrics SDK in JS is not stable and this package support for metrics aim to give it as a tease before 1.0. It's unlikely you might get quick support by the underlying packages, so I would slow down a bit on updating packages related to metrics.

@brpaz
Copy link

brpaz commented Jun 25, 2022

Hello. I am also getting this error:

opentelemetry-node-metrics@1.1.0/node_modules/opentelemetry-node-metrics/metrics/version.js:17
  }).bind(version).add(1)
     ^
TypeError: meter.createUpDownCounter(...).bind is not a function

From what I understood this was fixed here in the opentelemetry-node-metrics.. which is already the version on the main branch on this repo, but not in the latest released tag.

@pragmaticivan Any chance to create a new release please?

@1eedaegon
Copy link

For those in a hurry, here is a solution:

const OpenTelemetryModuleConfig = OpenTelemetryModule.forRoot({
metrics: {
...blah
// defaultMetrics: true, <- ** commented this line **
...blah
},
},
});

@austonpramodh
Copy link

austonpramodh commented Aug 22, 2022

For me, the below worked.

It seems to be an issue with the old version(1.1.0) of opentelemetry-node-metrics package being used. Forcing the package manager to install the latest version of opentelemetry-node-metrics did the trick for me.

add the following in package.json
image

btw, I am using yarn. This won't work for npm.

npm users: https://stackoverflow.com/questions/15806152/how-do-i-override-nested-npm-dependency-versions
yarn users: https://stackoverflow.com/questions/40226639/how-do-i-override-nested-dependencies-with-yarn

@pragmaticivan
How can I help resolve this issue? Should I update the dependency and raise a pr, or do you have something else in mind?

@pragmaticivan
Copy link
Owner

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

Successfully merging a pull request may close this issue.