Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@middy/cloudwatch-metrics

Package Overview
Dependencies
Maintainers
3
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/cloudwatch-metrics - npm Package Compare versions

Comparing version 5.1.0 to 5.2.0

71

index.js

@@ -1,35 +0,38 @@

import awsEmbeddedMetrics from 'aws-embedded-metrics';
const defaults = {};
const cloudwatchMetricsMiddleware = (opts = {})=>{
const { namespace, dimensions } = {
...defaults,
...opts
};
const cloudwatchMetricsBefore = (request)=>{
const metrics = awsEmbeddedMetrics.createMetricsLogger();
if (namespace) {
metrics.setNamespace(namespace);
}
if (dimensions) {
metrics.setDimensions(dimensions);
}
Object.assign(request.context, {
metrics
});
};
const cloudwatchMetricsAfter = async (request)=>{
await request.context.metrics.flush();
};
const cloudwatchMetricsOnError = async (request)=>{
try {
await cloudwatchMetricsAfter(request);
} catch (e) {}
};
return {
before: cloudwatchMetricsBefore,
after: cloudwatchMetricsAfter,
onError: cloudwatchMetricsOnError
};
};
export default cloudwatchMetricsMiddleware;
import awsEmbeddedMetrics from 'aws-embedded-metrics'
const defaults = {}
const cloudwatchMetricsMiddleware = (opts = {}) => {
const { namespace, dimensions } = { ...defaults, ...opts }
const cloudwatchMetricsBefore = (request) => {
const metrics = awsEmbeddedMetrics.createMetricsLogger()
// If not set, defaults to aws-embedded-metrics
if (namespace) {
metrics.setNamespace(namespace)
}
// If not set, keeps defaults as defined here https://github.com/awslabs/aws-embedded-metrics-node/#configuration
if (dimensions) {
metrics.setDimensions(dimensions)
}
Object.assign(request.context, { metrics })
}
const cloudwatchMetricsAfter = async (request) => {
await request.context.metrics.flush()
}
const cloudwatchMetricsOnError = async (request) => {
try {
await cloudwatchMetricsAfter(request)
} catch (e) {}
}
return {
before: cloudwatchMetricsBefore,
after: cloudwatchMetricsAfter,
onError: cloudwatchMetricsOnError
}
}
export default cloudwatchMetricsMiddleware
{
"name": "@middy/cloudwatch-metrics",
"version": "5.1.0",
"version": "5.2.0",
"description": "Embedded CloudWatch metrics middleware for the middy framework",

@@ -69,6 +69,6 @@ "type": "module",

"devDependencies": {
"@middy/core": "5.1.0",
"@middy/core": "5.2.0",
"@types/aws-lambda": "^8.10.101"
},
"gitHead": "bbdaf5843914921804ba085dd58117273febe6b5"
"gitHead": "2d9096a49cd8fb62359517be96d6c93609df41f0"
}
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