@@ -65,18 +65,18 @@ You can initialize Metrics anywhere in your code as many times as you need - It'
65
65
66
66
You can create metrics using ` putMetric ` , and manually create dimensions for all your aggregate metrics using ` add_dimension ` .
67
67
68
- ``` java:title=app.py
68
+ ``` java:title=Handler.java
69
69
public class PowertoolsMetricsEnabledHandler implements RequestHandler<Object , Object > {
70
70
71
71
MetricsLogger metricsLogger = PowertoolsMetricsLogger . metricsLogger();
72
72
73
73
@Override
74
74
@PowertoolsMetrics (namespace = " ExampleApplication" , service = " booking" )
75
75
public Object handleRequest (Object input , Context context ) {
76
- # highlight-start
76
+ // highlight-start
77
77
metricsLogger. putDimensions(DimensionSet . of(" environment" , " prod" ));
78
78
metricsLogger. putMetric(" SuccessfulBooking" , 1 , Unit . COUNT );
79
- # highlight-end
79
+ // highlight-end
80
80
...
81
81
}
82
82
}
@@ -110,13 +110,13 @@ You can use `putMetadata` for advanced use cases, where you want to metadata as
110
110
<strong >This will not be available during metrics visualization</strong > - Use <strong >dimensions</strong > for this purpose
111
111
</Note ><br />
112
112
113
- ``` javv :title=Handler.java
113
+ ``` java :title=Handler.java
114
114
@PowertoolsMetrics (namespace = " ServerlessAirline" , service = " payment" )
115
115
public APIGatewayProxyResponseEvent handleRequest(Object input, Context context) {
116
116
metricsLogger(). putMetric(" CustomMetric1" , 1 , Unit . COUNT );
117
- metricsLogger(). putMetadata(" booking_id" , " 1234567890" ); # highlight- line
118
-
117
+ metricsLogger(). putMetadata(" booking_id" , " 1234567890" ); // highlight-line
119
118
...
119
+ }
120
120
```
121
121
122
122
This will be available in CloudWatch Logs to ease operations on high cardinal data.
@@ -131,19 +131,21 @@ If metrics are provided, and any of the following criteria are not met, `Validat
131
131
If you want to ensure that at least one metric is emitted, you can pass ` raiseOnEmptyMetrics = true ` to the ** @PowertoolsMetrics ** annotation:
132
132
133
133
``` java:title=Handler.java
134
- @PowertoolsMetrics (raiseOnEmptyMetrics = true )
135
- public Object handleRequest(Object input, Context context) {
136
- ...
134
+ @PowertoolsMetrics (raiseOnEmptyMetrics = true )
135
+ public Object handleRequest(Object input, Context context) {
136
+ ...
137
+ }
137
138
```
138
139
139
140
## Capturing cold start metric
140
141
141
142
You can capture cold start metrics automatically with ` @PowertoolsMetrics ` via the ` captureColdStart ` variable.
142
143
143
144
``` java:title=Handler.java
144
- @PowertoolsMetrics (captureColdStart = true )
145
- public Object handleRequest(Object input, Context context) {
146
- ...
145
+ @PowertoolsMetrics (captureColdStart = true )
146
+ public Object handleRequest(Object input, Context context) {
147
+ ...
148
+ }
147
149
```
148
150
149
151
If it's a cold start invocation, this feature will:
0 commit comments