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

Express plugin not working #4037

Open
suhjohn opened this issue Feb 8, 2024 · 1 comment
Open

Express plugin not working #4037

suhjohn opened this issue Feb 8, 2024 · 1 comment

Comments

@suhjohn
Copy link

suhjohn commented Feb 8, 2024

I have an Express 4 app with dd-trace.

tracer.init is happening first thing in the code.

However, when I make an API request, top level request is http component not express, and everything is collapsed under the http method instead of the request path.

Screenshot 2024-02-07 at 5 00 21 PM Screenshot 2024-02-07 at 5 00 46 PM

To override this, tried to add a hook:

tracer.use('http', {
  hooks: {
    request: (span, req, _) => {
      if (span !== undefined) {
        if (req instanceof IncomingMessage) {
          logger.info(
            `[tracer.ts] req instanceof IncomingMessage setting resource.name - Span: ${span} req: ${req.url}`,
          );
        } else if (req instanceof ClientRequest) {
          logger.info(
            `[tracer.ts] req instanceof ClientRequest setting resource.name - Span: ${span} req: ${req.path}`,
          );
        }
      }
      if (req instanceof IncomingMessage) {
        logger.info(
          `[tracer.ts] req instanceof IncomingMessage span is undefined - req: ${req.url}`,
        );
      } else if (req instanceof ClientRequest) {
        logger.info(
          `[tracer.ts] req instanceof ClientRequest span is undefined - req: ${req.path}`,
        );
      }
    },
  },
});

This caused the application to crash with the following issue:

2024-02-08 00:24:32 [server] error: TypeError: Cannot read properties of undefined (reading 'length')

at DatadogSpan.toString (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:100:35)

at Object.request (file:///usr/src/app/server/build/src/config/tracer.js:27:109)

at Object.finishSpan (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/plugins/util/web.js:302:26)

at Object.finishAll (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/plugins/util/web.js:316:9)

at HttpServerPlugin.finish (/usr/src/app/node_modules/dd-trace/packages/datadog-plugin-http/src/server.js:66:9)

at /usr/src/app/node_modules/dd-trace/packages/dd-trace/src/plugins/tracing.js:73:22

at Subscription._handler (/usr/src/app/node_modules/dd-trace/packages/dd-trace/src/plugins/plugin.js:14:9)

at Channel.publish (node:diagnostics_channel:56:9)

at ServerResponse.emit (/usr/src/app/node_modules/dd-trace/packages/datadog-instrumentations/src/http/server.js:40:22)

at onFinish (node:_http_outgoing:1001:10)

Is that the right way to use hooks? How can I override the resource.name to something more sane?

Tried both ddtrace 4.26 and 5.2, and both don't work.

@suhjohn
Copy link
Author

suhjohn commented Feb 8, 2024

#3595

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

2 participants