Metrics creates custom metrics asynchronously by logging metrics to standard output following Amazon CloudWatch Embedded Metric Format (EMF).
These metrics can be visualized through Amazon CloudWatch Console.
Key featuresFor a full list of features go to docs.powertools.aws.dev/lambda/dotnet/core/metrics/
GitHub: https://github.com/aws-powertools/powertools-lambda-dotnet/
Sample FunctionView the full example here: https://github.com/aws-powertools/powertools-lambda-dotnet/tree/develop/examples/Metrics
public class Function
{
/// <summary>
/// Lambda Handler
/// </summary>
/// <param name="apigwProxyEvent">API Gateway Proxy event</param>
/// <param name="context">AWS Lambda context</param>
/// <returns>API Gateway Proxy response</returns>
[Logging(LogEvent = true)]
[Metrics(CaptureColdStart = true)]
public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigwProxyEvent,
ILambdaContext context)
{
var requestContextRequestId = apigwProxyEvent.RequestContext.RequestId;
Logger.LogInformation("Getting ip address from external service");
// Add Metric to capture the amount of time
Metrics.PushSingleMetric(
metricName: "CallingIP",
value: 1,
unit: MetricUnit.Count,
service: "lambda-powertools-metrics-example",
defaultDimensions: new Dictionary<string, string>
{
{ "Metric Type", "Single" }
});
var watch = Stopwatch.StartNew();
var location = await GetCallingIp();
watch.Stop();
Metrics.AddMetric("ElapsedExecutionTime", watch.ElapsedMilliseconds, MetricUnit.Milliseconds);
Metrics.AddMetric("SuccessfulLocations", 1, MetricUnit.Count);
var lookupRecord = new LookupRecord(lookupId: requestContextRequestId,
greeting: "Hello Powertools for AWS Lambda (.NET)", ipAddress: location);
try
{
Metrics.PushSingleMetric(
metricName: "RecordsSaved",
value: 1,
unit: MetricUnit.Count,
service: "lambda-powertools-metrics-example",
defaultDimensions: new Dictionary<string, string>
{
{ "Metric Type", "Single" }
});
await SaveRecordInDynamo(lookupRecord);
Metrics.AddMetric("SuccessfulWrites", 1, MetricUnit.Count);
return new APIGatewayProxyResponse
{
Body = JsonSerializer.Serialize(lookupRecord),
StatusCode = 200,
Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
};
}
catch (Exception e)
{
Logger.LogError(e.Message);
return new APIGatewayProxyResponse
{
Body = e.Message,
StatusCode = 500,
Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
};
}
}
}
Sample output
{
"_aws": {
"Timestamp": 1648181318790,
"CloudWatchMetrics": [
{
"Namespace": "AWSLambdaPowertools",
"Metrics": [
{
"Name": "CallingIP",
"Unit": "Count"
}
],
"Dimensions": [
[
"Metric Type"
],
[
"Service"
]
]
}
]
},
"Metric Type": "Single",
"Service": "lambda-powertools-metrics-example",
"CallingIP": 1
}
Product Versions Compatible and additional computed target framework versions. .NET net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. NuGet packages (1)
Showing the top 1 NuGet packages that depend on AWS.Lambda.Powertools.Metrics:
GitHub repositories (3)Showing the top 3 popular GitHub repositories that depend on AWS.Lambda.Powertools.Metrics:
Version Downloads Last Updated 2.1.1 158 7/29/2025 2.1.0 252 7/15/2025 2.0.0 27,282 3/7/2025 2.0.0-alpha1 11,605 10/21/2024 1.8.1-alpha 142 10/9/2024 1.7.1 138,195 7/12/2024 1.7.0-alpha3 123 7/14/2024 1.7.0-alpha2 107 7/12/2024 1.7.0-alpha 2,638 2/21/2024 1.6.2 9,736 5/23/2024 1.6.1 37,385 3/10/2024 1.6.0 22,851 2/16/2024 1.5.3 38,404 11/16/2023 1.4.3 1,580 10/30/2023 1.4.2 10,378 9/19/2023 1.3.3 3,832 8/22/2023 1.3.2 4,636 6/29/2023 1.3.1 40,540 6/21/2023 1.2.0 12,859 5/5/2023 1.1.0 210 5/5/2023 1.0.1 15,174 4/6/2023 1.0.0 3,888 2/24/2023 0.0.3-preview 143 9/18/2023 0.0.2-preview 253 1/18/2023 0.0.1-preview.1 4,908 8/1/2022Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4