diff --git a/init.js b/init.js index abfa1de8f24..310710d1075 100644 --- a/init.js +++ b/init.js @@ -2,8 +2,11 @@ const path = require('path') const Module = require('module') +const telemetry = require('./packages/dd-trace/src/telemetry/init-telemetry') let initBailout = false +let clobberBailout = false +let forced = ['1', 'true', 'True'].includes(process.env.DD_INJECT_FORCE) if (process.env.DD_INJECTION_ENABLED) { // If we're running via single-step install, and we're not in the app's @@ -19,24 +22,27 @@ if (process.env.DD_INJECTION_ENABLED) { if (resolvedInApp) { const ourselves = path.join(__dirname, 'index.js') if (ourselves !== resolvedInApp) { - initBailout = true + clobberBailout = true } } // If we're running via single-step install, and the runtime doesn't match // the engines field in package.json, then we should not initialize the tracer. - if (!initBailout) { + if (!clobberBailout) { const { engines } = require('./package.json') const version = process.versions.node const semver = require('semver') if (!semver.satisfies(version, engines.node)) { initBailout = true + telemetry('abort', ['reason:incompatible_runtime']) + telemetry('abort.runtime') } } } -if (!initBailout) { +if (!clobberBailout && (!initBailout || forced)) { const tracer = require('.') tracer.init() module.exports = tracer + telemetry('complete', [`injection_forced:${forced && initBailout ? 'true' : 'false'}`]) } diff --git a/packages/datadog-instrumentations/src/helpers/register.js b/packages/datadog-instrumentations/src/helpers/register.js index 9fc22ca45f1..93ae2c1e599 100644 --- a/packages/datadog-instrumentations/src/helpers/register.js +++ b/packages/datadog-instrumentations/src/helpers/register.js @@ -6,6 +6,7 @@ const semver = require('semver') const Hook = require('./hook') const requirePackageJson = require('../../../dd-trace/src/require-package-json') const log = require('../../../dd-trace/src/log') +const telemetry = require('../../../dd-trace/src/telemetry/init-telemetry') const { DD_TRACE_DISABLED_INSTRUMENTATIONS = '' } = process.env @@ -68,7 +69,17 @@ for (const packageName of names) { hook[HOOK_SYMBOL].set(moduleExports, name) } catch (e) { log.error(e) + telemetry('error', [ + `error_type:${e.constructor.name}`, + `integration:${name}`, + `integration_version:${version}` + ]) } + } else { + telemetry('abort.integration', [ + `integration:${name}`, + `integration_version:${version}` + ]) } } }