-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provided ability to disable instrumentation for a 3rd party pac…
…kage (#2551)
- Loading branch information
Showing
12 changed files
with
341 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const { boolean } = require('./formatters') | ||
const instrumentedLibraries = require('../instrumentations')() | ||
const pkgNames = Object.keys(instrumentedLibraries) | ||
|
||
/** | ||
* Builds the stanza for config.instrumentation.* | ||
* It defaults every library to true and assigns a boolean | ||
* formatter for the environment variable conversion of the values | ||
*/ | ||
module.exports = pkgNames.reduce((config, pkg) => { | ||
config[pkg] = { enabled: { formatter: boolean, default: true } } | ||
return config | ||
}, {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2022 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const test = require('node:test') | ||
const assert = require('node:assert') | ||
|
||
test('should default the instrumentation stanza', () => { | ||
const { boolean } = require('../../../lib/config/formatters') | ||
const pkgs = require('../../../lib/config/build-instrumentation-config') | ||
const instrumentation = require('../../../lib/instrumentations')() | ||
const pkgNames = Object.keys(instrumentation) | ||
|
||
pkgNames.forEach((pkg) => { | ||
assert.deepEqual(pkgs[pkg], { enabled: { formatter: boolean, default: true } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
test/versioned/disabled-instrumentation/disabled-express.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const assert = require('node:assert') | ||
const test = require('node:test') | ||
const helper = require('../../lib/agent_helper') | ||
const http = require('http') | ||
const params = require('../../lib/params') | ||
const { assertSegments } = require('../../lib/custom-assertions') | ||
|
||
test('should still record child segments if express instrumentation is disabled', async (t) => { | ||
const agent = helper.instrumentMockedAgent({ | ||
instrumentation: { | ||
express: { | ||
enabled: false | ||
} | ||
} | ||
}) | ||
const express = require('express') | ||
const app = express() | ||
const Redis = require('ioredis') | ||
const client = new Redis(params.redis_port, params.redis_host) | ||
|
||
app.get('/test-me', (_req, res) => { | ||
client.get('foo', (err) => { | ||
assert.equal(err, undefined) | ||
res.end() | ||
}) | ||
}) | ||
|
||
const promise = new Promise((resolve) => { | ||
agent.on('transactionFinished', (tx) => { | ||
assert.equal(tx.name, 'WebTransaction/NormalizedUri/*', 'should not name transactions') | ||
const rootSegment = tx.trace.root | ||
const expectedSegments = ['WebTransaction/NormalizedUri/*', ['Datastore/operation/Redis/get']] | ||
assertSegments(rootSegment, expectedSegments) | ||
resolve() | ||
}) | ||
}) | ||
|
||
const server = app.listen(() => { | ||
const { port } = server.address() | ||
http.request({ port, path: '/test-me' }).end() | ||
}) | ||
|
||
t.after(() => { | ||
server.close() | ||
client.disconnect() | ||
helper.unloadAgent(agent) | ||
}) | ||
|
||
await promise | ||
}) |
78 changes: 78 additions & 0 deletions
78
test/versioned/disabled-instrumentation/disabled-ioredis.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const assert = require('node:assert') | ||
const test = require('node:test') | ||
const helper = require('../../lib/agent_helper') | ||
const params = require('../../lib/params') | ||
const { assertSegments } = require('../../lib/custom-assertions') | ||
const mongoCommon = require('../mongodb/common') | ||
|
||
test('Disabled PG scenarios', async (t) => { | ||
t.beforeEach(async (ctx) => { | ||
ctx.nr = {} | ||
const agent = helper.instrumentMockedAgent({ | ||
instrumentation: { | ||
ioredis: { | ||
enabled: false | ||
} | ||
} | ||
}) | ||
const Redis = require('ioredis') | ||
const mongodb = require('mongodb') | ||
const mongo = await mongoCommon.connect({ mongodb }) | ||
const collection = mongo.db.collection('disabled-inst-test') | ||
const redisClient = new Redis(params.redis_port, params.redis_host) | ||
await redisClient.select(1) | ||
ctx.nr.redisClient = redisClient | ||
ctx.nr.agent = agent | ||
ctx.nr.collection = collection | ||
ctx.nr.db = mongo.db | ||
ctx.nr.mongoClient = mongo.client | ||
}) | ||
|
||
t.afterEach(async (ctx) => { | ||
const { agent, redisClient, mongoClient, db } = ctx.nr | ||
await mongoCommon.close(mongoClient, db) | ||
redisClient.disconnect() | ||
helper.unloadAgent(agent) | ||
}) | ||
|
||
await t.test('should record child segments if pg is disabled and using promises', async (t) => { | ||
const { agent, redisClient, collection } = t.nr | ||
await helper.runInTransaction(agent, async (tx) => { | ||
await redisClient.get('foo') | ||
await collection.countDocuments() | ||
await redisClient.get('bar') | ||
tx.end() | ||
assertSegments(tx.trace.root, [ | ||
'Datastore/statement/MongoDB/disabled-inst-test/aggregate', | ||
'Datastore/statement/MongoDB/disabled-inst-test/next' | ||
]) | ||
}) | ||
}) | ||
|
||
await t.test('should record child segments if pg is disabled and using callbacks', async (t) => { | ||
const { agent, redisClient, collection } = t.nr | ||
await helper.runInTransaction(agent, async (tx) => { | ||
await new Promise((resolve) => { | ||
redisClient.get('foo', async (err) => { | ||
assert.equal(err, null) | ||
await collection.countDocuments() | ||
redisClient.get('bar', (innerErr) => { | ||
tx.end() | ||
assert.equal(innerErr, null) | ||
assertSegments(tx.trace.root, [ | ||
'Datastore/statement/MongoDB/disabled-inst-test/aggregate', | ||
'Datastore/statement/MongoDB/disabled-inst-test/next' | ||
]) | ||
resolve() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
exports.config = { | ||
app_name: ['My Application'], | ||
license_key: 'license key here', | ||
logging: { | ||
level: 'trace' | ||
}, | ||
utilization: { | ||
detect_aws: false, | ||
detect_pcf: false, | ||
detect_azure: false, | ||
detect_gcp: false, | ||
detect_docker: false | ||
}, | ||
transaction_tracer: { | ||
enabled: true | ||
} | ||
} |
Oops, something went wrong.