Dd-trace-js: Request: Add support for Next.js

Created on 4 Mar 2021  路  5Comments  路  Source: DataDog/dd-trace-js

Next.js endpoint tracing would be very useful.

We have found some success using an Next.js custom server with Express and dd-trace, but since Next.js has it's own router to map paths to routes, it does not report the endpoint in Datadog, meaning it's only grouped by method.

community feature-request integrations

Most helpful comment

We're also facing the same issue.

All 5 comments

We are facing the same problem

We are using the following workaround:

ddtrace.init(...)
  .use('express', {
    hooks: {
      request: (span, req, res) => {
        if (!span || !req || !res) {
          return;
        }

        let route;
        if (res.locals.route) {
          route = res.locals.route;
        } else if (req.path.startsWith('/static/')) {
          route = '/static/';
        } else if (req.path.startsWith('/_next/')) {
          route = '/_next/';
        } else {
          route = req.path;
        }

        span.setTag('resource.name', `${req.method} ${route}`);
      },
    },
  });
  ```

and then in `App.getInitialProps`, we have this:

```javascript
// keep track of route, used for sending to Datadog APM
res.locals.route = ctx.pathname;

This would be very useful!

We're also facing the same issue and investigating traces is very confusing due to the resource names only containing the method.

We're also facing the same issue.

@mcuelenaere I've tried your method but for some reason it didn't work for me. Could you tell me please if you are adding ddTraceJs using express-opentracing or something else?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josephsofaer picture josephsofaer  路  5Comments

kumaraksi picture kumaraksi  路  5Comments

lancedikson picture lancedikson  路  6Comments

vecerek picture vecerek  路  3Comments

edrich-xendit picture edrich-xendit  路  3Comments