@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface Metrics
Metrics is used to signal that the annotated method should be
extended with Metrics functionality.
Metrics allows users to asynchronously create Amazon
CloudWatch metrics by using the CloudWatch Embedded Metrics Format.
Metrics manages the life-cycle of the MetricsLogger class,
to simplify the user experience when used with AWS Lambda.
Metrics should be used with the handleRequest method of a class
which implements either
com.amazonaws.services.lambda.runtime.RequestHandler or
com.amazonaws.services.lambda.runtime.RequestStreamHandler.
Metrics creates Amazon CloudWatch custom metrics. You can find
pricing information on the CloudWatch pricing documentation page.
To enable creation of custom metrics for cold starts you can add @Metrics(captureColdStart = true).
This will create a metric with the key "ColdStart" and the unit type COUNT.
To raise exception if no metrics are emitted, use @Metrics(raiseOnEmptyMetrics = true).
This will create a create a exception of type ValidationException. By default its value is set to false.
By default the service name associated with metrics created will be
"service_undefined". This can be overridden with the environment variable POWERTOOLS_SERVICE_NAME
or the annotation variable @Metrics(service = "Service Name").
If both are specified then the value of the annotation variable will be used.
By default the namespace associated with metrics created will be "aws-embedded-metrics".
This can be overridden with the environment variable POWERTOOLS_METRICS_NAMESPACE
or the annotation variable @Metrics(namespace = "Namespace").
If both are specified then the value of the annotation variable will be used.
| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
captureColdStart |
java.lang.String |
namespace |
boolean |
raiseOnEmptyMetrics |
java.lang.String |
service |
Copyright © 2022. All rights reserved.