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

Broken auto-instrumentation dependencies #1031

Closed
DavidPessoa opened this issue May 23, 2022 · 11 comments
Closed

Broken auto-instrumentation dependencies #1031

DavidPessoa opened this issue May 23, 2022 · 11 comments
Labels
bug Something isn't working stale

Comments

@DavidPessoa
Copy link

What version of OpenTelemetry are you using?

0.28.0

What version of Node are you using?

v18.0.0

What did you do?

Ran a npm run build && APP_ENV=tests node_modules/.bin/mocha --recursive --exit dist/test/**/*.spec.js

What did you expect to see?

What did you see instead?

Additional context

@DavidPessoa DavidPessoa added the bug Something isn't working label May 23, 2022
@dyladan
Copy link
Member

dyladan commented May 23, 2022

Can you please provide additional context? Your package.json would be very helpful, but if that can't be provided at least all @opentelemetry/* dependency versions listed would be a great start. The full error output from NPM and/or tsc would also be helpful.

@DavidPessoa
Copy link
Author

DavidPessoa commented May 23, 2022

My package.json

{
  "name": "api-gateway",
  "version": "0.2.0",
  "description": "NodeJS API Gateway Service for K8s",
  "scripts": {
    "test": "npm run build && APP_ENV=tests node_modules/.bin/mocha --recursive --exit dist/test/**/*.spec.js",
    "dev": "APP_ENV=local_dev ts-node-dev --respawn --transpileOnly src/app.ts",
    "prod": "node --require='./src/tracing.ts' --max-http-header-size=64000 dist/app",
    "build": "npm run clean && tsc --skipLibCheck",
    "clean": "rm -Rf ./dist",
    "cover": "npm run build && APP_ENV=tests nyc --all mocha --recursive --exit dist/test/**/*.spec.js",
    "cover_report": "nyc report --reporter=lcov"
  },
  "main": "dist/app.js",
  "license": "UNLICENSED",
  "repository": {
    "type": "git",
    "url": ""
  },
  "private": true,
  "nyc": {
    "check-coverage": true,
    "per-file": true,
    "lines": 75,
    "include": [
      "dist/**/*.js"
    ],
    "exclude": [
      "dist/test/**",
      "dist/config/overrides.*.js",
      "**/node_modules/**",
      "**/*{.,-}{test,spec}.ts"
    ],
    "require": [
      "ts-node/register"
    ],
    "reporter": [
      "text-summary",
      "html"
    ],
    "sourceMap": true,
    "instrument": true,
    "exclude-after-remap": false
  },
  "dependencies": {
    "@kubernetes/client-node": "^0.16.3",
    "@opentelemetry/api": "^1.0.4",
    "@opentelemetry/auto-instrumentations-node": "^0.27.4",
    "@opentelemetry/exporter-trace-otlp-grpc": "^0.27.0",
    "@opentelemetry/instrumentation-aws-sdk": "^0.6.0",
    "@opentelemetry/instrumentation-express": "^0.28.0",
    "@opentelemetry/instrumentation-http": "^0.28.0",
    "@opentelemetry/instrumentation-ioredis": "^0.28.0",
    "@opentelemetry/instrumentation-redis": "^0.29.0",
    "@opentelemetry/sdk-node": "^0.27.0",
    "@opentelemetry/sdk-trace-base": "^1.2.0",
    "@sentry/node": "^6.19.2",
    "@sentry/tracing": "^6.19.2",
    "async": "^3.2.3",
    "bunyan": "^1.8.15",
    "bunyan-prettystream": "^0.1.3",
    "cookie-parser": "^1.4.6",
    "express": "^4.17.3",
    "express-http-context": "^1.2.4",
    "ioredis": "^4.28.5",
    "jsonwebtoken": "^8.5.1",
    "lodash": "^4.17.21",
    "newrelic": "^8.9.1",
    "node-cache": "^5.1.2",
    "node-microsvc-lib": "^2.1.1",
    "opentelemetry-instrumentation-socket.io": "^0.27.1",
    "prom-client": "^11.5.3",
    "redis": "^3.1.2",
    "socket.io": "^2.4.1",
    "socket.io-redis": "^5.2.0",
    "tslib": "^2.3.1",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@istanbuljs/nyc-config-typescript": "^0.1.3",
    "@types/async": "^2.4.1",
    "@types/chai": "^4.1.7",
    "@types/cookie-parser": "^1.4.1",
    "@types/express": "^4.16.1",
    "@types/ioredis": "^4.0.10",
    "@types/jsonwebtoken": "^8.3.2",
    "@types/lodash": "^4.14.138",
    "@types/mocha": "^5.2.7",
    "@types/nock": "^10.0.3",
    "@types/redis": "^2.8.12",
    "@types/socket.io": "^2.1.2",
    "@types/socket.io-redis": "^1.0.25",
    "@types/uuid": "^3.4.4",
    "chai": "^4.2.0",
    "coveralls": "^3.0.3",
    "istanbul": "^0.4.5",
    "mocha": "^6.1.4",
    "nock": "^10.0.6",
    "nyc": "^14.1.1",
    "ts-node-dev": "^1.0.0-pre.32",
    "typescript": "^3.5.1"
  }
}

The error message I get:

#11 19.78 node_modules/@types/mongodb/index.d.ts(46,78): error TS7016: Could not find a declaration file for module 'bson'. '/app/node_modules/bson/lib/bson.js' implicitly has an 'any' type.
#11 19.78   Try `npm install @types/bson` if it exists or add a new declaration (.d.ts) file containing `declare module 'bson';`
#11 19.79 node_modules/@types/mongodb/index.d.ts(58,111): error TS7016: Could not find a declaration file for module 'bson'. '/app/node_modules/bson/lib/bson.js' implicitly has an 'any' type.
#11 19.79   Try `npm install @types/bson` if it exists or add a new declaration (.d.ts) file containing `declare module 'bson';`

@dyladan
Copy link
Member

dyladan commented May 23, 2022

Thank you. To get an immediate workaround you should be able to do --skipLibCheck but we can look into a more permanent solution as well.

@dyladan
Copy link
Member

dyladan commented May 23, 2022

I think this can be fixed by adding @types/bson to the dependencies of the mocha instrumentation here: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-mongodb/package.json#L71

@dyladan
Copy link
Member

dyladan commented May 23, 2022

@DavidPessoa can you try adding @types/bson to your package.json to see if the issue is solved? If that solves it I will add it to ours.

@DavidPessoa
Copy link
Author

@dyladan adding @types/bson to the particular node package it works.
When adding to the project level package.json it doesn't work.

Could not find a declaration file for module 'bson'. '/Users/david/Documents/WORK/Git/api-gateway/node_modules/bson/lib/bson.js' implicitly has an 'any' type.
  Try `npm install @types/bson` if it exists or add a new declaration (.d.ts) file containing `declare module 'bson';`

46 import { Binary, Decimal128, Double, Int32, Long, ObjectId, Timestamp } from "bson";

Adding it directly to a node module is not a good option because CI/CD pulls node modules from scratch

@dyladan
Copy link
Member

dyladan commented May 24, 2022

I'm surprised adding to project level package.json doesn't work. are you sure you added it to both package.json and package-lock.json if you are using npm ci? In any case, I'll add it to the instrumentation package.

@dyladan
Copy link
Member

dyladan commented May 24, 2022

I think I discovered the issue. It depends which version of @types/bson is installed and which is pulled in by either mongodb or @types/mongodb because the latest version of @types/bson is simply a stub with no real types in it. mongodb and bson have started shipping their own types directly in the package, but only recently. Depending on which version of mongodb is pulled in, it may depend on a version of bson which doesn't yet ship its own types. There was a PR recently to update the instrumentation to support mongodb v4 which ships its own types and depends on a bson version with its own types. Updating the package.json to reflect that mongodb version should also fix this.

@DavidPessoa
Copy link
Author

Thank you!

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2022

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Aug 1, 2022
@github-actions
Copy link
Contributor

This issue was closed because it has been stale for 14 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
2 participants