Skip to content

Example repository reproducing the stack trace mangling done by datadog

Notifications You must be signed in to change notification settings

AMN-DATA/eng-datadog-runtime-error

Repository files navigation

Datadog Runtime Error reproduction

This repository contains the reproduction case of recurring issue of dd-trace@^2.27 library wrapping all the erros in Runtime exceptions.

For further details, see the issue reported on dd-trace-js GH repository.

Project structure

There are two minimal sample applications in the apps folder:

  • sample-app-v2.24 - it contains a dockerized AWS Lambda function with installed dd-trace library in version 2.24.0; this example works properly
  • sample-app-v3.20 - it contains a dockerized AWS Lambda function with installed dd-trace library in (the latest at the moment [10.05.2023]) version 3.20.0; this example wraps all the errors in the Runtime.UnhandledPromiseRejection

Both sample apps contain the same code with the only difference being the dd-trace package version.

The sample lambda function only throws the error upon being called.

Steps to reproduce

First build the apps by running:

yarn install
yarn build:all

You can use docker-compose.yml file to build and run both apps:

docker-compose build
docker-compose up

Or build with docker separately:

docker build -f apps/sample-app-v2.24/Dockerfile . -t sample-app-v2.24

And then run:

docker run -p 9224:8080 sample-app-v2.24

v2.24.0

Call the first sample app (runs on local port 9224), which has dd-trace@v2.24.0 installed:

curl -XPOST "http://localhost:9224/2015-03-31/functions/function/invocations" -d '{}'

Correct result:

{
  "errorType": "CustomError",
  "errorMessage": "my error",
  "trace": [
    "CustomError: my error",
    "    at myHanlder (/var/task/sample-handler.js:11:11)",
    "    at /var/task/node_modules/datadog-lambda-js/dist/utils/handler.js:166:25",
    "    at /var/task/node_modules/datadog-lambda-js/dist/index.js:220:70",
    "    at step (/var/task/node_modules/datadog-lambda-js/dist/index.js:44:23)",
    "    at Object.next (/var/task/node_modules/datadog-lambda-js/dist/index.js:25:53)",
    "    at /var/task/node_modules/datadog-lambda-js/dist/index.js:19:71",
    "    at new Promise (<anonymous>)",
    "    at __awaiter (/var/task/node_modules/datadog-lambda-js/dist/index.js:15:12)",
    "    at traceListenerOnWrap (/var/task/node_modules/datadog-lambda-js/dist/index.js:197:36)",
    "    at /var/task/node_modules/dd-trace/packages/dd-trace/src/tracer.js:102:56"
  ]
}

Note that the response has the errorType of CustomError.

v3.20.0

Then make a request to the second sample app (runs on local port 9320), which has dd-trace@v3.20.0 installed:

curl -XPOST "http://localhost:9320/2015-03-31/functions/function/invocations" -d '{}'

⚠️ Mangled result:

{
  "errorType": "Runtime.UnhandledPromiseRejection",
  "errorMessage": "CustomError: my error",
  "trace": [
    "Runtime.UnhandledPromiseRejection: CustomError: my error",
    "    at process.<anonymous> (file:///var/runtime/index.mjs:1189:17)",
    "    at process.emit (node:events:513:28)",
    "    at emit (node:internal/process/promises:140:20)",
    "    at processPromiseRejections (node:internal/process/promises:274:27)",
    "    at processTicksAndRejections (node:internal/process/task_queues:97:32)"
  ]
}

Note that the response has the errorType of Runtime.UnhandledPromiseRejection instead of CustomError.

v3.24.0

curl -XPOST "http://localhost:9324/2015-03-31/functions/function/invocations" -d '{}'

Correct result:

{
  "errorType": "CustomError",
  "errorMessage": "my error",
  "trace": [
    "CustomError: my error",
    "    at myHanlder (/var/task/sample-handler.js:11:11)",
    "    at myHanlder (/var/task/node_modules/dd-trace/packages/dd-trace/src/lambda/handler.js:89:26)",
    "    at /var/task/node_modules/datadog-lambda-js/dist/utils/handler.js:166:25",
    "    at /var/task/node_modules/datadog-lambda-js/dist/index.js:220:70",
    "    at step (/var/task/node_modules/datadog-lambda-js/dist/index.js:44:23)",
    "    at Object.next (/var/task/node_modules/datadog-lambda-js/dist/index.js:25:53)",
    "    at /var/task/node_modules/datadog-lambda-js/dist/index.js:19:71",
    "    at new Promise (<anonymous>)",
    "    at __awaiter (/var/task/node_modules/datadog-lambda-js/dist/index.js:15:12)",
    "    at traceListenerOnWrap (/var/task/node_modules/datadog-lambda-js/dist/index.js:197:36)"
  ]
}

v4.3.0

curl -XPOST "http://localhost:9430/2015-03-31/functions/function/invocations" -d '{}'

Correct result:

{
  "errorType": "CustomError",
  "errorMessage": "my error",
  "trace": [
    "CustomError: my error",
    "    at myHanlder (/var/task/sample-handler.js:11:11)",
    "    at myHanlder (/var/task/node_modules/dd-trace/packages/dd-trace/src/lambda/handler.js:89:26)",
    "    at /var/task/node_modules/datadog-lambda-js/dist/utils/handler.js:166:25",
    "    at /var/task/node_modules/datadog-lambda-js/dist/index.js:220:70",
    "    at step (/var/task/node_modules/datadog-lambda-js/dist/index.js:44:23)",
    "    at Object.next (/var/task/node_modules/datadog-lambda-js/dist/index.js:25:53)",
    "    at /var/task/node_modules/datadog-lambda-js/dist/index.js:19:71",
    "    at new Promise (<anonymous>)",
    "    at __awaiter (/var/task/node_modules/datadog-lambda-js/dist/index.js:15:12)",
    "    at traceListenerOnWrap (/var/task/node_modules/datadog-lambda-js/dist/index.js:197:36)"
  ]
}

About

Example repository reproducing the stack trace mangling done by datadog

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published