diff --git a/packages/collector/src/announceCycle/unannounced.js b/packages/collector/src/announceCycle/unannounced.js index b7cd75a1ff..f287eeb115 100644 --- a/packages/collector/src/announceCycle/unannounced.js +++ b/packages/collector/src/announceCycle/unannounced.js @@ -224,11 +224,9 @@ function applySpanBatchingConfiguration(agentResponse) { } /** - * - The agent configuration currently uses a pipe ('|') as a separator for endpoints. - * - This function supports both ('|') and comma (',') to ensure future compatibility. - * - Additionally, it supports the `string[]` format for backward compatibility, - * as this was the previously used standard. The final design decision is not yet completed. - * https://github.ibm.com/instana/requests-for-discussion/pull/84 + * The agent configuration returns the `string[]` format. + * For more information, see the related design discussion: + * https://github.ibm.com/instana/requests-for-discussion/pull/84 * * @param {AgentAnnounceResponse} agentResponse */ @@ -239,9 +237,7 @@ function applyIgnoreEndpointsConfiguration(agentResponse) { const endpointTracingConfig = Object.fromEntries( Object.entries(endpointTracingConfigFromAgent).map(([service, endpoints]) => { let normalizedEndpoints = null; - if (typeof endpoints === 'string') { - normalizedEndpoints = endpoints.split(/[|,]/).map(endpoint => endpoint?.trim()?.toLowerCase()); - } else if (Array.isArray(endpoints)) { + if (Array.isArray(endpoints)) { normalizedEndpoints = endpoints.map(endpoint => endpoint?.toLowerCase()); } diff --git a/packages/collector/test/announceCycle/unannounced_test.js b/packages/collector/test/announceCycle/unannounced_test.js index 1ab1a26158..0392d44c86 100644 --- a/packages/collector/test/announceCycle/unannounced_test.js +++ b/packages/collector/test/announceCycle/unannounced_test.js @@ -217,7 +217,7 @@ describe('unannounced state', () => { prepareAnnounceResponse({ tracing: { 'ignore-endpoints': { - redis: 'get' + redis: ['get'] } } }); @@ -239,7 +239,7 @@ describe('unannounced state', () => { prepareAnnounceResponse({ tracing: { 'ignore-endpoints': { - redis: 'SET|GET' + redis: ['SET', 'GET'] } } }); @@ -261,8 +261,8 @@ describe('unannounced state', () => { prepareAnnounceResponse({ tracing: { 'ignore-endpoints': { - REDIS: 'get|set', - dynamodb: 'query' + REDIS: ['GET', 'SET'], + dynamodb: ['query'] } } }); @@ -281,11 +281,11 @@ describe('unannounced state', () => { }); }); - it('should apply tracing configuration to ignore endpoints when specified using array format', done => { + it('should set ignoreEndpoints to null when the format is invalid', done => { prepareAnnounceResponse({ tracing: { 'ignore-endpoints': { - REDIS: ['get', 'type'], + REDIS: 'get|set', dynamodb: 'query' } } @@ -295,8 +295,8 @@ describe('unannounced state', () => { expect(agentOptsStub.config).to.deep.equal({ tracing: { ignoreEndpoints: { - redis: ['get', 'type'], - dynamodb: ['query'] + redis: null, + dynamodb: null } } }); diff --git a/packages/collector/test/tracing/database/ioredis/test.js b/packages/collector/test/tracing/database/ioredis/test.js index 7e1c303b84..58225cb445 100644 --- a/packages/collector/test/tracing/database/ioredis/test.js +++ b/packages/collector/test/tracing/database/ioredis/test.js @@ -1289,7 +1289,7 @@ function checkConnection(span, setupType) { before(async () => { await customAgentControls.startAgent({ - ignoreEndpoints: { redis: 'get|set' } + ignoreEndpoints: { redis: ['get', 'set'] } }); controls = new ProcessControls({ @@ -1344,7 +1344,7 @@ function checkConnection(span, setupType) { useGlobalAgent: true, dirname: __dirname, env: { - INSTANA_IGNORE_ENDPOINTS: '{"redis": ["get"]}' + INSTANA_IGNORE_ENDPOINTS: 'redis:get' } }); await controls.start(); diff --git a/packages/collector/test/tracing/database/redis/test.js b/packages/collector/test/tracing/database/redis/test.js index 9217d56e6c..f58a9fe4a0 100644 --- a/packages/collector/test/tracing/database/redis/test.js +++ b/packages/collector/test/tracing/database/redis/test.js @@ -859,7 +859,7 @@ const globalAgent = require('../../../globalAgent'); let controls; before(async () => { await customAgentControls.startAgent({ - ignoreEndpoints: { redis: 'get|set' } + ignoreEndpoints: { redis: ['get', 'set'] } }); controls = new ProcessControls({ @@ -918,7 +918,7 @@ const globalAgent = require('../../../globalAgent'); env: { REDIS_VERSION: redisVersion, REDIS_PKG: redisPkg, - INSTANA_IGNORE_ENDPOINTS: '{"redis": ["get","set"]}' + INSTANA_IGNORE_ENDPOINTS: 'redis:get,set;' } }); await controls.start(); diff --git a/packages/core/src/util/normalizeConfig.js b/packages/core/src/util/normalizeConfig.js index cad667baec..fa667d765f 100644 --- a/packages/core/src/util/normalizeConfig.js +++ b/packages/core/src/util/normalizeConfig.js @@ -718,10 +718,24 @@ function normalizeIgnoreEndpoints(config) { } }); } else if (process.env.INSTANA_IGNORE_ENDPOINTS) { - // The environment variable name and its format are still under discussion. - // It is currently private and will not be documented or publicly shared. try { - config.tracing.ignoreEndpoints = JSON.parse(process.env.INSTANA_IGNORE_ENDPOINTS); + const ignoreEndpoints = Object.fromEntries( + process.env.INSTANA_IGNORE_ENDPOINTS.split(';') + .map(serviceEntry => { + const [serviceName, endpointList] = (serviceEntry || '').split(':').map(part => part.trim()); + + if (!serviceName || !endpointList) { + logger.warn( + `Invalid entry in INSTANA_IGNORE_ENDPOINTS ${process.env.INSTANA_IGNORE_ENDPOINTS}: "${serviceEntry}". Expected format is e.g. "service:endpoint1,endpoint2".` + ); + return null; + } + + return [serviceName.toLowerCase(), endpointList.split(',').map(endpoint => endpoint.trim().toLowerCase())]; + }) + .filter(Boolean) + ); + config.tracing.ignoreEndpoints = ignoreEndpoints; } catch (error) { logger.warn( `Failed to parse INSTANA_IGNORE_ENDPOINTS: ${process.env.INSTANA_IGNORE_ENDPOINTS}. Error: ${error.message}` diff --git a/packages/core/test/util/normalizeConfig_test.js b/packages/core/test/util/normalizeConfig_test.js index 4b1be86dc4..da3bc46c20 100644 --- a/packages/core/test/util/normalizeConfig_test.js +++ b/packages/core/test/util/normalizeConfig_test.js @@ -477,16 +477,26 @@ describe('util.normalizeConfig', () => { }); it('should apply ignore endpoints if the INSTANA_IGNORE_ENDPOINTS is set and valid', () => { - process.env.INSTANA_IGNORE_ENDPOINTS = '{"redis": ["get", "set"]}'; + process.env.INSTANA_IGNORE_ENDPOINTS = 'redis:get,set;'; const config = normalizeConfig(); expect(config.tracing.ignoreEndpoints).to.deep.equal({ redis: ['get', 'set'] }); }); + it('should correctly parse INSTANA_IGNORE_ENDPOINTS containing multiple services and endpoints', () => { + process.env.INSTANA_IGNORE_ENDPOINTS = 'redis:get,set; dynamodb:query'; + const config = normalizeConfig(); + expect(config.tracing.ignoreEndpoints).to.deep.equal({ + redis: ['get', 'set'], + dynamodb: ['query'] + }); + }); + it('should fallback to default if INSTANA_IGNORE_ENDPOINTS is set but has an invalid format', () => { - process.env.INSTANA_IGNORE_ENDPOINTS = '"redis": ["get", "set"]'; + process.env.INSTANA_IGNORE_ENDPOINTS = '"redis=get,set"'; const config = normalizeConfig(); expect(config.tracing.ignoreEndpoints).to.deep.equal({}); }); + it('should apply ignore endpoints via config', () => { const config = normalizeConfig({ tracing: {