npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bitgenics/honey-lambda-logger

v0.4.0

Published

A simple wrapper for NodeJS Lambda calls that logs every invocation in lambda with useful metadata

Downloads

39

Readme

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

| Name | Description | | --- | --- | | context.accountId | The AWS accountId running the Lambda. | | context.awsRequestId | The identifier of the invocation request. | | context.callbackWaitsForEmptyEventLoop | Send response immediately without waiting. | | context.functionName | The name of the Lambda function. | | context.functionVersion | The version of the function. | | context.invokedFunctionArn | The Amazon Resource Name (ARN) used to invoke the function. | | context.invokeid | context.awsRequestId, but different? | | context.logGroupName | The log group for the function. | | context.logStreamName | The log stream for the function instance.| | context.logUrl | A URL to the correct LogStream with a filter for this request. | | context.memoryLimitInMB | The amount of memory configured on the function. | | context.region | The region the Lambda ran in. |

General

| Name | Description | | --- | --- | | cold_start | Is this a cold start of the function? | | costInMicroDollar | The cost in microDollars. The $ price of a million requests| | costUnits | 1 cost unit = lowest possible charge: 100ms of 128Mb Lambda | | durationInMs | How long the execution took in milliseconds | | err | The error object | | likely_timeout | 250ms before the lambda times out we log an event with likely_timeout set | | remainingMs | How 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

| Name | Description | | --- | --- | | event_meta.accountId | The AWS accountId of the source of the event. | | event_meta.awsRegion | Region of the source. | | event_meta.eventSource | The system responsible for the trigger (ie aws:sns) | | event_meta.eventSourceARN | ARN of the source of the event. | | event_meta.eventVersion | Event version. | | event_meta.records_length | The amount of records in this event. |

DynamoDB events

| Name | Description | | --- | --- | | event_meta.dynamodb.StreamViewType | The StreamViewType of the DynamoDB Stream. | | event_meta.dynamodb.records | Array of Objects with all Key, eventName and eventID for every record |

SNS events

| Name | Description | | --- | --- | | event_meta.sns.MessageAttributes. | There is a column for every MessageAttribute and their value | | event_meta.sns.MessageId | MessageId | | event_meta.sns.TopicArn | Arn of the SNS Topic the notification is from. | | event_meta.sns.Type | Type of message. |