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

[BUG]: dd-trace throws error for express v4 when esbuild plugin is used #5056

Open
hoangnd25 opened this issue Dec 23, 2024 · 3 comments
Open

Comments

@hoangnd25
Copy link

hoangnd25 commented Dec 23, 2024

Tracer Version(s)

4.53.0

Node.js Version(s)

22

Bug Report

I got an error when updated dd-trace for lambda:

2024-12-23T22:13:28.217Z	undefined	ERROR	Uncaught Exception 	
{
    "errorType": "TypeError",
    "errorMessage": "hooks[payload.package] is not a function",
    "stack": [
        "TypeError: hooks[payload.package] is not a function",
        "    at /opt/nodejs/node_modules/dd-trace/packages/datadog-instrumentations/src/helpers/bundler-register.js:31:27",
        "    at Channel.publish (node:diagnostics_channel:143:9)",
        "    at ../../node_modules/express/node_modules/qs/lib/index.js (/node_modules/express/node_modules/qs/lib/index.js:26:12)",
        "    at __require3 (file:///var/task/functions/src/lambdas/api.mjs:21:50)",
        "    at <anonymous> (/node_modules/express/lib/middleware/query.js:19:10)",
        "    at ../../node_modules/express/lib/middleware/query.js (/node_modules/express/lib/middleware/query.js:51:7)",
        "    at __require3 (file:///var/task/functions/src/lambdas/api.mjs:21:50)",
        "    at ../../node_modules/express/lib/application.js (/node_modules/express/lib/application.js:20:13)",
        "    at __require3 (file:///var/task/functions/src/lambdas/api.mjs:21:50)",
        "    at ../../node_modules/express/lib/express.js (/node_modules/express/lib/express.js:18:13)"
    ]
}

The code is packaged using esbuild plugin.
The issue seems be missing qs hook when its trying to register instrument for express v4.

It looks like qs hook as removed as part of this change to support express v5

#4913

Packaged code generated by esbuild plugin


// node_modules/qs/lib/index.js
var require_lib5 = __commonJS({
  "node_modules/qs/lib/index.js"(exports2, module2) {
    (function() {
      "use strict";
      var stringify3 = require_stringify3();
      var parse = require_parse3();
      var formats = require_formats4();
      module2.exports = {
        formats,
        parse,
        stringify: stringify3
      };
    })(...arguments);
    {
      const dc = require_dc_polyfill();
      const ch = dc.channel("dd-trace:bundler:load");
      const mod = module2.exports;
      const payload = {
        module: mod,
        version: "6.11.2",
        package: "qs",
        path: "qs"
      };
      ch.publish(payload);
      module2.exports = payload.module;
    }
  }
});

Reproduction Code

No response

Error Logs

No response

Tracer Config

No response

Operating System

No response

Bundling

ESBuild

@hoangnd25 hoangnd25 added the bug Something isn't working label Dec 23, 2024
@hoangnd25 hoangnd25 changed the title [BUG]: [BUG]: dd-trace throws error for express v4 when esbuild plugin is used Dec 23, 2024
@simon-id
Copy link
Member

Thank you for reporting the issue, we're looking into it 👍

@tlhunter
Copy link
Member

(Note to self: Might be related to APMS-14365)

@IlyasShabi
Copy link
Contributor

IlyasShabi commented Dec 24, 2024

Thank you for reporting the issue. I tried to reproduce it but had no success.

  • Is this issue occurring only with Lambda, or with any Express 4/esbuild application ?
  • Could you please share a minimal reproducible application, including package.json, app.js, and the esbuild conf?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants