Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/collector/src/agent/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion packages/collector/src/agentConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Comment thread
kirrg001 marked this conversation as resolved.
path,
method: 'POST',
agent: http.agent,
Expand Down
1 change: 1 addition & 0 deletions packages/collector/src/types/collector.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface AgentConfig {
export interface CollectorConfig {
agentPort?: number;
agentHost?: string;
agentDataPort?: number;
agentRequestTimeout?: number;
tracing?: {
stackTraceLength?: number;
Expand Down
19 changes: 19 additions & 0 deletions packages/collector/src/util/normalizeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down