@middy/cloudwatch-metrics
Advanced tools
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" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7191
46