0.4.0 • Published 4 years ago

@bitgenics/honey-lambda-logger v0.4.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

honey-lambda-logger

The problem

Lambdas are amazing, but as soon as you have more than a handful of them logging & monitoring them becomes unwieldy. Creating alarms for every individual lambda isn't really an option and creating one for all lambdas is an exercise in frustration.

Cloudwatch: "Your threshold of 3 errors in 5 minutes is breached"
Me: That is bad! Which ones are giving errors?
Cloudwatch: "Your threshold of 3 errors in 5 minutes is breached"
Me: But where are the errors?!
CLoudwatch: "Your threshold of ... "
Me: Aaarrrrggghhhhh..

The Solution

This library is designed to wrap all NodeJS invocations and automagically suck all metadata into honeycomb. 90% of your data needs can be met with a quick:

const hll = require('@bitgenics/honeycomb-lambda-logger')

const handler = async (event, context) => {
  .....//Your regular lambda
}

module.exports = hll(handler)

NOTE! Currently honey-lambda-logger only works on async handlers and ignores the node6 callbacks or even early context.done type callbacks.

Configuring

Configuring hll is done through two environment variables

  • HONEYCOMB_WRITE_KEY: Your write key for Honeycomb.
  • HLL_DATASET: And surprise surprise, the Dataset to log to.

Customizing

We do give you a lot of control of what exactly should go to Honeycomb. Here are the options you can pass to hll(handler, options)

  • meta: An object that gets passed to honeycomb as-is. Use this for any static information about the Lambda, such as what module it is from.
  • transformEvent: Function with signature (event) => {}. We automatically extract any AWS specified metadata supplied in the event and context objects. But this function allows you to extract data from the event payload.
  • transformResult: Function with signature (result) => {}. We do not automatically log anything from the return value of the handler. If you do want to log something, this is your chance.
  • transformErr: Function with signature (err) => {}. We already log everything on the Error object, but maybe you want it in a different format?
  • rethrowErr: Boolean, default true. Whether or not to rethrow the error after logging it.
  • parseMetadata: Boolean, default true. If you don't want to parse the metadata associated with the event, you can disable it here.

Log Output

Context

For more information on most of these settings, see: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html

NameDescription
context.accountIdThe AWS accountId running the Lambda.
context.awsRequestIdThe identifier of the invocation request.
context.callbackWaitsForEmptyEventLoopSend response immediately without waiting.
context.functionNameThe name of the Lambda function.
context.functionVersionThe version of the function.
context.invokedFunctionArnThe Amazon Resource Name (ARN) used to invoke the function.
context.invokeidcontext.awsRequestId, but different?
context.logGroupNameThe log group for the function.
context.logStreamNameThe log stream for the function instance.
context.logUrlA URL to the correct LogStream with a filter for this request.
context.memoryLimitInMBThe amount of memory configured on the function.
context.regionThe region the Lambda ran in.

General

NameDescription
cold_startIs this a cold start of the function?
costInMicroDollarThe cost in microDollars. The $ price of a million requests
costUnits1 cost unit = lowest possible charge: 100ms of 128Mb Lambda
durationInMsHow long the execution took in milliseconds
errThe error object
likely_timeout250ms before the lambda times out we log an event with likely_timeout set
remainingMsHow many milliseconds are left

Events

If we can determine what type of event triggered the Lambda we will log as much as information as we can. Currently we only parse DynamoDB and SNS Notifications. We are working on API Gateway and S3 events.

All (some?) events

NameDescription
event_meta.accountIdThe AWS accountId of the source of the event.
event_meta.awsRegionRegion of the source.
event_meta.eventSourceThe system responsible for the trigger (ie aws:sns)
event_meta.eventSourceARNARN of the source of the event.
event_meta.eventVersionEvent version.
event_meta.records_lengthThe amount of records in this event.

DynamoDB events

NameDescription
event_meta.dynamodb.StreamViewTypeThe StreamViewType of the DynamoDB Stream.
event_meta.dynamodb.recordsArray of Objects with all Key, eventName and eventID for every record

SNS events

NameDescription
event_meta.sns.MessageAttributes.There is a column for every MessageAttribute and their value
event_meta.sns.MessageIdMessageId
event_meta.sns.TopicArnArn of the SNS Topic the notification is from.
event_meta.sns.TypeType of message.
0.4.0

4 years ago

0.3.5

4 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago