diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 7829b7118be..42b50f8c225 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -51,6 +51,7 @@ dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors dev,graphql,MIT,Copyright 2015 Facebook Inc. dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors +dev,knex,MIT,Copyright (c) 2013-present Tim Griesser dev,mkdirp,MIT,Copyright 2010 James Halliday dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation dev,multer,MIT,Copyright 2014 Hage Yaapa diff --git a/integration-tests/esbuild/basic-test.js b/integration-tests/esbuild/basic-test.js index faf85fd1dea..20f53708b44 100755 --- a/integration-tests/esbuild/basic-test.js +++ b/integration-tests/esbuild/basic-test.js @@ -11,6 +11,7 @@ const tracer = require('../../').init() // dd-trace const assert = require('assert') const express = require('express') const http = require('http') +require('knex') // has dead code paths for multiple instrumented packages const app = express() const PORT = 31415 diff --git a/integration-tests/esbuild/build.js b/integration-tests/esbuild/build.js index 3f3687b58ff..fa862f279ad 100755 --- a/integration-tests/esbuild/build.js +++ b/integration-tests/esbuild/build.js @@ -9,7 +9,18 @@ esbuild.build({ outfile: 'out.js', plugins: [ddPlugin], platform: 'node', - target: ['node16'] + target: ['node16'], + external: [ + // dead code paths introduced by knex + 'pg', + 'mysql2', + 'better-sqlite3', + 'sqlite3', + 'mysql', + 'oracledb', + 'pg-query-stream', + 'tedious' + ] }).catch((err) => { console.error(err) // eslint-disable-line no-console process.exit(1) diff --git a/integration-tests/esbuild/package.json b/integration-tests/esbuild/package.json index 1e70730cbe8..b25cbebccc5 100644 --- a/integration-tests/esbuild/package.json +++ b/integration-tests/esbuild/package.json @@ -19,6 +19,7 @@ "license": "ISC", "dependencies": { "esbuild": "0.16.12", - "express": "^4.16.2" + "express": "^4.16.2", + "knex": "^2.4.2" } } diff --git a/package.json b/package.json index c64cd55b71f..0c86e121ef4 100644 --- a/package.json +++ b/package.json @@ -120,6 +120,7 @@ "graphql": "0.13.2", "int64-buffer": "^0.1.9", "jszip": "^3.5.0", + "knex": "^2.4.2", "mkdirp": "^0.5.1", "mocha": "8", "msgpack-lite": "^0.1.26", diff --git a/packages/datadog-esbuild/index.js b/packages/datadog-esbuild/index.js index ee4b469ea40..71db959bed6 100644 --- a/packages/datadog-esbuild/index.js +++ b/packages/datadog-esbuild/index.js @@ -39,7 +39,19 @@ module.exports.setup = function (build) { if (args.namespace === 'file' && packagesOfInterest.has(packageName)) { // The file namespace is used when requiring files from disk in userland - const pathToPackageJson = require.resolve(`${packageName}/package.json`, { paths: [ args.resolveDir ] }) + + let pathToPackageJson + try { + pathToPackageJson = require.resolve(`${packageName}/package.json`, { paths: [ args.resolveDir ] }) + } catch (err) { + if (err.code === 'MODULE_NOT_FOUND') { + console.warn(`Unable to open "${packageName}/package.json". Is the "${packageName}" package dead code?`) + return + } else { + throw err + } + } + const pkg = require(pathToPackageJson) if (DEBUG) {