Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Add env variable for disabling Http 4xx 5xx error.
Browse files Browse the repository at this point in the history
  • Loading branch information
fatihaydilek committed Aug 7, 2019
1 parent 546e0a0 commit bcbef89
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export const envVariableKeys = {
THUNDRA_AGENT_COUNT_AWARE_SAMPLER_COUNT_FREQ: 'thundra_agent_lambda_sampler_countAware_countFreq',

THUNDRA_AWS_INSTRUMENT_ON_LOAD: 'thundra_agent_lambda_trace_integrations_aws_instrument_onLoad',

THUNDRA_AGENT_TRACE_INTEGRATION_HTTP_ERROR_ON_4XX: 'thundra_agent_trace_integrations_http_set_error_on_4xx_response_code_disable',
THUNDRA_AGENT_TRACE_INTEGRATION_HTTP_ERROR_ON_5XX: 'thundra_agent_trace_integrations_http_set_error_on_5xx_response_code_disable',
};

export function getTimeoutMargin(region: string) {
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/config/TraceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TraceConfig extends BasePluginConfig {
maskResponse: (response: any) => any;
disabledIntegrations: IntegrationConfig[];
disableInstrumentation: boolean;
disableHttp4xxError: boolean;
disableHttp5xxError: boolean;
integrationsMap: Map<string, Integration>;
instrumenter: Instrumenter;
maskRedisStatement: boolean;
Expand Down Expand Up @@ -57,6 +59,14 @@ class TraceConfig extends BasePluginConfig {
envVariableKeys.THUNDRA_LAMBDA_TRACE_INSTRUMENT_DISABLE) ? Utils.getConfiguration(
envVariableKeys.THUNDRA_LAMBDA_TRACE_INSTRUMENT_DISABLE) === 'true' : options.disableInstrumentation;

this.disableHttp4xxError = Utils.getConfiguration(
envVariableKeys.THUNDRA_AGENT_TRACE_INTEGRATION_HTTP_ERROR_ON_4XX) ? Utils.getConfiguration(
envVariableKeys.THUNDRA_AGENT_TRACE_INTEGRATION_HTTP_ERROR_ON_4XX) === 'true' : options.disableHttp4xxError;

this.disableHttp5xxError = Utils.getConfiguration(
envVariableKeys.THUNDRA_AGENT_TRACE_INTEGRATION_HTTP_ERROR_ON_5XX) ? Utils.getConfiguration(
envVariableKeys.THUNDRA_AGENT_TRACE_INTEGRATION_HTTP_ERROR_ON_5XX) === 'true' : options.disableHttp5xxError;

this.maskRedisStatement = Utils.getConfiguration(
envVariableKeys.THUNDRA_MASK_REDIS_STATEMENT) ? Utils.getConfiguration(
envVariableKeys.THUNDRA_MASK_REDIS_STATEMENT) === 'true' : options.maskRedisStatement;
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/integrations/HttpIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class HttpIntegration implements Integration {
const libHTTPS = lib[1];
const nodeVersion = process.version;
const plugin = this;

function wrapper(request: any) {
return function requestWrapper(options: any, callback: any) {
try {
Expand Down Expand Up @@ -138,7 +139,10 @@ class HttpIntegration implements Integration {
span._setOperationName(resourceName);
}
const statusCode = res.statusCode.toString();
if (statusCode.startsWith('4') || statusCode.startsWith('5')) {
if (!config.disableHttp5xxError && statusCode.startsWith('5')) {
span.setErrorTag(new HttpError(res.statusMessage));
}
if (!config.disableHttp4xxError && statusCode.startsWith('4')) {
span.setErrorTag(new HttpError(res.statusMessage));
}
span.setTag(HttpTags.HTTP_STATUS, res.statusCode);
Expand Down
37 changes: 36 additions & 1 deletion test/integration/http.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('HTTP integration', () => {

return Http.getError(sdk).then(() => {
const span = tracer.getRecorder().spanList[0];

console.log(span);
expect(span.operationName).toBe('httpstat.us/404');
expect(span.className).toBe('HTTP');
expect(span.domainName).toBe('API');
Expand All @@ -68,6 +68,41 @@ describe('HTTP integration', () => {
});
});

test('should disable 4XX 5XX errors on HTTP calls', () => {
const integration = new HttpIntegration({
httpPathDepth: 2,
disableHttp4xxError:true

});
const sdk = require('http');

const tracer = new ThundraTracer();
InvocationSupport.setFunctionName('functionName');

return Http.getError(sdk).then(() => {
const span = tracer.getRecorder().spanList[0];
console.log(span);
expect(span.operationName).toBe('httpstat.us/404');
expect(span.className).toBe('HTTP');
expect(span.domainName).toBe('API');

expect(span.tags['operation.type']).toBe('GET');
expect(span.tags['http.method']).toBe('GET');
expect(span.tags['http.host']).toBe('httpstat.us');
expect(span.tags['http.path']).toBe('/404');
expect(span.tags['http.url']).toBe('httpstat.us/404');
expect(span.tags['http.status_code']).toBe(404);
expect(span.tags['error']).toBe(undefined);
expect(span.tags['error.kind']).toBe(undefined);
expect(span.tags['error.message']).toBe(undefined);
expect(span.tags['topology.vertex']).toEqual(true);
expect(span.tags['trigger.domainName']).toEqual('API');
expect(span.tags['trigger.className']).toEqual('AWS-Lambda');
expect(span.tags['trigger.operationNames']).toEqual(['functionName']);
expect(span.tags['http.body']).not.toBeTruthy();
});
});

test('should instrument HTTPS POST calls', () => {
const integration = new HttpIntegration({
httpPathDepth: 0,
Expand Down

0 comments on commit bcbef89

Please sign in to comment.