Skip to content
Merged
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
43 changes: 41 additions & 2 deletions packages/collector/src/announceCycle/unannounced.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ const maxRetryDelay = 60 * 1000; // one minute
* @property {boolean} [span-batching-enabled]
* @property {import('@instana/core/src/config/types').Disable} [disable]
* @property {StackTraceConfig} [global]
* @property {HTTPTracingConfig} [http]
*/

/**
* @typedef {Object} HTTPExitConfig
* @property {boolean} [classify-all-4xx-as-errors]
* @property {Array<number>} [classify-as-errors]
*/

/**
* @typedef {Object} HTTPTracingConfig
* @property {Array.<string>} [extra-http-headers]
* @property {HTTPExitConfig} [exit]
*/

/**
Expand Down Expand Up @@ -132,6 +145,7 @@ function tryToAnnounce(ctx, retryDelay = initialRetryDelay) {
function applyAgentConfiguration(agentResponse) {
applySecretsConfiguration(agentResponse);
applyExtraHttpHeaderConfiguration(agentResponse);
applyHttpExitConfiguration(agentResponse);
applyKafkaTracingConfiguration(agentResponse);
applyOtlpExporterConfiguration(agentResponse);
applySpanBatchingConfiguration(agentResponse);
Expand Down Expand Up @@ -288,7 +302,7 @@ function applyStackTraceConfiguration(agentResponse) {
ensureNestedObjectExists(agentOpts.config, ['tracing', 'global']);

if (globalConfig['stack-trace'] !== undefined) {
const stackTraceModeValidation = coreConfig.validate.validateStackTraceMode(globalConfig['stack-trace']);
const stackTraceModeValidation = coreConfig.validators.validateStackTraceMode(globalConfig['stack-trace']);
if (stackTraceModeValidation.isValid) {
const normalizedStackTrace = coreConfig.normalizers.stackTrace.normalizeStackTraceModeFromAgent(
globalConfig['stack-trace']
Expand All @@ -302,7 +316,9 @@ function applyStackTraceConfiguration(agentResponse) {
}

if (globalConfig['stack-trace-length'] !== undefined) {
const stackTraceLengthValidation = coreConfig.validate.validateStackTraceLength(globalConfig['stack-trace-length']);
const stackTraceLengthValidation = coreConfig.validators.validateStackTraceLength(
globalConfig['stack-trace-length']
);
if (stackTraceLengthValidation.isValid) {
const normalizedStackTraceLength = coreConfig.normalizers.stackTrace.normalizeStackTraceLengthFromAgent(
globalConfig['stack-trace-length']
Expand Down Expand Up @@ -333,6 +349,29 @@ function applyDisableConfiguration(agentResponse) {
tracing: { disable: disablingConfig }
}).value;
}

/**
* @param {AgentAnnounceResponse} agentResponse
*/
function applyHttpExitConfiguration(agentResponse) {
const exitConfig = agentResponse?.tracing?.http?.exit;
if (!exitConfig) {
return;
}

ensureNestedObjectExists(agentOpts.config, ['tracing', 'http', 'exit']);
Comment thread
kirrg001 marked this conversation as resolved.

const classifyAll4xxAsErrors = coreConfig.validators.booleanValidator(exitConfig['classify-all-4xx-as-errors']);
if (classifyAll4xxAsErrors !== undefined) {
agentOpts.config.tracing.http.exit.classifyAll4xxAsErrors = classifyAll4xxAsErrors;
}

const classifyAsErrors = coreConfig.validators.httpExitErrorCodeValidator(exitConfig['classify-as-errors']);
if (classifyAsErrors !== undefined) {
agentOpts.config.tracing.http.exit.classifyAsErrors = classifyAsErrors;
}
}

module.exports = {
init,

Expand Down
4 changes: 4 additions & 0 deletions packages/collector/src/types/collector.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export interface AgentConfig {
tracing?: {
http?: {
extraHttpHeadersToCapture?: string[];
exit?: {
classifyAll4xxAsErrors?: boolean;
classifyAsErrors?: number[];
};
};
kafka?: {
traceCorrelation?: boolean;
Expand Down
8 changes: 7 additions & 1 deletion packages/collector/test/apps/agentStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const ignoreEndpoints = process.env.IGNORE_ENDPOINTS && JSON.parse(process.env.I
const disable = process.env.AGENT_DISABLE_TRACING && JSON.parse(process.env.AGENT_DISABLE_TRACING);
const stackTraceConfig = process.env.STACK_TRACE_CONFIG && JSON.parse(process.env.STACK_TRACE_CONFIG);
const otlpExporter = process.env.OTLP_EXPORTER && JSON.parse(process.env.OTLP_EXPORTER);
const httpExitConfig = process.env.AGENT_STUB_HTTP_EXIT_CONFIG && JSON.parse(process.env.AGENT_STUB_HTTP_EXIT_CONFIG);

const uuids = {};
const agentLogs = [];
Expand Down Expand Up @@ -126,7 +127,8 @@ app.put('/com.instana.plugin.nodejs.discovery', (req, res) => {
ignoreEndpoints ||
disable ||
stackTraceConfig ||
otlpExporter
otlpExporter ||
httpExitConfig
) {
response.tracing = {};

Expand Down Expand Up @@ -157,6 +159,10 @@ app.put('/com.instana.plugin.nodejs.discovery', (req, res) => {
if (otlpExporter) {
response.tracing.otlp = otlpExporter;
}
if (httpExitConfig) {
response.tracing.http = response.tracing.http || {};
response.tracing.http.exit = httpExitConfig;
}
}

res.send(response);
Expand Down
3 changes: 3 additions & 0 deletions packages/collector/test/apps/agentStubControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class AgentStubControls {
if (opts.otlpExporter) {
env.OTLP_EXPORTER = JSON.stringify(opts.otlpExporter);
}
if (opts.httpExitConfig) {
env.AGENT_STUB_HTTP_EXIT_CONFIG = JSON.stringify(opts.httpExitConfig);
}

this.agentStub = spawn('node', [path.join(__dirname, 'agentStub.js')], {
stdio: config.getAppStdio(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ if (process.env.APP_USES_HTTPS === 'true') {
});
}

app.get('/fetch-with-status', (req, res) => {
const status = req.query.status || '200';
const options = {
hostname: 'localhost',
port: process.env.SERVER_PORT,
method: 'GET',
path: `/fetch-with-status?status=${status}`
};
const req_ = httpModule.request(options, response => {
response.resume();
response.on('end', () => res.status(response.statusCode).send());
});
req_.on('error', err => res.status(503).send(err.message));
req_.end();
});

app.get('/matrix-params/:params', (req, res) => {
res.sendStatus(200);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ app.get('/timeout', (req, res) => {
}, 10000);
});

app.all('/fetch-with-status', (req, res) => {
const status = parseInt(req.query.status, 10) || 200;
res.status(status).json({ status });
});

app.put('/continue', (req, res) => {
// Node http server will automatically send 100 Continue when it receives a request with an "Expect: 100-continue"
// header present, unless we override the 'checkContinue' listener. For our test case, the default behaviour is just
Expand Down
Loading