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

Package broken with newest opentelemetry dependencies

Open MarcStdt opened this issue 3 years ago • 17 comments

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)

MarcStdt avatar Nov 22 '21 21:11 MarcStdt

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: https://github.com/open-telemetry/opentelemetry-js/issues/2480

pragmaticivan avatar Nov 22 '21 22:11 pragmaticivan

any news?

elbasan avatar Dec 03 '21 14:12 elbasan

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

pragmaticivan avatar Dec 03 '21 14:12 pragmaticivan

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

elbasan avatar Dec 03 '21 14:12 elbasan

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

pragmaticivan avatar Dec 03 '21 15:12 pragmaticivan

I've fixed the compatibility with opentelemetry 0.27 in https://github.com/marcbachmann/opentelemetry-node-metrics/pull/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

marcbachmann avatar Dec 14 '21 14:12 marcbachmann

This still seems to be broken:

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

MattGson avatar May 01 '22 02:05 MattGson

The dependencies got updated on the branch main: https://github.com/pragmaticivan/nestjs-otel/commit/c2f8b7b9fbe116953521fb6b5d7f4648d09d7712#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R42

marcbachmann avatar May 01 '22 06:05 marcbachmann

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

pragmaticivan avatar May 02 '22 03:05 pragmaticivan

This still seems to be broken:

[email protected]/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() ?

simakwm avatar May 04 '22 13:05 simakwm

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

dkrylovdotcom avatar May 17 '22 10:05 dkrylovdotcom

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

schoenbergerb avatar May 19 '22 07:05 schoenbergerb

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

fuergaosi233 avatar May 28 '22 14:05 fuergaosi233

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.

pragmaticivan avatar May 29 '22 23:05 pragmaticivan

Hello. I am also getting this error:

[email protected]/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?

brpaz avatar Jun 25 '22 11:06 brpaz

For those in a hurry, here is a solution:

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

1eedaegon avatar Jun 30 '22 01:06 1eedaegon

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?

austonpramodh avatar Aug 22 '22 07:08 austonpramodh

Working example here: https://github.com/pragmaticivan/nestjs-otel-prom-grafana-tempo

pragmaticivan avatar Aug 29 '22 22:08 pragmaticivan