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

Type 'PeriodicExportingMetricReader' is not assignable to type 'MetricReader'. Types have separate declarations of a private property '_shutdown'. #3944

Closed
Eji4h opened this issue Jun 23, 2023 · 13 comments
Labels
bug Something isn't working has:reproducer This bug/feature has a minimal reproducer provided information-requested Bug is waiting on additional information from the user triage

Comments

@Eji4h
Copy link

Eji4h commented Jun 23, 2023

What happened?

Steps to Reproduce

By following the instructions in the [Exporters] article (https://opentelemetry.io/docs/instrumentation/js/exporters/), my team set up PeriodicExportingMetricReader to metricReader of NodeSDK.

Expected Result

No error message should be received.

Actual Result

Type 'PeriodicExportingMetricReader' is not assignable to type 'MetricReader'.
  Types have separate declarations of a private property '_shutdown'.

from TypeScript when we set PeriodicExportingMetricReader to metricReader of NodeSDK.

Additional Details

Setting traceExporter is acceptable. We attempt to install dependencies on any version, but it is not working.

OpenTelemetry Setup Code

'use strict';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { envDetector } from '@opentelemetry/resources';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { IncomingMessage } from 'http';
import { KafkaJsInstrumentation } from 'opentelemetry-instrumentation-kafkajs';

import { traceExporterUrl } from './configs/log.config.env';

const httpInstrumentConfig = {
  ignoreIncomingRequestHook: (req: IncomingMessage) => req.url == '/health',
};

const exporterOptions = {
  url: traceExporterUrl,
};

const traceExporter = new OTLPTraceExporter(exporterOptions);
const metricExporter = new OTLPMetricExporter({
  url: '<your-otlp-endpoint>/v1/metrics', // url is optional and can be omitted - default is http://localhost:4318/v1/metrics
  headers: {}, // an optional object containing custom headers to be sent with each request
});

const sdk = new NodeSDK({
  traceExporter,
  metricReader: new PeriodicExportingMetricReader({
    exporter: metricExporter,
  }),
  instrumentations: [
    getNodeAutoInstrumentations({ '@opentelemetry/instrumentation-http': httpInstrumentConfig }),
    new KafkaJsInstrumentation(),
  ],
  resourceDetectors: [envDetector],
});

export const start = () => sdk.start();

['SIGINT', 'SIGTERM'].forEach((signal) => {
  process.on(signal, () => {
    sdk
      .shutdown()
      .then(() => console.info('Tracing terminated'))
      .catch((error) => console.error('Error terminating tracing', error))
      .finally(() => process.exit(0));
  });
});

package.json

{
  "name": "backend",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "engines": {
    "node": ">=18",
    "pnpm": ">=7"
  },
  "scripts": {
    ...
  },
  "dependencies": {
    ...
    "@opentelemetry/api": "^1.3.0",
    "@opentelemetry/auto-instrumentations-node": "^0.37.1",
    "@opentelemetry/exporter-metrics-otlp-grpc": "^0.40.0",
    "@opentelemetry/exporter-trace-otlp-grpc": "^0.40.0",
    "@opentelemetry/resources": "^1.14.0",
    "@opentelemetry/sdk-metrics": "^1.14.0",
    "@opentelemetry/sdk-node": "^0.40.0",
    "@opentelemetry/sdk-trace-node": "^1.14.0",
    "@opentelemetry/semantic-conventions": "^1.14.0",
    ...
  },
  "devDependencies": {
    ...
    "@types/node": "^18.14.0",
    "typescript": "^4.9.5",
    ...
  }
}

Relevant log output

No response

@Eji4h Eji4h added bug Something isn't working triage labels Jun 23, 2023
@pichlermarc pichlermarc added the needs:reproducer This bug/feature is in need of a minimal reproducer label Jun 28, 2023
@pichlermarc
Copy link
Member

Hi, thanks for reaching out - I tried to reproduce this but it looks like everything compiles fine when I try it. (see https://github.com/pichlermarc/repro-3944)

Would you mind adding a reproducer similar to (or based on) the one I linked above so we can troubleshoot the problem? 🤔

@dyladan dyladan added the information-requested Bug is waiting on additional information from the user label Jun 28, 2023
@Mifrill
Copy link

Mifrill commented Sep 18, 2023

Hey @pichlermarc, I face the same issue but for different versions of packages, please take a look at PR with bug reproduction:
pichlermarc/repro-3944#1

@pichlermarc
Copy link
Member

@Mifrill ah, thanks, this does reproduce it! this seems to be because "@opentelemetry/sdk-node": "^0.41.2" selects @opentelemetry/[email protected] and "@opentelemetry/sdk-metrics": "^1.14.0" selects @opentelemetry/[email protected]. These are not expected to be compatible, see https://github.com/open-telemetry/opentelemetry-js#package-version-compatibility. A fix would be to bump the dependency so that @opentelemetry/[email protected] is selected.

Please let me know if that fixes the issue 🙂

@pichlermarc pichlermarc added has:reproducer This bug/feature has a minimal reproducer provided and removed needs:reproducer This bug/feature is in need of a minimal reproducer labels Sep 19, 2023
@Mifrill
Copy link

Mifrill commented Sep 20, 2023

@pichlermarc yup, the bump @opentelemetry/sdk-node@ to 0.43.0 version solving it, thank you, much appreciated 👍

@pichlermarc
Copy link
Member

@pichlermarc yup, the bump @opentelemetry/sdk-node@ to 0.43.0 version solving it, thank you, much appreciated 👍

Glad to hear 🙂

@Eji4h would you mind checking if the proposed solution also works for you?

@Eji4h
Copy link
Author

Eji4h commented Sep 28, 2023

@pichlermarc yup, the bump @opentelemetry/sdk-node@ to 0.43.0 version solving it, thank you, much appreciated 👍

Glad to hear 🙂

@Eji4h would you mind checking if the proposed solution also works for you?

Thanks

@Mifrill
Copy link

Mifrill commented Oct 23, 2023

Hey @pichlermarc based on your comment and documentation, the sdk-node 0.43 should be compatible with sdk-metrics 1.17:
image

However, it seems like something went wrong with documenation, because this bug is reproducible on those versions, see: pichlermarc/repro-3944#2

Though, it can be fixed by the next version sdk-node 0.44, see: Mifrill/repro-3944#1.

Perhaps it is worth docs fix.

@saadbahir
Copy link

I have

"@opentelemetry/sdk-metrics": "^1.19.0",
"@opentelemetry/sdk-node": "^0.46.0",

and i have the exact same issue

Type 'PeriodicExportingMetricReader' is not assignable to type 'MetricReader'.
  Types have separate declarations of a private property '_shutdown'.ts(2322)

anyone else is in the same boat?

@itsgrimetime
Copy link

I'm also hitting this still, with the following versions:

    "@opentelemetry/auto-instrumentations-node": "^0.40.3",
    "@opentelemetry/exporter-metrics-otlp-grpc": "^0.47.0",
    "@opentelemetry/exporter-trace-otlp-grpc": "^0.47.0",
    "@opentelemetry/sdk-metrics": "^1.20.0",
    "@opentelemetry/sdk-node": "^0.47.0",
    "@opentelemetry/api": "^1.7.0",
    "@opentelemetry/core": "^1.20.0",

@cscervantes
Copy link

cscervantes commented Feb 16, 2024

This would fix that

  1. npx npm-check-updates -u
  2. npm install

But first remove package-lock.json and node_modules before running npm install.

@TmNguyen12
Copy link

I'm running into this issue with version:

"@opentelemetry/sdk-metrics": "^1.23.0",
"@opentelemetry/sdk-node": "^0.50.0",

@chagasjoao
Copy link

Same here!

"@opentelemetry/sdk-metrics": "^1.24.0",
"@opentelemetry/sdk-node": "^0.50.0",

@Lehoczky
Copy link

I can confirm, the issue exists with the latest versions as well:

    "@opentelemetry/sdk-metrics": "^1.25.1",
    "@opentelemetry/sdk-node": "^0.52.1",

For anyone looking for a workaround, these version ranges work:

    "@opentelemetry/sdk-metrics": "~1.24.1",
    "@opentelemetry/sdk-node": "~0.51.1",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has:reproducer This bug/feature has a minimal reproducer provided information-requested Bug is waiting on additional information from the user triage
Projects
None yet
Development

No branches or pull requests

10 participants