Socket
Socket
Sign inDemoInstall

@aws-lambda-powertools/metrics

Package Overview
Dependencies
Maintainers
2
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-lambda-powertools/metrics

The metrics package for the Powertools for AWS Lambda (TypeScript) library


Version published
Weekly downloads
145K
increased by34.56%
Maintainers
2
Weekly downloads
 
Created

What is @aws-lambda-powertools/metrics?

@aws-lambda-powertools/metrics is an npm package designed to simplify the creation and management of custom metrics in AWS Lambda functions. It provides utilities to easily capture and publish metrics to Amazon CloudWatch, enabling better observability and monitoring of serverless applications.

What are @aws-lambda-powertools/metrics's main functionalities?

Creating Custom Metrics

This feature allows you to create custom metrics and publish them to CloudWatch. The code sample demonstrates how to add metrics for successful invocations and processing time, and then publish them.

const { Metrics, MetricUnits } = require('@aws-lambda-powertools/metrics');

const metrics = new Metrics();

exports.handler = async (event) => {
  metrics.addMetric('SuccessfulInvocations', MetricUnits.Count, 1);
  metrics.addMetric('ProcessingTime', MetricUnits.Milliseconds, 200);
  await metrics.publishStoredMetrics();
  return { statusCode: 200, body: 'Metrics published' };
};

Namespace and Dimensions

This feature allows you to set a namespace and dimensions for your metrics, which helps in organizing and filtering them in CloudWatch. The code sample shows how to set a namespace and dimensions for a payment service.

const { Metrics, MetricUnits } = require('@aws-lambda-powertools/metrics');

const metrics = new Metrics({ namespace: 'MyApp', dimensions: { Service: 'Payment' } });

exports.handler = async (event) => {
  metrics.addMetric('PaymentSuccess', MetricUnits.Count, 1);
  await metrics.publishStoredMetrics();
  return { statusCode: 200, body: 'Payment metrics published' };
};

Automatic Cold Start Metric

This feature automatically captures a cold start metric, which is useful for understanding the performance impact of cold starts in your Lambda functions. The code sample demonstrates how to enable this feature.

const { Metrics, MetricUnits } = require('@aws-lambda-powertools/metrics');

const metrics = new Metrics({ captureColdStartMetric: true });

exports.handler = async (event) => {
  metrics.addMetric('HandlerInvoked', MetricUnits.Count, 1);
  await metrics.publishStoredMetrics();
  return { statusCode: 200, body: 'Cold start metric captured' };
};

Other packages similar to @aws-lambda-powertools/metrics

Keywords

FAQs

Package last updated on 29 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc