Skip to content

Commit

Permalink
telemetry for guardrails
Browse files Browse the repository at this point in the history
  • Loading branch information
bengl committed Jun 3, 2024
1 parent 7a88c4f commit aefbd02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'}`])
}
11 changes: 11 additions & 0 deletions packages/datadog-instrumentations/src/helpers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}`
])
}
}
}
Expand Down

0 comments on commit aefbd02

Please sign in to comment.