Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 4a61ad0

Browse files
Update dependencies; update README.md (#34)
Key changes: - updated SignalFx client and SignalFx tracing libs to the latest version - updated README.md with sample code demonstrating how to add extra tags to spans sent by the wrapper - updated README.md with recommended approach to metrics and events delivery
1 parent 71a04d3 commit 4a61ad0

File tree

3 files changed

+765
-276
lines changed

3 files changed

+765
-276
lines changed

README.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
You can use this document to add a SignalFx wrapper to your AWS Lambda for Node.js. 
5+
You can use this document to add a SignalFx wrapper to your AWS Lambda for Node.js.
66

77
The SignalFx Node.js Lambda Wrapper wraps around an AWS Lambda Node.js function handler, which allows metrics and traces to be sent to SignalFx.
88

@@ -47,15 +47,15 @@ In this option, you will use a Lambda layer created and hosted by SignalFx.
4747

4848
In this option, you will choose a SignalFx template, and then deploy a copy of the layer.
4949

50-
1. Open your AWS console. 
50+
1. Open your AWS console.
5151
2. In the landing page, under **Compute**, click **Lambda**.
5252
3. Click **Create function** to create a layer with SignalFx's capabilities.
5353
4. Click **Browse serverless app repository**.
5454
5. Click **Public applications**.
5555
6. In the search field, enter and select **signalfx-lambda-python-wrapper**.
5656
7. Review the template, permissions, licenses, and then click **Deploy**.
5757
* A copy of the layer will now be deployed into your account.
58-
8. Return to the previous screen to add a layer to the function, select from list of runtime compatible layers, and then select the name of the copy. 
58+
8. Return to the previous screen to add a layer to the function, select from list of runtime compatible layers, and then select the name of the copy.
5959

6060
### Option 3: Install the wrapper package with npm
6161

@@ -190,13 +190,12 @@ To learn more, see:
190190
exports.handler = signalFxLambda.wrapper((event, context, callback) => {
191191
...
192192
// to send custom event:
193-
signalFxLambda.helper.sendCustomEvent('Custom', {functionName: context.functionName}, {description: 'Custom event'})
194-
.then(() => callback(null, 'Done'));
193+
signalFxLambda.helper.sendCustomEvent('Custom', {functionName: context.functionName}, {description: 'Custom event'});
195194
196195
// to transform & forward CloudWatch event:
197-
signalFxLambda.helper.sendCloudWatchEvent(event)
198-
.then(() => callback(null, 'Done'))
199-
196+
signalFxLambda.helper.sendCloudWatchEvent(event);
197+
198+
callback(null, 'Done');
200199
});
201200
```
202201
@@ -209,10 +208,10 @@ To learn more, see:
209208
exports.handler = signalFxLambda.asyncWrapper(async (event, context) => {
210209
...
211210
// to send custom event:
212-
await signalFxLambda.helper.sendCustomEvent('Custom', {functionName: context.functionName}, {description: 'Custom event'});
211+
signalFxLambda.helper.sendCustomEvent('Custom', {functionName: context.functionName}, {description: 'Custom event'});
213212
214213
// to transform & forward CloudWatch event:
215-
await signalFxLambda.helper.sendCloudWatchEvent(event);
214+
signalFxLambda.helper.sendCloudWatchEvent(event);
216215
...
217216
});
218217
```
@@ -265,6 +264,36 @@ The tracing wrapper creates a span for the wrapper handler. This span contains t
265264
| function_wrapper_version | SignalFx function wrapper qualifier (e.g., signalfx_lambda_0.0.2) |
266265
| component | The literal value of 'python-lambda-wrapper |
267266

267+
#### Adding Extra Tags
268+
269+
If you want to add extra tags to your spans use the following snippet **inside** your lambda handler (i.e. this code has to run during lambda handler invocation, not as a part of the cold start logic):
270+
271+
```js
272+
const tracing = require("signalfx-lambda/tracing");
273+
274+
// this sample uses asyncWrapper but the logic is the same when
275+
// the synchronous wrapper is used
276+
exports.handler = signalFxLambda.asyncWrapper(async (event, context) => {
277+
const tracer = tracing.tracer();
278+
tracer.scope().active().setTag("my-custom-tag", "some-value");
279+
});
280+
```
281+
282+
### Asynchronous Metrics and Events Delivery
283+
284+
Although the following `signalFxLambda.helper.send*` methods all return promises that resolve when send operation completes it is recommended to ignore those promises as the wrapper is going to wait for their completion internally.
285+
286+
This way multiple send operations may run concurrently without blocking your lambda handler code.
287+
288+
You can still await any of those promises if your use case forces you to do so.
289+
290+
```js
291+
function sendGauge(metricName, metricValue, dimensions);
292+
function sendCounter(metricName, metricValue, dimensions);
293+
function sendCustomEvent(type, dimensions, properties, timestamp);
294+
function sendCloudWatchEvent(cwevent);
295+
```
296+
268297
### Deployment
269298

270299
1. Run `npm pack` to package the module with the configuration in `package.json`.

0 commit comments

Comments
 (0)