Skip to content

Commit e0df19b

Browse files
committed
Add example for overwriting dimension of cold start metric.
1 parent 36dd713 commit e0df19b

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

docs/core/metrics.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,15 @@ Metrics has two global settings that will be used across all metrics emitted. Us
118118

119119
!!! tip "Use your application or main service as the metric namespace to easily group all metrics"
120120

121-
<!-- prettier-ignore-start -->
122-
!!!info "Order of Precedence of `MetricsLogger` configuration"
123-
The `MetricsLogger` Singleton can be configured by three different interfaces. The following order of precedence applies:
121+
### Order of Precedence of `MetricsLogger` configuration
124122

125-
1. `@Metrics` annotation (recommended)
126-
2. `MetricsLoggerBuilder` using Builder pattern (see [Advanced section](#usage-without-metrics-annotation))
127-
3. Environment variables (recommended)
123+
The `MetricsLogger` Singleton can be configured by three different interfaces. The following order of precedence applies:
128124

129-
For most use-cases, we recommend using Environment variables and only overwrite settings in code where needed using either the `@Metrics` annotation or `MetricsLoggerBuilder` if the annotation cannot be used.
130-
<!-- prettier-ignore-end -->
125+
1. `@Metrics` annotation
126+
2. `MetricsLoggerBuilder` using Builder pattern (see [Advanced section](#usage-without-metrics-annotation))
127+
3. Environment variables (recommended)
128+
129+
For most use-cases, we recommend using Environment variables and only overwrite settings in code where needed using either the `@Metrics` annotation or `MetricsLoggerBuilder` if the annotation cannot be used.
131130

132131
=== "template.yaml"
133132

@@ -302,6 +301,25 @@ You can also specify a custom function name to be used in the cold start metric:
302301
}
303302
```
304303

304+
<!-- prettier-ignore-start -->
305+
!!!tip "You can overwrite the default `Service` and `FunctionName` dimensions of the cold start metric"
306+
Set `#!java @Metrics(captureColdStart = false)` and use the `captureColdStartMetric` method manually:
307+
308+
```java hl_lines="6 8"
309+
public class MetricsColdStartCustomFunction implements RequestHandler<Object, Object> {
310+
311+
private static final MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
312+
313+
@Override
314+
@Metrics(captureColdStart = false)
315+
public Object handleRequest(Object input, Context context) {
316+
metricsLogger.captureColdStartMetric(context, DimensionSet.of("CustomDimension", "CustomValue"));
317+
...
318+
}
319+
}
320+
```
321+
<!-- prettier-ignore-end -->
322+
305323
## Advanced
306324

307325
### Adding metadata

0 commit comments

Comments
 (0)