dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

Can't compile with Nuxt / Node 16.x and dd-trace 2.x

Open gplusdotgr opened this issue 3 years ago • 3 comments



 ERROR  Failed to compile with 27 errors                                                       friendly-errors 16:45:56

These dependencies were not found:                                                             friendly-errors 16:45:56
                                                                                               friendly-errors 16:45:56
* async_hooks in ./node_modules/dd-trace/packages/datadog-core/src/storage/async_resource.js, ./node_modules/dd-trace/packages/datadog-instrumentations/src/helpers/instrument.js and 1 other
* child_process in ./node_modules/@datadog/native-appsec/node_modules/detect-libc/lib/detect-libc.js, ./node_modules/dd-trace/packages/dd-trace/src/plugins/util/exec.js
* dgram in ./node_modules/dd-trace/packages/dd-trace/src/dogstatsd.js                          friendly-errors 16:45:56
* dns in ./node_modules/dd-trace/packages/datadog-instrumentations/src/net.js, ./node_modules/dd-trace/packages/dd-trace/src/dogstatsd.js
* fs in ./node_modules/@datadog/native-appsec/node_modules/detect-libc/lib/detect-libc.js, ./node_modules/@datadog/pprof/node_modules/source-map/lib/read-wasm.js and 10 others
* graphql/language/printer in ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/transforms.js
* graphql/language/visitor in ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/transforms.js
* graphql/utilities in ./node_modules/dd-trace/packages/datadog-plugin-graphql/src/tools/transforms.js
* module in ./node_modules/dd-trace/packages/dd-trace/src/ritm.js                              friendly-errors 16:45:56
* net in ./node_modules/dd-trace/packages/dd-trace/src/dogstatsd.js                            friendly-errors 16:45:56
* v8 in ./node_modules/dd-trace/packages/dd-trace/src/metrics.js                               friendly-errors 16:45:56
* ~/locales in ./plugins/i18n.js                                                               friendly-errors 16:45:56
                                                                                               friendly-errors 16:45:56
To install them, you can run: npm install --save async_hooks child_process dgram dns fs graphql/language/printer graphql/language/visitor graphql/utilities module net v8 ~/locales

Environment

  • Operation system:
  • mac 12.4 (21F79)
  • Node.js version:
  • 16.15.0
  • Tracer version:
  • Agent version:
  • Relevant library versions: "dd-trace": "^2.11.0",

initialisation script: ( used to work fine for dd-trace 0.x.x )

const tracer = require('dd-trace')

export default function Datadog() {
  tracer.init({
    hostname: process.env.DD_AGENT_HOST,
    service: 'purchaser/index-pages',
    env: process.env.STAGE,
    logInjection: true,
  })
}
const tracer = require('dd-trace')
const formats = require('dd-trace/ext/formats')

export default (_, inject) => {
  function logger(level, payload, message) {
    const span = tracer.scope().active()
    const time = new Date().toISOString()
    const record = { time, level, ...payload, message }

    if (span) {
      tracer.inject(span.context(), formats.LOG, record)
    }

    console.log(record)
  }

  inject('logger', logger)
}

gplusdotgr avatar Jul 19 '22 13:07 gplusdotgr

There are a lot of Node built-in modules that are not available, which shouldn't be possible in Node. Is this a browser build? If that's the case, browsers are not supported by this library and the browser SDK should be used instead in those environments.

rochdev avatar Jul 19 '22 14:07 rochdev

it's an SSR server/client framework (Nuxt) but I assume I'll need to restrict this to server-side? (weird, we didn't explicitly needed to do this for the older dd-trace versions)

gplusdotgr avatar Jul 19 '22 14:07 gplusdotgr

Yes, it should be restricted to the server. Some versions used to "run" in the browser in the sense that it would transpile and not necessarily error, but they would not be generating traces. Some very old versions used to also support the browser explicitly but that support has been replaced by the browser SDK since RUM is better suited for browser observability.

rochdev avatar Jul 19 '22 14:07 rochdev

It looks like this issue was wrapped up. If I'm misunderstanding feel free to reopen and tag us.

tlhunter avatar Dec 18 '23 20:12 tlhunter