From 44d5750802f507e05ebe9d1133be8e8c770763fa Mon Sep 17 00:00:00 2001 From: Jarod Stewart Date: Tue, 12 Sep 2017 12:55:31 -0600 Subject: [PATCH] Fixes #7 by checking if tracing is a string value or boolean --- index.js | 7 ++++--- test/test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 94c37c3..b8d57ee 100644 --- a/index.js +++ b/index.js @@ -13,12 +13,13 @@ module.exports = class TracingConfigPlugin { processTracing() { const service = this.serverless.service; const stage = this.options.stage; - const providerLevelTracingEnabled = (service.provider.tracing === true); + const providerLevelTracingEnabled = (service.provider.tracing === true || service.provider.tracing === 'true'); return Promise.all(Object.keys(service.functions).map(functionName => { return this.toggleTracing( service.functions[functionName].name || `${service.service}-${stage}-${functionName}`, - (service.functions[functionName].tracing === true) - || (providerLevelTracingEnabled && service.functions[functionName].tracing !== false) + service.functions[functionName].tracing === true + || service.functions[functionName].tracing === 'true' + || (providerLevelTracingEnabled && (service.functions[functionName].tracing !== false && service.functions[functionName].tracing !== 'false')) ); })); } diff --git a/test/test.js b/test/test.js index 9bcf0be..9dc3407 100644 --- a/test/test.js +++ b/test/test.js @@ -187,4 +187,33 @@ describe('serverless-plugin-tracing', function() { } ]); }); + + it('enables tracing when opt variable is "true"', function() { + runPlugin({ + functions: { + healthcheck: { + tracing: 'false' + }, + mainFunction: { + tracing: 'true' + } + }, + provider: { + tracing: 'true' + } + }); + + assert.deepEqual(logSpy.getCall(0).args[0], 'Tracing DISABLED for function "myService-test-healthcheck"'); + assert.deepEqual(logSpy.getCall(1).args[0], 'Tracing ENABLED for function "myService-test-mainFunction"'); + assert.deepEqual(requestSpy.getCall(1).args, [ + 'Lambda', + 'updateFunctionConfiguration', + { + FunctionName: 'myService-test-mainFunction', + TracingConfig: { + Mode: 'Active' + } + } + ]); + }); });