Giter Club home page Giter Club logo

dazn-lambda-powertools's Introduction

dazn-lambda-power-tools

An integrated suite of powertools for Lambda functions to make it effortless for you to comply with our guidelines around logging and monitoring:

  • support correlation IDs

  • debug logs are turned off in production, and are instead sampled for 1% of invocations

  • debug logging decisions are respected by all the functions on a call chain

  • HTTP requests always report both latency as well as response count metrics

Overview of available tools

  • logger: structured logging with JSON, configurable log levels, and integrates with other tools to support correlation IDs and sampling (only enable debug logs on 1% of invocations)

  • correlation IDs: create and store correlation IDs that follow our naming convention

  • correlation IDs middleware: automatically extract correlation IDs from the invocation event

  • sample logging middleware: enable debug logging for 1% of invocations, or when upstream caller has made the decision to enable debug logging

  • obfuscater middleware: allows you to obfuscate the invocation event so that sensitive data (e.g. PII) is not logged accidentally

  • log timeout middleware: logs an error message when a function invocation times out

  • stop infinite loop middleware: stops infinite loops

Client libraries

  • http client: HTTP client that automatically forwards any correlation IDs you have captured or created, and records both latency as well as response count metrics

  • SNS client: SNS client that automatically forwards any correlation IDs you have captured or created when you publish a message to SNS

  • SQS client: SQS client that automatically forwards any correlation IDs you have captured or created when you publish a message to SQS

  • Kinesis client: Kinesis client that automatically forwards any correlation IDs you have captured or created when you publish record(s) to a Kinesis stream

  • Step Functions client: Step Functions client that automatically forwards any correlation IDs you have captured or created when you start an execution

  • Lambda client: Lambda client that automatically forwards any correlation IDs you have captured or created when you invokes a Lambda function directly

Patterns

  • basic template for a function: wrapper for your function that applies and configures the function to work well with datadog metrics and sample logging

  • obfuscate template: basic template (above) + obfuscate the invocation event so sensitive data is obfuscated in the after and onError handlers.

Design goal

Compliance with our guidelines around logging and monitoring should be the default behaviour. These tools make it simple for you to do the right thing and gets out of your way as much as possible.

Individually they are useful on their own right, but together they're so much more useful!

The middlewares capture incoming correlation IDs, and the logger automatically includes them in every log message, and the other clients (HTTP, Kinesis, SNS, etc.) would also automatically forward them on to external systems.

Even if your function doens't do anything with correlation IDs, the tools make sure that it behalves correctly as these correlation IDs flows through it.

Did you consider monkey-patching the clients instead?

Instead of forcing you to use our own AWS clients, we could have monkey patched the AWS SDK clients (which we already do in the tests). We can also monkey patch Node's http module (like what Nock does) to intercept HTTP requests and inject correlation IDs as HTTP headers.

We can apply these monkey patching when you apply the correlation IDs middleware, and your function would automagically forward correlation IDs without having to use our own client libraries. That way, as a user of the tools, I can use whatever HTTP client I wish, and can use the standard SDK clients as well.

We did entertain this idea, but I wanted to leave at least one decision for you to make. The rationale is that when things go wrong (e.g. unhandled error, or bug in our wrapper code) or when they don't work as expected (e.g. you're using an AWS SDK client that we don't support yet), at least you have that one decision to start debugging (change the require statement to use the official library instead of our own to see if things things still work).

Useful Lerna CLI commands

bootstrapping locally

Because of the inter-dependencies between packages, it can be tricky to test your changes haven't broken another package.

You can use Lerna CLI to bootstrap all the dependencies with the current local version:

lerna bootstrap

run all tests

lerna run test

create a new package

lerna create <name of package>

and follow the instruction to bootstrap the new project.

Contributing

Please read our contribution guide to see how you can contribute towards this project.

dazn-lambda-powertools's People

Contributors

theburningmonk avatar thomasrogersdazn avatar simontabor avatar obkalay avatar brucehsu avatar gsingh1 avatar jackbravo avatar mike-dazn avatar rmax avatar rehangit avatar justin-caldicott avatar

Stargazers

Ivan Ka avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.