@serverless/sdk-beta
Advanced tools
Comparing version 0.1.3 to 0.2.0
13
index.js
@@ -10,2 +10,3 @@ 'use strict'; | ||
}; | ||
const RUNTIME = 'nodejs4.3'; | ||
@@ -18,3 +19,3 @@ class SDK { | ||
host: ENDPOINTS[process.env.AWS_REGION], | ||
path: '/events', | ||
path: '/events/v0', | ||
method: 'POST', | ||
@@ -29,2 +30,6 @@ }; | ||
sendInvocation(invocation, callback) { | ||
const tags = invocation.tags || {}; | ||
tags.region = process.env.AWS_REGION; | ||
tags.runtime = RUNTIME; | ||
const event = { | ||
@@ -41,2 +46,3 @@ apikey: this.APIKey, | ||
requestId: invocation.requestId, | ||
tags: Object.keys(tags).map(name => ({ name, value: tags[name] })), | ||
}; | ||
@@ -60,3 +66,3 @@ | ||
trackHandler(handler) { | ||
trackHandler(handler, tags) { | ||
// bind `this` to variable `sdk` so it can be used inside the callback | ||
@@ -70,6 +76,5 @@ const sdk = this; | ||
memory: parseInt(context.memoryLimitInMB, 10), | ||
runtime: 'nodejs4.3', | ||
provider: 'aws', | ||
requestId: context.invokeid, | ||
region: process.env.AWS_REGION, | ||
tags, | ||
}); | ||
@@ -76,0 +81,0 @@ |
{ | ||
"name": "@serverless/sdk-beta", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "lint": "eslint .", |
@@ -9,5 +9,5 @@ # sdk | ||
## Examples | ||
## How to use | ||
Wrap your function with the SDK's trackHandler | ||
Wrap your function with the SDK's `trackHandler`: | ||
@@ -17,12 +17,29 @@ ```js | ||
// Your first function handler | ||
// Your function handler | ||
module.exports.hello = sdk.trackHandler((event, context, cb) => { | ||
// remove the comment in the next line to track an error | ||
// throw new Error('Whoops!'); | ||
cb(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event }); | ||
cb(null, { | ||
message: 'Go Serverless v1.0! Your function executed successfully!', event | ||
}); | ||
}); | ||
``` | ||
## Development guideline | ||
## API | ||
Make sure this code adds the least overhead possible to allow Insights providing value. Every bit send, every function invocation counts in the millions … | ||
### `trackHandler(handler, tags)` | ||
Track handler function invocations. | ||
Arguments: | ||
- `handler` - **required** - function to track by SDK. | ||
- `tags` - optional object with custom tags e.g. `{'owner': 'teamA'}`. Each key/value pair is treated as separate tag. `region` and `runtime` tags are added to each invocation. | ||
#### Tracking errors | ||
Errors thrown from within handler function are automatically tracked. | ||
```js | ||
module.exports.hello = sdk.trackHandler((event, context, cb) => { | ||
throw new Error('Whoops!'); | ||
}); | ||
``` |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4562
98
44
1