Skip to content

Commit 14ff618

Browse files
committed
fix: Updated shimmer.setupSubscribers to properly setup and skip subscribers that are disabled (#3275)
1 parent 86db420 commit 14ff618

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

lib/shimmer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ const shimmer = (module.exports = {
395395
'Skipping subscriber %s because it is disabled in the config',
396396
subscriber.id
397397
)
398-
return
398+
continue
399399
}
400400

401401
subscriber.enable()

lib/subscribers/base.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class Subscriber {
1818
this.opaque = false
1919
this.prefix = 'orchestrion:'
2020
this.requireActiveTx = true
21-
this.channel = tracingChannel(`${this.prefix}${this.packageName}:${this.channelName}`)
21+
this.id = `${this.prefix}${this.packageName}:${this.channelName}`
22+
this.channel = tracingChannel(this.id)
2223
this.store = agent.tracer._contextManager._asyncLocalStorage
2324
}
2425

test/unit/shimmer.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,51 @@ test('Shimmer with logger mock', async (t) => {
842842
)
843843
})
844844

845+
test('Shimmer subscriber setup/teardown', async (t) => {
846+
t.beforeEach((ctx) => {
847+
ctx.nr = {}
848+
const sandbox = sinon.createSandbox()
849+
const loggerMock = require('./mocks/logger')(sandbox)
850+
const shimmer = proxyquire('../../lib/shimmer', {
851+
'./logger': {
852+
child: sandbox.stub().callsFake(() => loggerMock)
853+
}
854+
})
855+
const agent = helper.loadMockedAgent({}, true)
856+
agent.config.instrumentation.pino.enabled = false
857+
agent.config.instrumentation.ioredis.enabled = true
858+
ctx.nr = {
859+
agent,
860+
sandbox,
861+
shimmer,
862+
loggerMock
863+
}
864+
})
865+
866+
t.afterEach((ctx) => {
867+
const { agent, sandbox, shimmer } = ctx.nr
868+
sandbox.restore()
869+
clearCachedModules([TEST_MODULE_RELATIVE_PATH])
870+
helper.unloadAgent(agent, shimmer)
871+
})
872+
873+
await t.test('should setup subscribers that are enabled', (t) => {
874+
const { agent, shimmer } = t.nr
875+
assert.ok(!shimmer._subscribers, 'should not have subscribers before setup')
876+
shimmer.setupSubscribers(agent)
877+
assert.ok(!shimmer._subscribers['orchestrion:pino:nr_asJson'])
878+
assert.ok(shimmer._subscribers['orchestrion:ioredis:nr_sendCommand'])
879+
})
880+
881+
await t.test('should teardown subscribers that are enabled', (t) => {
882+
const { agent, shimmer } = t.nr
883+
assert.ok(!shimmer._subscribers, 'should not have subscribers before setup')
884+
shimmer.setupSubscribers(agent)
885+
shimmer.teardownSubscribers()
886+
assert.deepEqual(shimmer._subscribers, {}, 'should not have subscribers after teardown')
887+
})
888+
})
889+
845890
function clearCachedModules(modules) {
846891
modules.forEach((moduleName) => {
847892
try {

0 commit comments

Comments
 (0)