diff --git a/packages/collector/src/agent/opts.js b/packages/collector/src/agent/opts.js index 2b988e5836..25a5ac2c17 100644 --- a/packages/collector/src/agent/opts.js +++ b/packages/collector/src/agent/opts.js @@ -12,6 +12,8 @@ exports.requestTimeout = 5000; exports.host = '127.0.0.1'; // @ts-ignore - Cannot redeclare exported variable exports.port = 42699; +// @ts-ignore - Cannot redeclare exported variable +exports.dataPort = 42699; /** @type {string} */ exports.agentUuid = undefined; // @ts-ignore - Cannot redeclare exported variable @@ -30,6 +32,8 @@ exports.init = function init(config) { exports.host = config.agentHost; // @ts-ignore - Cannot redeclare exported variable exports.port = config.agentPort; + // @ts-ignore - Cannot redeclare exported variable + exports.dataPort = config.agentDataPort; // TODO: Why is autoProfile part of agentOpts? O_o // @ts-ignore - Cannot redeclare exported variable diff --git a/packages/collector/src/agentConnection.js b/packages/collector/src/agentConnection.js index 7ca47d69c5..cceff652c7 100644 --- a/packages/collector/src/agentConnection.js +++ b/packages/collector/src/agentConnection.js @@ -133,6 +133,7 @@ exports.announceNodeCollector = function announceNodeCollector(callback) { logger.debug(`Announcing the Node.js collector to the Instana host agent at ${agentOpts.host}:${agentOpts.port}`); + // Agent announcement uses agentOpts.port (agent connection port) const req = http.request( { host: agentOpts.host, @@ -235,6 +236,8 @@ exports.sendLogToAgent = function sendLogToAgent(logLevel, message, stackTrace) const payload = Buffer.from(JSON.stringify(payloadObject), 'utf8'); + // Log forwarding uses agentOpts.port (agent connection port) for now + // this can be customized if we use OTLP transformation for logs in the future const req = http.request( { host: agentOpts.host, @@ -271,6 +274,7 @@ exports.sendLogToAgent = function sendLogToAgent(logLevel, message, stackTrace) function checkWhetherResponseForPathIsOkay(path, cb) { cb = util.atMostOnce('callback for checkWhetherResponseForPathIsOkay', cb); + // Agent readiness check uses agentOpts.port (agent connection port) const req = http.request( { host: agentOpts.host, @@ -452,10 +456,12 @@ function sendData(path, data, cb, ignore404 = false) { return setImmediate(cb.bind(null, error)); } + // Use dataPort for sending all telemetry data (metrics, spans, profiles, events, etc.) + // dataPort defaults to agentPort but can be configured separately for future use cases (e.g., OTel format) const req = http.request( { host: agentOpts.host, - port: agentOpts.port, + port: agentOpts.dataPort, path, method: 'POST', agent: http.agent, diff --git a/packages/collector/src/types/collector.d.ts b/packages/collector/src/types/collector.d.ts index 008b263e59..a6028fe49d 100644 --- a/packages/collector/src/types/collector.d.ts +++ b/packages/collector/src/types/collector.d.ts @@ -24,6 +24,7 @@ export interface AgentConfig { export interface CollectorConfig { agentPort?: number; agentHost?: string; + agentDataPort?: number; agentRequestTimeout?: number; tracing?: { stackTraceLength?: number; diff --git a/packages/collector/src/util/normalizeConfig.js b/packages/collector/src/util/normalizeConfig.js index d288dbf188..8c018afe88 100644 --- a/packages/collector/src/util/normalizeConfig.js +++ b/packages/collector/src/util/normalizeConfig.js @@ -30,6 +30,7 @@ module.exports = function normalizeConfig(userConfig = {}) { // as extraFinalConfig to core's normalize function. finalConfig.agentHost = normalizeAgentHost(userConfig, defaults); finalConfig.agentPort = normalizeAgentPort(userConfig, defaults); + finalConfig.agentDataPort = normalizeAgentDataPort(userConfig, defaults); finalConfig.agentRequestTimeout = normalizeAgentRequestTimeout(userConfig, defaults); finalConfig.autoProfile = normalizeAutoProfile(userConfig, defaults); finalConfig.reportUnhandledPromiseRejections = normalizeUnhandledRejections(userConfig); @@ -73,6 +74,24 @@ function normalizeAgentPort(userConfig, defaultConfig) { return value; } +/** + * @param {import('../types/collector').CollectorConfig} userConfig + * @param {{ agentPort: number }} defaultConfig + * @returns {number} + */ +function normalizeAgentDataPort(userConfig, defaultConfig) { + // Future logic for OTLP enabled check can be added here to determine which port to use + const { value } = util.resolve( + { + envValue: 'INSTANA_AGENT_PORT', + inCodeValue: userConfig.agentPort, + defaultValue: defaultConfig.agentPort + }, + [validate.numberValidator] + ); + return value; +} + /** * @param {import('../types/collector').CollectorConfig} userConfig * @param {{ agentRequestTimeout: number }} defaultConfig