Skip to content

Commit

Permalink
switch to internal diagnostics channel with node bug patch (#3002)
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev committed Apr 13, 2023
1 parent f72976b commit 1f5dfb7
Show file tree
Hide file tree
Showing 30 changed files with 182 additions and 48 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"plugin:mocha/recommended"
],
"plugins": [
"mocha"
"mocha",
"n"
],
"env": {
"node": true,
Expand All @@ -31,6 +32,7 @@
"mocha/no-identical-title": 0,
"mocha/no-global-tests": 0,
"mocha/no-exports": 0,
"mocha/no-skipped-tests": 0
"mocha/no-skipped-tests": 0,
"n/no-restricted-require": [2, ["diagnostics_channel"]]
}
}
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dev,eslint,MIT,Copyright JS Foundation and other contributors https://js.foundat
dev,eslint-config-standard,MIT,Copyright Feross Aboukhadijeh
dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck
dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima
dev,eslint-plugin-node,MIT,Copyright 2015 Toru Nagashima
dev,eslint-plugin-promise,ISC,jden and other contributors
dev,eslint-plugin-standard,MIT,Copyright 2015 Jamund Ferguson
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"eslint-config-standard": "^11.0.0-beta.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-core/src/storage/async_resource.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { createHook, executionAsyncResource } = require('async_hooks')
const { channel } = require('diagnostics_channel')
const { channel } = require('../../../diagnostics_channel')

const beforeCh = channel('dd-trace:storage:before')
const afterCh = channel('dd-trace:storage:after')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const dc = require('diagnostics_channel')
const dc = require('../../../diagnostics_channel')
const semver = require('semver')
const instrumentations = require('./instrumentations')
const { AsyncResource } = require('async_hooks')
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-instrumentations/src/helpers/register.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { channel } = require('diagnostics_channel')
const { channel } = require('../../../diagnostics_channel')
const path = require('path')
const semver = require('semver')
const Hook = require('./hook')
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-fs/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const semver = require('semver')
const rimraf = require('rimraf')
const util = require('util')
const plugins = require('../../dd-trace/src/plugins')
const { channel } = require('diagnostics_channel')
const { channel } = require('../../diagnostics_channel')

const hasWritev = semver.satisfies(process.versions.node, '>=12.9.0')
const hasOSymlink = realFS.constants.O_SYMLINK
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/appsec/gateway/channels.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const dc = require('diagnostics_channel')
const dc = require('../../../../diagnostics_channel')

// TODO: use TBD naming convention
// or directly use http plugin's channels
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/appsec/iast/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { enableAllAnalyzers, disableAllAnalyzers } = require('./analyzers')
const web = require('../../plugins/util/web')
const { storage } = require('../../../../datadog-core')
const overheadController = require('./overhead-controller')
const dc = require('diagnostics_channel')
const dc = require('../../../../diagnostics_channel')
const iastContextFunctions = require('./iast-context')
const { enableTaintTracking, disableTaintTracking, createTransaction, removeTransaction } = require('./taint-tracking')

Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/appsec/iast/telemetry/logs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const dc = require('diagnostics_channel')
const dc = require('../../../../../diagnostics_channel')
const logCollector = require('./log_collector')
const { sendData } = require('../../../telemetry/send-data')
const log = require('../../../log')
Expand Down
2 changes: 2 additions & 0 deletions packages/dd-trace/src/dcitm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

// TODO: Figure out why we can't use the internal version.
// eslint-disable-next-line n/no-restricted-require
const dc = require('diagnostics_channel')

const CHANNEL_PREFIX = 'dd-trace:bundledModuleLoadStart'
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/iitm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const semver = require('semver')
const logger = require('./log')
const { addHook } = require('import-in-the-middle')
const dc = require('diagnostics_channel')
const dc = require('../../diagnostics_channel')

if (semver.satisfies(process.versions.node, '>=14.13.1')) {
const moduleLoadStartChannel = dc.channel('dd-trace:moduleLoadStart')
Expand Down
23 changes: 11 additions & 12 deletions packages/dd-trace/src/log/channels.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const dc = require('diagnostics_channel')
const { channel } = require('../../../diagnostics_channel')

const Level = {
Debug: 'debug',
Expand All @@ -11,19 +11,18 @@ const Level = {

const defaultLevel = Level.Debug

class LogChannel extends dc.Channel {
constructor (name, logLevel) {
super(`datadog:log:${name}`)
this.logLevel = logLevel
}
}

// based on: https://github.com/trentm/node-bunyan#levels
const logChannels = {
[Level.Debug]: new LogChannel(Level.Debug, 20),
[Level.Info]: new LogChannel(Level.Info, 30),
[Level.Warn]: new LogChannel(Level.Warn, 40),
[Level.Error]: new LogChannel(Level.Error, 50)
[Level.Debug]: createLogChannel(Level.Debug, 20),
[Level.Info]: createLogChannel(Level.Info, 30),
[Level.Warn]: createLogChannel(Level.Warn, 40),
[Level.Error]: createLogChannel(Level.Error, 50)
}

function createLogChannel (name, logLevel) {
const logChannel = channel(`datadog:log:${name}`)
logChannel.logLevel = logLevel
return logChannel
}

function getChannelLogLevel (level) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/plugin_manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { channel } = require('diagnostics_channel')
const { channel } = require('../../diagnostics_channel')
const { isFalse } = require('./util')
const plugins = require('./plugins')
const log = require('./log')
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/plugins/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// TODO: move anything related to tracing to TracingPlugin instead

const dc = require('diagnostics_channel')
const dc = require('../../../diagnostics_channel')
const { storage } = require('../../../datadog-core')

class Subscription {
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/profiling/profilers/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { storage } = require('../../../../datadog-core')

const dc = require('diagnostics_channel')
const dc = require('../../../../diagnostics_channel')

const beforeCh = dc.channel('dd-trace:storage:before')
const afterCh = dc.channel('dd-trace:storage:after')
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/ritm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const path = require('path')
const Module = require('module')
const parse = require('module-details-from-path')
const dc = require('diagnostics_channel')
const dc = require('../../diagnostics_channel')

const origRequire = Module.prototype.require

Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/telemetry/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
const parse = require('module-details-from-path')
const requirePackageJson = require('../require-package-json')
const { sendData } = require('./send-data')
const dc = require('diagnostics_channel')
const dc = require('../../../diagnostics_channel')
const { fileURLToPath } = require('url')

const savedDependencies = new Set()
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/telemetry/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const tracerVersion = require('../../../../package.json').version
const dc = require('diagnostics_channel')
const dc = require('../../../diagnostics_channel')
const os = require('os')
const dependencies = require('./dependencies')
const { sendData } = require('./send-data')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('vulnerability-analyzer', () => {
expect(vulnerabilityAnalyzer._subscriptions).to.have.lengthOf(1)
vulnerabilityAnalyzer._subscriptions[0].enable()

const dc = require('diagnostics_channel')
const dc = require('../../../../../diagnostics_channel')
expect(() => { dc.channel('dd-trace:test:error:sub').publish({}) }).to.not.throw()
})
})
2 changes: 1 addition & 1 deletion packages/dd-trace/test/appsec/iast/iast-log.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('IAST log', () => {
error: sinon.stub()
}
telemetryLogs = proxyquire('../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': {
'../../../../../diagnostics_channel': {
channel: (name) => name === 'datadog:telemetry:start' ? telemetryStartChannel : telemetryStopChannel
}
})
Expand Down
20 changes: 10 additions & 10 deletions packages/dd-trace/test/appsec/iast/telemetry/logs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('telemetry logs', () => {
describe('start', () => {
it('should be enabled by default and subscribe', () => {
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc
'../../../../../diagnostics_channel': dc
})
logs.start()
defaultConfig.telemetry.logCollection = true
Expand All @@ -61,7 +61,7 @@ describe('telemetry logs', () => {

it('should be disabled and not subscribe if DD_TELEMETRY_LOG_COLLECTION_ENABLED = false', () => {
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc
'../../../../../diagnostics_channel': dc
})
logs.start()

Expand All @@ -76,7 +76,7 @@ describe('telemetry logs', () => {

let logCollectorCalled = 0
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc,
'../../../../../diagnostics_channel': dc,
'../../../telemetry/send-data': { sendData },
'./log_collector': {
drain: () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('telemetry logs', () => {
describe('stop', () => {
it('should unsubscribe configured listeners', () => {
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc
'../../../../../diagnostics_channel': dc
})
logs.start()
onTelemetryStart()(onTelemetryStartMsg)
Expand All @@ -118,7 +118,7 @@ describe('telemetry logs', () => {

it('should unsubscribe configured listeners when datadog:telemetry:stop is received', () => {
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc
'../../../../../diagnostics_channel': dc
})
logs.start()
onTelemetryStart()(onTelemetryStartMsg)
Expand All @@ -137,7 +137,7 @@ describe('telemetry logs', () => {
it('should be called with DEBUG level and error if config.telemetry.debug = true', () => {
const logCollectorAdd = sinon.stub()
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc,
'../../../../../diagnostics_channel': dc,
'./log_collector': {
add: logCollectorAdd
}
Expand All @@ -159,7 +159,7 @@ describe('telemetry logs', () => {
it('should be not called with DEBUG level if config.telemetry.debug = false', () => {
const logCollectorAdd = sinon.stub()
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc,
'../../../../../diagnostics_channel': dc,
'./log_collector': {
add: logCollectorAdd
}
Expand All @@ -175,7 +175,7 @@ describe('telemetry logs', () => {
it('should be called with WARN level', () => {
const logCollectorAdd = sinon.stub()
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc,
'../../../../../diagnostics_channel': dc,
'./log_collector': {
add: logCollectorAdd
}
Expand All @@ -191,7 +191,7 @@ describe('telemetry logs', () => {
it('should be called with ERROR level', () => {
const logCollectorAdd = sinon.stub()
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc,
'../../../../../diagnostics_channel': dc,
'./log_collector': {
add: logCollectorAdd
}
Expand All @@ -207,7 +207,7 @@ describe('telemetry logs', () => {
it('should be called with ERROR level and stack_trace', () => {
const logCollectorAdd = sinon.stub()
const logs = proxyquire('../../../../src/appsec/iast/telemetry/logs', {
'diagnostics_channel': dc,
'../../../../../diagnostics_channel': dc,
'./log_collector': {
add: logCollectorAdd
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/iitm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('./setup/tap')

const { expect } = require('chai')
const semver = require('semver')
const dc = require('diagnostics_channel')
const dc = require('../../diagnostics_channel')

describe('iitm.js', () => {
let hookFn
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/plugin_manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require('./setup/tap')

const { channel } = require('diagnostics_channel')
const { channel } = require('../../diagnostics_channel')
const proxyquire = require('proxyquire')

const loadChannel = channel('dd-trace:instrumentation:load')
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/plugins/log_plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const LogPlugin = require('../../src/plugins/log_plugin')
const Tracer = require('../../src/tracer')
const Config = require('../../src/config')

const { channel } = require('diagnostics_channel')
const { channel } = require('../../../diagnostics_channel')
const { expect } = require('chai')

const testLogChannel = channel('apm:test:log')
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/ritm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require('./setup/tap')

const dc = require('diagnostics_channel')
const dc = require('../../diagnostics_channel')
const { assert } = require('chai')
const Hook = require('../src/ritm')

Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/test/telemetry/dependencies.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('../setup/tap')

const proxyquire = require('proxyquire')
const path = require('path')
const dc = require('diagnostics_channel')
const dc = require('../../../diagnostics_channel')
const moduleLoadStartChannel = dc.channel('dd-trace:moduleLoadStart')
const originalSetImmediate = global.setImmediate
describe('dependencies', () => {
Expand All @@ -13,7 +13,7 @@ describe('dependencies', () => {
const subscribe = sinon.stub()
const dc = { channel () { return { subscribe } } }
const dependencies = proxyquire('../../src/telemetry/dependencies', {
'diagnostics_channel': dc
'../../../diagnostics_channel': dc
})
dependencies.start()
expect(subscribe).to.have.been.calledOnce
Expand Down
3 changes: 3 additions & 0 deletions packages/diagnostics_channel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

module.exports = require('./src')
Loading

0 comments on commit 1f5dfb7

Please sign in to comment.