You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
requireNonNull(dimensionSet, "Null dimension set not allowed");
76
-
77
-
if (dimensionSet.getDimensionKeys().size() > 0) {
78
-
defaultDimensions(dimensionSet);
79
-
}
80
-
}
81
-
82
-
83
67
/**
84
68
* Add and immediately flush a single metric. It will use the default namespace
85
69
* specified either on {@link Metrics} annotation or via POWERTOOLS_METRICS_NAMESPACE env var.
@@ -95,11 +79,20 @@ public static void withSingleMetric(final String name,
95
79
finaldoublevalue,
96
80
finalUnitunit,
97
81
finalConsumer<MetricsLogger> logger) {
98
-
withMetricsLogger(metricsLogger ->
99
-
{
82
+
MetricsLoggermetricsLogger = logger();
83
+
84
+
try {
85
+
metricsLogger.setNamespace(defaultNameSpace());
100
86
metricsLogger.putMetric(name, value, unit);
87
+
captureRequestAndTraceId(metricsLogger);
101
88
logger.accept(metricsLogger);
102
-
});
89
+
} catch (InvalidNamespaceExceptione) {
90
+
thrownewRuntimeException("A valid namespace is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_METRICS_NAMESPACE", e);
91
+
} catch (InvalidMetricExceptione) {
92
+
thrownewRuntimeException(e);
93
+
} finally {
94
+
metricsLogger.flush();
95
+
}
103
96
}
104
97
105
98
/**
@@ -118,12 +111,20 @@ public static void withSingleMetric(final String name,
118
111
finalUnitunit,
119
112
finalStringnamespace,
120
113
finalConsumer<MetricsLogger> logger) {
121
-
withMetricsLogger(metricsLogger ->
122
-
{
114
+
MetricsLoggermetricsLogger = logger();
115
+
116
+
try {
123
117
metricsLogger.setNamespace(namespace);
124
118
metricsLogger.putMetric(name, value, unit);
119
+
captureRequestAndTraceId(metricsLogger);
125
120
logger.accept(metricsLogger);
126
-
});
121
+
} catch (InvalidNamespaceExceptione) {
122
+
thrownewRuntimeException("A valid namespace is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_METRICS_NAMESPACE", e);
thrownewRuntimeException("A valid namespace is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_METRICS_NAMESPACE", e);
144
147
} finally {
145
148
metricsLogger.flush();
146
149
}
147
150
}
148
151
149
-
/**
150
-
* Provide and immediately flush a {@link MetricsLogger}. It uses the default namespace
151
-
* specified either on {@link Metrics} annotation or via POWERTOOLS_METRICS_NAMESPACE env var.
152
-
* It by default captures function_request_id as property if used together with {@link Metrics} annotation. It will also
153
-
* capture xray_trace_id as property if tracing is enabled.
154
-
*
155
-
* @param logger the MetricsLogger
156
-
* @deprecated use {@link MetricsUtils#withMetricsLogger} instead
Copy file name to clipboardExpand all lines: powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/internal/LambdaMetricsAspect.java
thrownewRuntimeException("A valid service is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_SERVICE_NAME", e);
thrownewRuntimeException("A valid namespace is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_METRICS_NAMESPACE", e);
thrownewRuntimeException("A valid service is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_SERVICE_NAME", e);
Copy file name to clipboardExpand all lines: powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/handlers/PowertoolsMetricsColdStartEnabledHandler.java
0 commit comments