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'. #5090

Closed
mirkobertone opened this issue Oct 25, 2024 · 3 comments
Labels
bug Something isn't working needs:author-response waiting for author to respond needs:reproducer This bug/feature is in need of a minimal reproducer pkg:sdk-metrics pkg:sdk-node triage

Comments

@mirkobertone
Copy link

What happened?

Steps to Reproduce

I followed the tutorial at this page
https://opentelemetry.io/docs/languages/js/getting-started/nodejs/ in order to setup the metrics part.
I have this typescript error at metricReader

metricReader: new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter(),
}),

Type 'PeriodicExportingMetricReader' is not assignable to type 'MetricReader'.
Types have separate declarations of a private property '_shutdown'.ts(2322)
types.d.ts(15, 5): The expected type comes from property 'metricReader' which is declared here on type 'Partial'

OpenTelemetry Setup Code

import { logs, NodeSDK } from '@opentelemetry/sdk-node';
// import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPTraceExporter as OTLPHTTPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import 'dotenv/config';

import { Resource } from '@opentelemetry/resources';
import {
  ATTR_SERVICE_NAME,
  ATTR_SERVICE_VERSION,
  SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,
  SEMRESATTRS_SERVICE_NAME,
  SEMRESATTRS_SERVICE_NAMESPACE,
  SEMRESATTRS_SERVICE_VERSION,
} from '@opentelemetry/semantic-conventions';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
import {
  PeriodicExportingMetricReader,
  ConsoleMetricExporter,
} from '@opentelemetry/sdk-metrics';

// const spanProcessors = [
//   // new SimpleSpanProcessor(new ConsoleSpanExporter()),
//   new BatchSpanProcessor(
//     new OTLPTraceExporter({
//       url: 'http://localhost:4318/v1/traces',
//     }),
//   ),
// ];

const resource = new Resource({
  [ATTR_SERVICE_NAME]: process.env.npm_package_name || 'unknown_service',
  [ATTR_SERVICE_VERSION]: process.env.npm_package_version || '0.0.0',
  [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: process.env.NODE_ENV || 'development',
  [SEMRESATTRS_SERVICE_NAMESPACE]: 'xcally',
});

const SeverityLookup = {
  10: 'TRACE',
  20: 'DEBUG',
  30: 'INFO',
  40: 'WARN',
  50: 'ERROR',
  60: 'FATAL',
};
const sdk = new NodeSDK({
  metricReader:  new PeriodicExportingMetricReader({
    exporter: new ConsoleMetricExporter(),
  }),
  resource: resource,
  // spanProcessors,
  traceExporter: new OTLPHTTPTraceExporter({
    url: (process.env.OTLP_HTTP_URL || 'http://localhost:4318/') + 'v1/traces',
    // // optional - default url is http://localhost:4318/v1/traces  HTTP
    // // optional - default url is http://localhost:4317/v1/traces   GRPC
    // url: 'http://localhost:4318/v1/traces',
    // // optional - collection of custom headers to be sent with each request, empty by default
    // headers: {},
  }),
  // logRecordProcessors: [new logs.SimpleLogRecordProcessor(new logs.ConsoleLogRecordExporter())],
  instrumentations: [
    new PinoInstrumentation({
      logHook: (span, record, level) => {
        record['severity'] = `${SeverityLookup[level]}`;
      },
    }),
    getNodeAutoInstrumentations({
      '@opentelemetry/instrumentation-fs': { enabled: false },
      '@opentelemetry/instrumentation-express': { enabled: false },
      '@opentelemetry/instrumentation-net': { enabled: false },
      '@opentelemetry/instrumentation-dns': { enabled: false },
    }),
  ],
});

process.on('SIGTERM', () => {
  sdk
    .shutdown()
    .then(
      () => console.log('SDK shut down successfully'),
      err => console.log('Error shutting down SDK', err),
    )
    .finally(() => process.exit(0));
});

export default sdk;

package.json

{
  "name": "grpc-nest-api-gateway",
  "version": "0.0.5",
  "private": true,
  "description": "",
  "license": "UNLICENSED",
  "author": "",
  "scripts": {[...]},
  "dependencies": {
    "@grpc/grpc-js": "^1.10.6",
    "@grpc/proto-loader": "^0.7.12",
    "@nestjs/axios": "^3.0.2",
    "@nestjs/cli": "^10.3.2",
    "@nestjs/common": "^10.3.7",
    "@nestjs/config": "^3.2.2",
    "@nestjs/core": "^10.3.7",
    "@nestjs/microservices": "^10.3.7",
    "@nestjs/platform-express": "^10.3.7",
    "@nestjs/swagger": "^7.3.1",
    "@nestjs/terminus": "^10.2.3",
    "@opentelemetry/api": "^1.9.0",
    "@opentelemetry/auto-instrumentations-node": "^0.51.0",
    "@opentelemetry/exporter-trace-otlp-http": "^0.53.0",
    "@opentelemetry/instrumentation-pino": "^0.41.0",
    "@opentelemetry/resources": "^1.26.0",
    "@opentelemetry/sdk-metrics": "^1.27.0",
    "@opentelemetry/sdk-node": "^0.54.0",
    "@opentelemetry/semantic-conventions": "^1.27.0",
    "axios": "^1.6.8",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.1",
    "dotenv": "^16.4.5",
    "nestjs-paginate": "^8.6.2",
    "protobufjs": "^7.2.6",
    "reflect-metadata": "^0.2.2",
    "rxjs": "^7.8.1",
  },
  "devDependencies": {
    "@automock/adapters.nestjs": "^2.1.0",
    "@automock/jest": "^2.1.0",
    "@commitlint/cli": "^19.2.2",
    "@compodoc/compodoc": "^1.1.23",
    "@golevelup/ts-jest": "^0.5.0",
    "@nestjs/schematics": "^10.1.1",
    "@nestjs/testing": "^10.3.7",
    "@nestjs/typeorm": "^10.0.2",
    "@types/express": "^4.17.21",
    "@types/jest": "^29.5.12",
    "@types/node": "^20.12.7",
    "@types/supertest": "^6.0.2",
    "@typescript-eslint/eslint-plugin": "^7.6.0",
    "@typescript-eslint/parser": "^7.6.0",
    "commitizen": "^4.3.0",
    "eslint": "^8.56.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-prettier": "^5.1.3",
    "husky": "^9.0.11",
    "javascript-obfuscator": "^4.1.0",
    "jest": "^29.7.0",
    "lint-staged": "^15.2.2",
    "mysql2": "^3.9.7",
    "nodemon": "^3.1.0",
    "prettier": "^3.2.5",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.4",
    "ts-jest": "^29.1.2",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.2",
    "ts-proto": "^1.172.0",
    "tsconfig-paths": "^4.2.0",
    "typeorm": "^0.3.20",
    "typescript": "^5.4.5"
  },
  "engines": {
    "node": ">=22"
  }
}

Relevant log output

No response

@mirkobertone mirkobertone added bug Something isn't working triage labels Oct 25, 2024
@pichlermarc
Copy link
Member

pichlermarc commented Oct 25, 2024

Hi @mirkobertone, thanks for reaching out.

I just tested this with the code that was provided but I was not able to reproduce.
Would you mind trying to update all @opentelemetry/* packages to the latest versions and trying again?

@dyladan dyladan added needs:reproducer This bug/feature is in need of a minimal reproducer needs:author-response waiting for author to respond labels Oct 30, 2024
@r34son
Copy link

r34son commented Nov 3, 2024

Try to update exporter to ^0.54.0. Fixed for me.

@mirkobertone
Copy link
Author

Hi @mirkobertone, thanks for reaching out.

I just tested this with the code that was provided but I was not able to reproduce. Would you mind trying to update all @opentelemetry/* packages to the latest versions and trying again?

It works! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:author-response waiting for author to respond needs:reproducer This bug/feature is in need of a minimal reproducer pkg:sdk-metrics pkg:sdk-node triage
Projects
None yet
Development

No branches or pull requests

4 participants