@dazn/lambda-powertools-middleware-sample-logging

1.29.0 • Public • Published

lambda-powertools-middleware-sample-logging

A Middy middleware that will enable debug logging for a configurable % of invocations. Defaults is 1%.

Main features:

  • integrates with the @dazn/lambda-powertools-logger package to enable debug logging

  • integrates with the @dazn/lambda-powertools-correlation-ids package to allow sampling decision to flow through correlation IDs - i.e. enable debug logging at the edge, and the entire call chain will respect that decision

  • enables debug logging for some % (defaults to 1%) of invocations

  • records an error log message with the invocation event as attribute when an invocation errors

Getting Started

Install from NPM: npm install @dazn/lambda-powertools-middleware-sample-logging

Alternatively, if you use the template @dazn/lambda-powertools-pattern-basic then this would be configured for you.

API

Accepts a configuration object of the following shape:

{
  sampleRate: double [between 0 and 1]
}
const middy = require('middy')
const sampleLogging = require('@dazn/lambda-powertools-middleware-sample-logging')

const handler = async (event, context) => {
  return 42
}

module.exports = middy(handler)
  .use(sampleLogging({ sampleRate: 0.01 }))
}

This middleware is often used alongside the @dazn/lambda-powertools-middleware-correlation-ids middleware to implement sample logging. It's recommended that you use the @dazn/lambda-powertools-pattern-basic which configures both to enable debug logging at 1% of invocations.

Dependencies (2)

Dev Dependencies (1)

Package Sidebar

Install

npm i @dazn/lambda-powertools-middleware-sample-logging

Weekly Downloads

3,579

Version

1.29.0

License

MIT

Unpacked Size

13.6 kB

Total Files

6

Last publish

Collaborators

  • gideonparanoid
  • davidrv87
  • gabriela_nowicka
  • criveindazn
  • dazn.builder.frontend
  • automation-drone
  • m.bazalik
  • dazn.oss.lambda.powertools