elastic / apm-agent-nodejs

https://www.elastic.co/guide/en/apm/agent/nodejs/current/index.html
BSD 2-Clause "Simplified" License
581 stars 224 forks source link

Mysql spawn metric lost in bluebird wrapper #2006

Closed exejutable closed 3 years ago

exejutable commented 3 years ago

Im using node-promise-mysql is a bluebird wrapper of mysql.

Question

Why i dont see the span of mysql? check the kibana apm image

  1. Is for the wrapper?
  2. This is the expected behaviour?
  3. Any suggested workaround?

Environment

Configuration

import agent from 'elastic-apm-node';

export const apm = agent.start({
  secretToken: '*********',
  serverUrl: '******',
  environment: 'production',
  captureBody: 'all',
  active: true,
  logLevel: 'info',
  sourceLinesErrorAppFrames: 10,
  sourceLinesErrorLibraryFrames: 10,
  transactionIgnoreUrls: [
    '/alive',
  ],
  ignoreUrls: [
    '/alive',
  ],
});

PACKAGE.JSON

{
  "name": "payment-service",
  "version": "0.0.1",
  "description": "Payment DG Service",
  "main": "src/app.ts",
  "author": "Adrian Gutierrez",
  "license": "MIT",
  "dependencies": {
    "@dg/rest-common": "^0.0.1",
    "@dg/sso-http-client": "^0.0.1",
    "@elastic/ecs-winston-format": "^1.0.0",
    "@elastic/elasticsearch": "^7.11.0",
    "axios": "^0.21.1",
    "body-parser": "^1.19.0",
    "class-transformer": "0.3.1",
    "class-validator": "0.12.2",
    "class-validator-jsonschema": "2.2.0",
    "cls-rtracer": "^2.5.1",
    "compression": "^1.7.4",
    "config": "^3.3.3",
    "cors": "^2.8.5",
    "cron": "^1.8.2",
    "elastic-apm-node": "^3.12.1",
    "express": "^4.17.1",
    "googleapis": "^67.1.0",
    "helmet": "^4.2.0",
    "i18n": "^0.13.2",
    "iap": "^1.1.1",
    "import-fresh": "^3.2.2",
    "in-app-purchase": "^1.11.4",
    "jsonwebtoken": "^8.5.1",
    "moment": "^2.29.1",
    "multer": "^1.4.2",
    "mysql": "^2.18.1",
    "mysql8.0": "^1.1.2",
    "node-apple-receipt-verify": "^1.9.3",
    "php-serialize": "^4.0.2",
    "promise-mysql": "^5.0.0",
    "reflect-metadata": "^0.1.13",
    "routing-controllers": "0.9.0-alpha.6",
    "routing-controllers-openapi": "2.2.0",
    "ts-node": "^9.0.0",
    "typedi": "^0.8.0",
    "typescript": "^4.1.2",
    "winston": "^3.3.3",
    "winston-elasticsearch": "^0.12.2",
    "winston3-logstash-transport": "^1.0.1-c"
  },
  "devDependencies": {
    "@types/body-parser": "^1.19.0",
    "@types/compression": "^1.7.0",
    "@types/config": "^0.0.37",
    "@types/express": "^4.17.9",
    "@types/i18n": "^0.12.0",
    "@types/jest": "^26.0.16",
    "@types/jsonwebtoken": "^8.5.0",
    "@types/multer": "^1.4.4",
    "@types/mysql": "^2.15.16",
    "@types/supertest": "^2.0.10",
    "@typescript-eslint/eslint-plugin": "^4.14.0",
    "@typescript-eslint/parser": "^4.14.0",
    "eslint": "^7.18.0",
    "eslint-config-airbnb-base": "^14.2.1",
    "eslint-plugin-import": "^2.22.1",
    "jest": "^26.6.3",
    "supertest": "^6.0.1",
    "ts-jest": "^26.4.4",
    "ts-node-dev": "^1.0.0"
  }
}
astorm commented 3 years ago

Thanks for reporting @exejutable -- if your MySQL query happened during a transaction it should be reported. If it wasn't there's myriad reasons why not.

The first culprit might be the promise-mysql library. While we instrument bluebird and mysql both, we don't explicitly instrument promise-mysql. If promise-mysql is doing something we didn't anticipate with our BlueBird instrumentation that may result in a span generated outside of a transaction, which means it won't be reported. When possible, we recommend folks move over to Node.js native promises -- our native promises instrumentation tends to be more stable than instrumentation of third party promise libraries.

All that said -- there's lots of other reasons a span might be missing. The next best step for us would be a reproduction of the issue. If you had example code that demonstrates the problem that usually lets us zero in on why something might be missing. Do you think that's something you'd be able to provide?

exejutable commented 3 years ago

Y check this in a playground it was an import order problem

  1. only mysql | ok
  2. only mysql2 | ok
  3. mysql + bluebird | ok
  4. mysql2 +bluebird | ok
  5. promise-mysql | ok

thanks for the answer!