elastic / elastic/apm-agent-nodejs

Wrong stack trace in typescript with ts-node

Open
#2,009 0 comments 0 reactions 0 assignees View on GitHub
agent-nodejs
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

typescript stack trace is wrong in the report of apm. Also report the same stack two times:

Console stack trace: [image](https://ibb.co/DwVrCQN)
Apm error report [image](https://ibb.co/hLrZFHZ)
Two errors with the same report [image](https://ibb.co/Wp0ddc3)

Current stack trace in logs
```json
{
"@timestamp":"2021-03-18T02:48:05.056Z",
"log.level":"error",
"message":"Cannot read property 'p_id' of undefined",
"ecs":{
"version":"1.6.0"
},
"event":{
"dataset":"payment-service.log"
},
"trace":{
"id":"d7737078f7ad760f45b56020ca2a46f0"
},
"transaction":{
"id":"a4c19c5f8c9ab0a1"
},
"span":{
"id":"f380c2458db911e5"
},
"service":{
"name":"payment-service"
},
"error":{
"message":"Cannot read property 'p_id' of undefined",
"stack_trace":"TypeError: Cannot read property 'p_id' of undefined\n at PaymentService.transformToModel (C:\\Users\\Adri\\projects\\dg\\payment-service\\src\\api\\services\\PaymentService.ts:205:18)\n at PaymentService. (C:\\Users\\Adri\\projects\\dg\\payment-service\\src\\api\\services\\PaymentService.ts:56:29)\n at Generator.next ()\n at fulfilled (C:\\Users\\Adri\\projects\\dg\\payment-service\\node_modules\\tslib\\tslib.js:112:62)"
},
"className":"ErrorMiddleware"
}
```

Apm error report [image](https://ibb.co/hLrZFHZ)

APM stack trace

```json
{
"_index": "apm-7.11.2-error",
"_type": "_doc",
"_id": "9CkCQngB-Cz7CJHPa-Iw",
"_version": 1,
"_score": null,
"_source": {
"parent": {
"id": "8646b76e6196f213"
},
"process": {
"args": [
"C:\\Program Files\\nodejs\\node.exe",
"src/app"
],
"pid": 25044,
"title": " - ts-node-dev src/app",
"ppid": 3852
},
"agent": {
"name": "nodejs",
"version": "3.12.1"
},
"source": {
"ip": "::1"
},
"error": {
"exception": [
{
"stacktrace": [
{
"exclude_from_grouping": false,
"library_frame": false,
"filename": "src\\api\\services\\PaymentService.ts",
"abs_path": "C:\\Users\\Adri\\projects\\dg\\payment-service\\src\\api\\services\\PaymentService.ts",
"line": {
"number": 262,
"context": " } else if (fromRequest && fromRequest.tenant) {"
},
"function": "transformToModel",
"context": {
"pre": [
" uuid: this.dgStorageManager.getAccount().current_device.uuid,",
" ip: this.dgStorageManager.getIpAddress(),",
" country: this.dgStorageManager.getRegion().code,",
" tenant: this.dgStorageManager.getAccount().current_tenant.code,",
" };"
],
"post": [
" userMetadata = fromRequest;",
" this.dgStorageManager.setTenant({",
" id: 1,",
" code: fromRequest.tenant,"
]
}
},
{
"exclude_from_grouping": false,
"library_frame": false,
"filename": "src\\api\\services\\PaymentService.ts",
"abs_path": "C:\\Users\\Adri\\projects\\dg\\payment-service\\src\\api\\services\\PaymentService.ts",
"line": {
"number": 85,
"context": " let insertTransaction = await this.transactionService.createOne(transactionModel);"
},
"function": "PaymentService.",
"context": {
"pre": [
" /**",
" * Insert transaction",
" */",
"",
" this.logger.info('Creating transaction', { meta: { method: this.createOnePayment.name } });"
],
"post": [
"",
" createdResourceResponse.id = insertTransaction.id;",
" transactionModel.id = insertTransaction.id;",
""
]
}
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "",
"line": {
"number": 0
},
"function": "next"
},
{
"library_frame": true,
"exclude_from_grouping": false,
"filename": "node_modules\\tslib\\tslib.js",
"abs_path": "C:\\Users\\Adri\\projects\\dg\\payment-service\\node_modules\\tslib\\tslib.js",
"line": {
"number": 112,
"context": " function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }"
},
"function": "fulfilled",
"context": {
"pre": [
" };",
"",
" __awaiter = function (thisArg, _arguments, P, generator) {",
" function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }",
" return new (P || (P = Promise))(function (resolve, reject) {"
],
"post": [
" function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }",
" function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }",
" step((generator = generator.apply(thisArg, _arguments || [])).next());",
" });"
]
}
}
],
"handled": true,
"message": "Cannot read property 'p_id' of undefined",
"type": "TypeError"
}
],
"culprit": "transformToModel (src\\api\\services\\PaymentService.ts)",
"id": "a15ff8fd3ba1828fd74ebe89620eaecb",
"grouping_key": "ac087473e8e9ca41e7ec9a3d6b38ab57"
},
"processor": {
"name": "error",
"event": "error"
},
"url": {
"path": "/api/payments/paddle/success",
"original": "/api/payments/paddle/success",
"scheme": "http",
"port": 3001,
"domain": "localhost",
"full": "http://localhost:3001/api/payments/paddle/success"
},
"observer": {
"hostname": "15ab0ed2e015",
"name": "instance-0000000003",
"id": "bf7f90cf-0ccb-40b5-a13b-db732aadd62d",
"ephemeral_id": "bcf2a754-c7f0-4846-b015-6baa83b01d37",
"type": "apm-server",
"version": "7.11.2",
"version_major": 7
},
"trace": {
"id": "39fe77c4770300aae6c605c8e2a054b4"
},
"@timestamp": "2021-03-17T21:05:53.586Z",
"ecs": {
"version": "1.6.0"
},
"service": {
"node": {
"name": "Adri"
},
"environment": "development",
"name": "payment-service",
"runtime": {
"name": "node",
"version": "14.15.4"
},
"language": {
"name": "javascript"
},
"version": "0.0.1"
},
"host": {
"hostname": "Adri",
"os": {
"platform": "win32"
},
"ip": "188.158.133.41",
"name": "Adri",
"architecture": "x64"
},
"client": {
"ip": "::1"
},
"http": {
"request": {
"headers": {
"Origin": [
"http://localhost:3001"
],
"Cookie": [
"Webstorm-e68db379=3138c3ab-f060-47ef-bbef-890b7c3d1c5b; sid=Fe26.2**9080e51515c07c518a8bc6dc15f01993440baf05774d213cb8561d4dc43950cd*-t8j9Ht8GKDKWdD5ptnwDA*ax4JdLvK53ufoPiI6mSTWBP0qqwrByHkuqX9jrvX-Fx2wOcGkJO5SEbl73Wi3t-tBq69fjURNMgAIr8CxyBbMG8JboED7XrYRhEZ2l8_ZC1FHhUS8D7YoQTmkffvB7GkMOgUX3029pDec0QNSkvOjUCsg2O4Xcxxr-MDXUFwAka4Ut5tTkmsoJtHTMEtMgAZ_2WaLwrrCD5bpnucaKxyLmBmNW7_UwlJ_J4-eYFYUe4**01a632f37e3cc56e80695b232995900826f94aa249b2b92a05a71374b49d0a54*WjIf9s0Mf1jdGdaJ_-e-x5WWcr3gufM0Uh1k39wQaYU; mongo-express=s:Bl91-OWD5SJ3W5OP2ToE_0dsXXfROW2J.E3SXLeRord4cEclMcEb+iNUby/qOQFza3I7kw2S8xZE"
],
"Sec-Ch-Ua": [
"\"Google Chrome\";v=\"89\", \"Chromium\";v=\"89\", \";Not A Brand\";v=\"99\""
],
"Accept": [
"*/*"
],
"Connection": [
"keep-alive"
],
"User-Agent": [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"
],
"Sec-Fetch-Site": [
"same-origin"
],
"Sec-Fetch-Dest": [
"empty"
],
"Host": [
"localhost:3001"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
"Sec-Fetch-Mode": [
"cors"
],
"Accept-Language": [
"es-ES,es;q=0.9,en;q=0.8,und;q=0.7"
],
"Content-Length": [
"1455"
],
"Sec-Ch-Ua-Mobile": [
"?0"
],
"Content-Type": [
"application/json"
]
},
"method": "POST",
"socket": {
"encrypted": false,
"remote_address": "::1"
},
"body": {
"original": "{\"alert_id\":\"1731092700\",\"alert_name\":\"payment_succeeded\",\"balance_currency\":\"USD\",\"balance_earnings\":\"31.38\",\"balance_fee\":\"318.97\",\"balance_gross\":\"885.04\",\"balance_tax\":\"602.07\",\"checkout_id\":\"2-1255221f1654564-c256eb8d03\",\"country\":\"GB\",\"coupon\":\"Coupon 0\",\"currency\":\"USD\",\"customer_name\":\"customer_name\",\"earnings\":\"677.4\",\"email\":\"berge.marquis@example.com\",\"event_time\":\"2021-02-18 16:25:10\",\"fee\":\"0.78\",\"ip\":\"189.137.115.130\",\"marketing_consent\":\"1\",\"order_id\":\"8\",\"p_signature\":\"vediY3enoWYBRNhnFGUw1MO8WwrAom1BhER6CxNcdkWIB3U4PrcFUI1OFh295Sw+m7AuhNIyPgVs/KvE1z+Q0pmUlYf5XiOP4VUlt8VbcPhrI4csWjicqbESBC3EjkfTNdEiPiJcjB+zST+a6LO/7Wa3korG8788ixmVvAF/Trxq2AJ5iAMDCxKIArQvcBgp3noLhxdRdzJiBqzgbb2tFfSi+hJFPzde9IcyXSMTCTSWoofQCa40Nh38WjREUTxYXjrc20vgQHVhTbj97oM25+WM3mHnIS6s/YTxvSEe9s0NAmx73UKFhrBcCR8qPn5hPINnagZHO7Th15e/didtF5SEE+fTDHG55W1ve7hhiYR1b8hyKFjwXBLip8dJr+b7rurVR3GL8a7OSKYCK3NyYof84lDBsNltYQ4Draw9BZCJYEcGo0D4xFQs5lGhcDeJ/9TZ+fHngkmK3eMP5ja/1mYDPhJfrifcY4gpCKZTTpGV5WRYlMCSZNyo3HAg2O1+2rLrE2ZNbAQ2x+0WDPew85"
}
},
"response": {
"headers": {
"Keep-Alive": [
"timeout=5"
],
"X-Dns-Prefetch-Control": [
"off"
],
"Access-Control-Allow-Origin": [
"*"
],
"X-Content-Type-Options": [
"nosniff"
],
"Connection": [
"keep-alive"
],
"X-Download-Options": [
"noopen"
],
"X-Permitted-Cross-Domain-Policies": [
"none"
],
"Date": [
"Wed, 17 Mar 2021 21:05:53 GMT"
],
"X-Frame-Options": [
"SAMEORIGIN"
],
"Referrer-Policy": [
"no-referrer"
],
"Strict-Transport-Security": [
"max-age=15552000; includeSubDomains"
],
"Etag": [
"W/\"4b-w7UH8tYSn75ahakBiqT8d4rdJms\""
],
"X-Xss-Protection": [
"0"
],
"Vary": [
"Accept-Encoding"
],
"Content-Length": [
"75"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expect-Ct": [
"max-age=0"
]
},
"status_code": 500,
"finished": true,
"headers_sent": true
},
"version": "1.1"
},
"event": {
"ingested": "2021-03-17T21:05:57.837459920Z"
},
"user_agent": {
"original": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36",
"os": {
"name": "Windows",
"version": "10",
"full": "Windows 10"
},
"name": "Chrome",
"device": {
"name": "Other"
},
"version": "89.0.4389.82"
},
"transaction": {
"id": "05fb652aca7aee6a",
"type": "request",
"sampled": true
},
"timestamp": {
"us": 1616015153586000
}
},
"fields": {
"event.ingested": [
"2021-03-17T21:05:57.837Z"
],
"@timestamp": [
"2021-03-17T21:05:53.586Z"
]
},
"highlight": {
"error.grouping_key": [
"@kibana-highlighted-field@ac087473e8e9ca41e7ec9a3d6b38ab57@/kibana-highlighted-field@"
],
"transaction.id": [
"@kibana-highlighted-field@05fb652aca7aee6a@/kibana-highlighted-field@"
],
"trace.id": [
"@kibana-highlighted-field@39fe77c4770300aae6c605c8e2a054b4@/kibana-highlighted-field@"
],
"service.name": [
"@kibana-highlighted-field@payment-service@/kibana-highlighted-field@"
]
},
"sort": [
1616015153586
]
}

```

Two error with the same report [image](https://ibb.co/Wp0ddc3)

**Environment**

- OS: docker node lts-alpine 14
- Node.js version: 14.15.4
- APM Server version: 7.11.2 (elk cloud service)
- Agent version: 3.12.1

**Configuration**

```typescript
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**

```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"
}
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.