-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathMetricsLoggerHelper.java
35 lines (27 loc) · 1.06 KB
/
MetricsLoggerHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package software.amazon.cloudwatchlogs.emf.model;
import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException;
import java.lang.reflect.Field;
import static software.amazon.lambda.powertools.metrics.MetricsUtils.metricsLogger;
public final class MetricsLoggerHelper {
private MetricsLoggerHelper() {
}
public static boolean hasNoMetrics() {
return metricsContext().getRootNode().getAws().isEmpty();
}
public static long dimensionsCount() {
try {
return metricsContext().getDimensions().size();
} catch (DimensionSetExceededException e) {
throw new RuntimeException("Too many dimensions defined", e);
}
}
public static MetricsContext metricsContext() {
try {
Field f = metricsLogger().getClass().getDeclaredField("context");
f.setAccessible(true);
return (MetricsContext) f.get(metricsLogger());
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}