Skip to content

Commit

Permalink
Merge pull request #8 from stewartjarod/StringValue
Browse files Browse the repository at this point in the history
Using Serverless CLI or Env variables to set tracing value
  • Loading branch information
alex-murashkin committed Sep 13, 2017
2 parents 7a00388 + a38d98c commit f2fab04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
);
}));
}
Expand Down
29 changes: 29 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@ 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'
}
}
]);
});

it('noDeploy: enables tracing when function.tracing=true, but does not execute AWS request', function() {
runPlugin({
noDeploy: true,
Expand Down

0 comments on commit f2fab04

Please sign in to comment.