diff --git a/packages/collector/test/integration/currencies/databases/redis/test_base.js b/packages/collector/test/integration/currencies/databases/redis/test_base.js index cfd811a511..c84fa6121d 100644 --- a/packages/collector/test/integration/currencies/databases/redis/test_base.js +++ b/packages/collector/test/integration/currencies/databases/redis/test_base.js @@ -21,6 +21,7 @@ const { } = require('@_local/core/test/test_util'); const ProcessControls = require('@_local/collector/test/test_util/ProcessControls'); const globalAgent = require('@_local/collector/test/globalAgent'); +const { AgentStubControls } = require('@_local/collector/test/apps/agentStubControls'); // v3 is considered the legacy version. // - It does not support Redis clustering. @@ -938,9 +939,130 @@ module.exports = function (name, version, isLatest, mode) { } }); + describe('Config precedence', () => { + describe('when both agent config and env var are set, env var takes precedence', () => { + const customAgentControls = new AgentStubControls(); + let controls; + + before(async () => { + await customAgentControls.startAgent({ + ignoreEndpoints: { redis: ['get', 'set'] } + }); + + controls = new ProcessControls({ + agentControls: customAgentControls, + dirname: __dirname, + appName: isLegacyVersion ? 'legacyApp' : 'app', + env: { + LIBRARY_LATEST: isLatest, + LIBRARY_VERSION: version, + LIBRARY_NAME: name, + REDIS_SETUP_TYPE: mode, + INSTANA_IGNORE_ENDPOINTS: 'redis:get;' + } + }); + await controls.startAndWaitForAgentConnection(5000, Date.now() + 1000 * 60 * 5); + }); + + beforeEach(async () => { + await customAgentControls.clearReceivedTraceData(); + }); + + after(async () => { + await customAgentControls.stopAgent(); + await controls.stop(); + }); + + it('should use env var config and ignore only get (not set)', async () => { + await controls + .sendRequest({ + method: 'POST', + path: '/values', + qs: { + key: 'discount', + value: 50 + } + }) + .then(async () => { + return retry(async () => { + const spans = await customAgentControls.getSpans(); + // 1 x http entry span + // 1 x http client span + // 1 x redis set span (set is NOT ignored because env var only ignores 'get') + expect(spans.length).to.equal(3); + + const redisSpans = spans.filter(span => span.n === 'redis'); + expect(redisSpans.length).to.equal(1); + expect(redisSpans[0].data.redis.command).to.equal('set'); + }); + }); + }); + }); + + mochaSuiteFn('disable redis:', function () { + describe('when both agent config and env var are set, env var takes precedence', () => { + const customAgentControls = new AgentStubControls(); + let controls; + + before(async () => { + await customAgentControls.startAgent({ + disable: { redis: false } + }); + + controls = new ProcessControls({ + agentControls: customAgentControls, + dirname: __dirname, + appName: isLegacyVersion ? 'legacyApp' : 'app', + env: { + LIBRARY_LATEST: isLatest, + LIBRARY_VERSION: version, + LIBRARY_NAME: name, + REDIS_SETUP_TYPE: mode, + INSTANA_TRACING_DISABLE_INSTRUMENTATIONS: 'redis' + } + }); + await controls.startAndWaitForAgentConnection(5000, Date.now() + 1000 * 60 * 5); + }); + + beforeEach(async () => { + await customAgentControls.clearReceivedTraceData(); + }); + + after(async () => { + await customAgentControls.stopAgent(); + await controls.stop(); + }); + + it('should use env var config and disable redis tracing', async () => { + await controls + .sendRequest({ + method: 'POST', + path: '/values', + qs: { + key: 'discount', + value: 50 + } + }) + .then(async () => { + return retry(async () => { + const spans = await customAgentControls.getSpans(); + // 1 x http entry span + // 1 x http client span + // No redis spans because redis is disabled via env var + expect(spans.length).to.equal(2); + + spans.forEach(span => { + expect(span.n).not.to.equal('redis'); + }); + }); + }); + }); + }); + }); + }); + mochaSuiteFn('ignore-endpoints:', function () { describe('when ignore-endpoints is enabled via agent configuration', () => { - const { AgentStubControls } = require('@_local/collector/test/apps/agentStubControls'); const customAgentControls = new AgentStubControls(); let controls; diff --git a/packages/core/test/config/normalizeConfig_test.js b/packages/core/test/config/normalizeConfig_test.js index 987254aa41..32bc26a6d9 100644 --- a/packages/core/test/config/normalizeConfig_test.js +++ b/packages/core/test/config/normalizeConfig_test.js @@ -170,6 +170,7 @@ describe('config.normalizeConfig', () => { expect(config.tracing.enabled).to.be.true; expect(config.tracing.automaticTracingEnabled).to.be.false; }); + it('should not enable automatic tracing when tracing is disabled in general', () => { const config = coreConfig.normalize({ userConfig: { @@ -206,6 +207,12 @@ describe('config.normalizeConfig', () => { expect(config.tracing.enabled).to.be.false; }); + it('should enable tracing if env var conatin non-boolean value', () => { + process.env.INSTANA_TRACING_DISABLE = 'redis'; + const config = coreConfig.normalize({}); + expect(config.tracing.enabled).to.be.true; + }); + it('should use default (true) for automaticTracingEnabled when neither env nor config is set', () => { const config = coreConfig.normalize({}); expect(config.tracing.automaticTracingEnabled).to.be.true;