-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Updated instrumentation registration to allow for instrumenting …
…of a local file that does not exist within node_modules. You must pass in `absolutePath` with the absolute path to the file that is being instrumented along with the moduleName which in this case is just the file name without the extension (#1974)
- Loading branch information
Showing
5 changed files
with
117 additions
and
7 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
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,8 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
module.exports = () => ({ hello: 'world' }) |
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,64 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const tap = require('tap') | ||
const API = require('../../../api') | ||
const helper = require('../../lib/agent_helper') | ||
const sinon = require('sinon') | ||
const shimmer = require('../../../lib/shimmer') | ||
|
||
tap.test('Agent API - instrumentMessages', (t) => { | ||
t.autoend() | ||
|
||
let agent = null | ||
let api = null | ||
|
||
t.beforeEach(() => { | ||
agent = helper.loadMockedAgent() | ||
api = new API(agent) | ||
|
||
sinon.spy(shimmer, 'registerInstrumentation') | ||
}) | ||
|
||
t.afterEach(() => { | ||
helper.unloadAgent(agent) | ||
agent = null | ||
|
||
shimmer.registerInstrumentation.restore() | ||
}) | ||
|
||
t.test('should register the instrumentation with shimmer', (t) => { | ||
const opts = { | ||
moduleName: 'foobar', | ||
absolutePath: `${__dirname}/foobar`, | ||
onRequire: function () {} | ||
} | ||
api.instrumentMessages(opts) | ||
|
||
t.ok(shimmer.registerInstrumentation.calledOnce) | ||
const args = shimmer.registerInstrumentation.getCall(0).args | ||
const [actualOpts] = args | ||
|
||
t.same(actualOpts, opts) | ||
t.equal(actualOpts.type, 'message') | ||
|
||
t.end() | ||
}) | ||
|
||
t.test('should convert separate args into an options object', (t) => { | ||
function onRequire() {} | ||
function onError() {} | ||
api.instrumentMessages('foobar', onRequire, onError) | ||
|
||
const opts = shimmer.registerInstrumentation.getCall(0).args[0] | ||
t.equal(opts.moduleName, 'foobar') | ||
t.equal(opts.onRequire, onRequire) | ||
t.equal(opts.onError, onError) | ||
|
||
t.end() | ||
}) | ||
}) |