@middy/cloudwatch-metrics
Advanced tools
Comparing version 2.5.5 to 2.5.6
42
index.js
@@ -1,38 +0,32 @@ | ||
"use strict"; | ||
const awsEmbeddedMetrics = require('aws-embedded-metrics') | ||
const awsEmbeddedMetrics = require('aws-embedded-metrics'); | ||
const cloudwatchMetricsMiddleware = (opts = {}) => { | ||
const defaults = {}; | ||
const options = { ...defaults, | ||
...opts | ||
}; | ||
const defaults = {} | ||
const options = { ...defaults, ...opts } | ||
const cloudwatchMetricsBefore = request => { | ||
const metrics = awsEmbeddedMetrics.createMetricsLogger(); // If not set, defaults to aws-embedded-metrics | ||
const cloudwatchMetricsBefore = (request) => { | ||
const metrics = awsEmbeddedMetrics.createMetricsLogger() | ||
// If not set, defaults to aws-embedded-metrics | ||
if (options.namespace) { | ||
metrics.setNamespace(options.namespace); | ||
} // If not set, defaults to ServiceName, ServiceType and LogGroupName | ||
metrics.setNamespace(options.namespace) | ||
} | ||
// If not set, defaults to ServiceName, ServiceType and LogGroupName | ||
if (options.dimensions) { | ||
metrics.setDimensions(...options.dimensions); | ||
metrics.setDimensions(...options.dimensions) | ||
} | ||
Object.assign(request.context, { metrics }) | ||
} | ||
Object.assign(request.context, { | ||
metrics | ||
}); | ||
}; | ||
const cloudwatchMetricsAfter = async (request) => { | ||
await request.context.metrics.flush() | ||
} | ||
const cloudwatchMetricsAfter = async request => { | ||
await request.context.metrics.flush(); | ||
}; | ||
return { | ||
before: cloudwatchMetricsBefore, | ||
after: cloudwatchMetricsAfter | ||
}; | ||
}; | ||
} | ||
} | ||
module.exports = cloudwatchMetricsMiddleware; | ||
module.exports = cloudwatchMetricsMiddleware |
{ | ||
"name": "@middy/cloudwatch-metrics", | ||
"version": "2.5.5", | ||
"version": "2.5.6", | ||
"description": "Embedded CloudWatch metrics middleware for the middy framework", | ||
@@ -55,5 +55,5 @@ "type": "commonjs", | ||
"devDependencies": { | ||
"@middy/core": "^2.5.5" | ||
"@middy/core": "^2.5.6" | ||
}, | ||
"gitHead": "b84840ec8afd289f6decfd0d645be4899051792d" | ||
"gitHead": "0c789f55b4adf691f977b0d9904d1a805bb3bb2b" | ||
} |
7607
33