-
Notifications
You must be signed in to change notification settings - Fork 424
feat: Provided ability to disable instrumentation for a 3rd party package #2551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.