1.2.0
Changes
Tracing and Logging utilities remain on 1.1.0 (no changes)
Metrics 1.2.0
Metrics produced by AWS services are standard resolution by default. When you publish a custom metric, you can define it as either standard resolution or high resolution. When you publish a high-resolution metric, CloudWatch stores it with a resolution of 1 second, and you can read and retrieve it with a period of 1 second, 5 seconds, 10 seconds, 30 seconds, or any multiple of 60 seconds.
High-resolution metrics can give you more immediate insight into your application's sub-minute activity. Keep in mind that every PutMetricData call for a custom metric is charged, so calling PutMetricData more often on a high-resolution metric can lead to higher charges. For more information about CloudWatch pricing, see Amazon CloudWatch Pricing.
If you set an alarm on a high-resolution metric, you can specify a high-resolution alarm with a period of 10 seconds or 30 seconds, or you can set a regular alarm with a period of any multiple of 60 seconds. There is a higher charge for high-resolution alarms with a period of 10 or 30 seconds.
{ "_aws":{ "Timestamp":1680086851067, "CloudWatchMetrics":[ { "Namespace":"dotnet-powertools-test", "Metrics":[ { "Name":"Time", "Unit":"Milliseconds", "StorageResolution":60 <---- New property } ], "Dimensions":[ [ "Service" ], [ "functionVersion" ] ] } ] }, "Service":"testService", "functionVersion":"$LATEST", "Time":100.5 }
User experience
using AWS.Lambda.Powertools.Metrics;
public class Function {
[Metrics(Namespace = "ExampleApplication", Service = "Booking")]
public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
{
// Publish a metric with standard resolution i.e. StorageResolution = 60
Metrics.AddMetric("SuccessfulBooking", 1, MetricUnit.Count, MetricResolution.Standard);
// Publish a metric with high resolution i.e. StorageResolution = 1
Metrics.AddMetric("FailedBooking", 1, MetricUnit.Count, MetricResolution.High);
// The last parameter (storage resolution) is optional
Metrics.AddMetric("SuccessfulUpgrade", 1, MetricUnit.Count);
}
}
When method is called without MetricsResolution
parameter it will default to not sending StorageResolution.
2023-04-26T15:07:43.552Z 49e1f9a4-9b00-4462-b111-478fcd8ceffa info {
"_aws": {
"Timestamp": 1682521663552,
"CloudWatchMetrics": [
{
"Namespace": "ServerlessGreeting",
"Metrics": [
{
"Name": "SuccessfulBooking",
"Unit": "Count",
"StorageResolution": 60
},
{
"Name": "FailedBooking",
"Unit": "Count",
"StorageResolution": 1
},
{
"Name": "SuccessfulUpgrade",
"Unit": "Count"
}
],
"Dimensions": [
[
"Service"
]
]
}
]
},
"Service": "ServerlessGreeting",
"GetGreeting_Invocations": 1,
"High": 1
}