Skip to content

Commit

Permalink
Revert "feat: Provided ability to disable instrumentation for a 3rd p…
Browse files Browse the repository at this point in the history
…arty package (newrelic#2551)"

This reverts commit 7e467b8.
  • Loading branch information
sumitsuthar authored Sep 20, 2024
1 parent 258742f commit af5bcf6
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 341 deletions.
19 changes: 0 additions & 19 deletions lib/config/build-instrumentation-config.js

This file was deleted.

9 changes: 1 addition & 8 deletions lib/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

const defaultConfig = module.exports
const { array, int, float, boolean, object, objectList, allowList, regex } = require('./formatters')
const pkgInstrumentation = require('./build-instrumentation-config')

/**
* A function that returns the definition of the agent configuration
Expand Down Expand Up @@ -1383,13 +1382,7 @@ defaultConfig.definition = () => ({
default: true
}
}
},
/**
* Stanza that contains all keys to disable 3rd party package instrumentation(i.e. mongodb, pg, redis, etc)
* Note: Disabling a given 3rd party library may affect the instrumentation of 3rd party libraries used after
* the disabled library.
*/
instrumentation: pkgInstrumentation
}
})

/**
Expand Down
6 changes: 1 addition & 5 deletions lib/shimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,7 @@ const shimmer = (module.exports = {
*/
registerThirdPartyInstrumentation(agent) {
for (const [moduleName, instrInfo] of Object.entries(INSTRUMENTATIONS)) {
if (agent.config.instrumentation?.[moduleName]?.enabled === false) {
logger.warn(
`Instrumentation for ${moduleName} has been disabled via 'config.instrumentation.${moduleName}.enabled. Not instrumenting package`
)
} else if (instrInfo.module) {
if (instrInfo.module) {
// Because external instrumentations can change independent of
// the agent core, we don't want breakages in them to entirely
// disable the agent.
Expand Down
89 changes: 0 additions & 89 deletions test/lib/custom-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,94 +80,6 @@ function compareSegments(parent, segments) {
})
}

/**
* @param {TraceSegment} parent Parent segment
* @param {Array} expected Array of strings that represent segment names.
* If an item in the array is another array, it
* represents children of the previous item.
* @param {boolean} options.exact If true, then the expected segments must match
* exactly, including their position and children on all
* levels. When false, then only check that each child
* exists.
* @param {array} options.exclude Array of segment names that should be excluded from
* validation. This is useful, for example, when a
* segment may or may not be created by code that is not
* directly under test. Only used when `exact` is true.
*/
function assertSegments(parent, expected, options) {
let child
let childCount = 0

// rather default to what is more likely to fail than have a false test
let exact = true
if (options && options.exact === false) {
exact = options.exact
} else if (options === false) {
exact = false
}

function getChildren(_parent) {
return _parent.children.filter(function (item) {
if (exact && options && options.exclude) {
return options.exclude.indexOf(item.name) === -1
}
return true
})
}

const children = getChildren(parent)
if (exact) {
for (let i = 0; i < expected.length; ++i) {
const sequenceItem = expected[i]

if (typeof sequenceItem === 'string') {
child = children[childCount++]
assert.equal(
child ? child.name : undefined,
sequenceItem,
'segment "' +
parent.name +
'" should have child "' +
sequenceItem +
'" in position ' +
childCount
)

// If the next expected item is not array, then check that the current
// child has no children
if (!Array.isArray(expected[i + 1])) {
assert.ok(
getChildren(child).length === 0,
'segment "' + child.name + '" should not have any children'
)
}
} else if (typeof sequenceItem === 'object') {
assertSegments(child, sequenceItem, options)
}
}

// check if correct number of children was found
assert.equal(children.length, childCount)
} else {
for (let i = 0; i < expected.length; i++) {
const sequenceItem = expected[i]

if (typeof sequenceItem === 'string') {
// find corresponding child in parent
for (let j = 0; j < parent.children.length; j++) {
if (parent.children[j].name === sequenceItem) {
child = parent.children[j]
}
}
assert.ok(child, 'segment "' + parent.name + '" should have child "' + sequenceItem + '"')
if (typeof expected[i + 1] === 'object') {
assertSegments(child, expected[i + 1], exact)
}
}
}
}
}

/**
* Like `tap.prototype.match`. Verifies that `actual` satisfies the shape
* provided by `expected`.
Expand Down Expand Up @@ -235,7 +147,6 @@ function match(actual, expected) {
module.exports = {
assertCLMAttrs,
assertExactClmAttrs,
assertSegments,
compareSegments,
isNonWritable,
match
Expand Down
1 change: 1 addition & 0 deletions test/lib/metrics_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function assertSegments(parent, expected, options) {
// If the next expected item is not array, then check that the current
// child has no children
if (!Array.isArray(expected[i + 1])) {
// var children = child.children
this.ok(
getChildren(child).length === 0,
'segment "' + child.name + '" should not have any children'
Expand Down
20 changes: 0 additions & 20 deletions test/unit/config/build-instrumentation-config.test.js

This file was deleted.

6 changes: 0 additions & 6 deletions test/unit/config/config-defaults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,4 @@ test('with default properties', async (t) => {
assert.equal(configuration.ai_monitoring.enabled, false)
assert.equal(configuration.ai_monitoring.streaming.enabled, true)
})

await t.test('instrumentation defaults', () => {
assert.equal(configuration.instrumentation.express.enabled, true)
assert.equal(configuration.instrumentation['@prisma/client'].enabled, true)
assert.equal(configuration.instrumentation.npmlog.enabled, true)
})
})
14 changes: 0 additions & 14 deletions test/unit/config/config-env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,19 +768,5 @@ test('when overriding configuration values via environment variables', async (t)
end()
})
})

await t.test('should convert NEW_RELIC_INSTRUMENTATION* accordingly', (t, end) => {
const env = {
NEW_RELIC_INSTRUMENTATION_IOREDIS_ENABLED: 'false',
['NEW_RELIC_INSTRUMENTATION_@GRPC/GRPC-JS_ENABLED']: 'false',
NEW_RELIC_INSTRUMENTATION_KNEX_ENABLED: 'false'
}
idempotentEnv(env, (config) => {
assert.equal(config.instrumentation.ioredis.enabled, false)
assert.equal(config.instrumentation['@grpc/grpc-js'].enabled, false)
assert.equal(config.instrumentation.knex.enabled, false)
end()
})
})
}
})
56 changes: 0 additions & 56 deletions test/versioned/disabled-instrumentation/disabled-express.test.js

This file was deleted.

78 changes: 0 additions & 78 deletions test/versioned/disabled-instrumentation/disabled-ioredis.test.js

This file was deleted.

24 changes: 0 additions & 24 deletions test/versioned/disabled-instrumentation/newrelic.js

This file was deleted.

Loading

0 comments on commit af5bcf6

Please sign in to comment.