serverless-plugin-tracing
Advanced tools
Comparing version 1.1.0 to 2.0.0
26
index.js
@@ -7,5 +7,4 @@ 'use strict'; | ||
this.options = options; | ||
this.aws = serverless.getProvider('aws'); | ||
this.hooks = { | ||
'after:deploy:deploy': this.processTracing.bind(this) | ||
'package:compileEvents': this.processTracing.bind(this) | ||
}; | ||
@@ -16,2 +15,12 @@ } | ||
const service = this.serverless.service; | ||
this.functionResources = Object.keys(service.provider.compiledCloudFormationTemplate.Resources) | ||
.reduce((acc, resourceId) => { | ||
const resource = service.provider.compiledCloudFormationTemplate.Resources[resourceId]; | ||
if (resource.Type === "AWS::Lambda::Function") { | ||
if (resource.Properties) { | ||
acc[resource.Properties.FunctionName] = resource; | ||
} | ||
} | ||
return acc; | ||
}, {}); | ||
const stage = this.options.stage; | ||
@@ -30,10 +39,11 @@ const providerLevelTracingEnabled = (service.provider.tracing === true || service.provider.tracing === 'true'); | ||
toggleTracing(functionName, isEnabled) { | ||
if (!this.functionResources[functionName]) { | ||
this.serverless.cli.log(`Tracing NOT SET for function "${functionName}" as couldn't find it in Cloud Formation template`); | ||
return; | ||
} | ||
this.serverless.cli.log(`Tracing ${isEnabled ? 'ENABLED' : 'DISABLED'} for function "${functionName}"`); | ||
return this.options.noDeploy ? Promise.resolve(void 'noop') : this.aws.request('Lambda', 'updateFunctionConfiguration', { | ||
FunctionName: functionName, | ||
TracingConfig: { | ||
Mode: isEnabled === true ? 'Active' : 'PassThrough' | ||
} | ||
}); | ||
this.functionResources[functionName].Properties.TracingConfig = { | ||
Mode: isEnabled === true ? 'Active' : 'PassThrough' | ||
}; | ||
} | ||
}; |
{ | ||
"name": "serverless-plugin-tracing", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Enables AWS X-Ray for entire Serverless stack or individual functions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,5 +9,9 @@ # serverless-plugin-tracing | ||
**Update**: as of `2.0.0`, plugin uses Cloud Formation to update `TracingConfig` and no longer | ||
makes additional AWS SDK calls. No cange to YAML contract: stays same as in 1.x | ||
Tested with `serverless@1.22.0`. | ||
Note: this plugin is currently **Beta**. | ||
Note: tested to work well with `serverless@1.13.2`. Some older versions of `serverless` | ||
Note: 1.x was tested to work well with `serverless@1.13.2`. Some older versions of `serverless` | ||
may not work due to outdated Javascript SDK that | ||
@@ -14,0 +18,0 @@ does not support `TracingConfig`. |
16276
8
43
68