Skip to content

Commit a1db8b4

Browse files
authored
fix(aws-lambda): ensured tracer is properly disabled when configured (#1593)
Detected bug in #1315
1 parent 703ed88 commit a1db8b4

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

packages/aws-lambda/src/wrapper.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ function shimmedHandler(originalHandler, originalThis, originalArgs, _config) {
6868
const lambdaCallback = originalArgs[2];
6969

7070
const arnInfo = arnParser(context);
71-
init(event, arnInfo, _config);
71+
const tracingEnabled = init(event, arnInfo, _config);
72+
73+
if (!tracingEnabled) {
74+
return originalHandler.apply(originalThis, originalArgs);
75+
}
7276

7377
// The AWS lambda runtime does not seem to inspect the number of arguments the handler function expects. Instead, it
7478
// always call the handler with three arguments (event, context, callback), no matter if the handler will use the
@@ -248,6 +252,10 @@ function init(event, arnInfo, _config) {
248252
// - we always renormalize unconditionally to ensure safety.
249253
config = normalizeConfig(config, logger);
250254

255+
if (!config.tracing.enabled) {
256+
return false;
257+
}
258+
251259
const useLambdaExtension = shouldUseLambdaExtension();
252260
if (useLambdaExtension) {
253261
logger.info('@instana/aws-lambda will use the Instana Lambda extension to send data to the Instana back end.');
@@ -282,6 +290,8 @@ function init(event, arnInfo, _config) {
282290
metrics.init(config);
283291
metrics.activate();
284292
tracing.activate();
293+
294+
return true;
285295
}
286296

287297
function registerTimeoutDetection(context, entrySpan) {

packages/aws-lambda/test/integration_test/test_definition.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ function prelude(opts) {
5757
if (opts.instanaEndpointUrlMissing) {
5858
env.INSTANA_ENDPOINT_URL = '';
5959
}
60+
if (opts.instanaTracingDisabled) {
61+
env.INSTANA_DISABLE_TRACING = 'true';
62+
}
6063
if (opts.instanaAgentKey) {
6164
env.INSTANA_AGENT_KEY = opts.instanaAgentKey;
6265
}
@@ -988,6 +991,42 @@ function registerTests(handlerDefinitionPath, reduced) {
988991
});
989992
});
990993

994+
describeOrSkipIfReduced()('when INSTANA_DISABLE_TRACING is set', function () {
995+
// - INSTANA_ENDPOINT_URL is missing
996+
// - lambda function ends with success
997+
const env = prelude.bind(this)({
998+
handlerDefinitionPath,
999+
instanaAgentKey,
1000+
instanaTracingDisabled: true
1001+
});
1002+
1003+
let control;
1004+
1005+
before(async () => {
1006+
control = new Control({
1007+
faasRuntimePath: path.join(__dirname, '../runtime_mock'),
1008+
handlerDefinitionPath,
1009+
startBackend: true,
1010+
env
1011+
});
1012+
1013+
await control.start();
1014+
});
1015+
1016+
beforeEach(async () => {
1017+
await control.reset();
1018+
await control.resetBackendSpansAndMetrics();
1019+
});
1020+
1021+
after(async () => {
1022+
await control.stop();
1023+
});
1024+
1025+
it('expect no tracing data', () => {
1026+
return verify(control, { error: false, expectMetrics: false, expectSpans: false });
1027+
});
1028+
});
1029+
9911030
describeOrSkipIfReduced(reduced)(
9921031
'when the back end becomes responsive again after a timeout in a previous handler run',
9931032
function () {

0 commit comments

Comments
 (0)