Skip to content

Commit 83e390b

Browse files
author
Pankaj Agrawal
committed
docs: clarify docs about default dimensions
1 parent f691dcb commit 83e390b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/core/metrics.md

+29
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,35 @@ You can use `putMetadata` for advanced use cases, where you want to metadata as
183183

184184
This will be available in CloudWatch Logs to ease operations on high cardinal data.
185185

186+
## Overriding default dimension set
187+
188+
By default, all metrics emitted via module captures `Service` as one of the default dimension. This is either specified via
189+
`POWERTOOLS_SERVICE_NAME` environment variable or via `service` attribute on `Metrics` annotation. If you wish to override the default
190+
Dimension, it can be done via `#!java MetricsUtils.defaultDimensionSet()`.
191+
192+
=== "App.java"
193+
194+
```java hl_lines="8 9 10"
195+
import software.amazon.lambda.powertools.metrics.Metrics;
196+
import static software.amazon.lambda.powertools.metrics.MetricsUtils;
197+
198+
public class App implements RequestHandler<Object, Object> {
199+
200+
MetricsLogger metricsLogger = MetricsUtils.metricsLogger();
201+
202+
static {
203+
MetricsUtils.defaultDimensionSet(DimensionSet.of("CustomDimension", "booking"));
204+
}
205+
206+
@Override
207+
@Metrics(namespace = "ExampleApplication", service = "booking")
208+
public Object handleRequest(Object input, Context context) {
209+
...
210+
MetricsUtils.withSingleMetric("Metric2", 1, Unit.COUNT, log -> {});
211+
}
212+
}
213+
```
214+
186215
## Creating a metric with a different dimension
187216

188217
CloudWatch EMF uses the same dimensions across all your metrics. Use `withSingleMetric` if you have a metric that should have different dimensions.

0 commit comments

Comments
 (0)