File tree Expand file tree Collapse file tree 4 files changed +18
-7
lines changed
main/java/software/amazon/lambda/powertools/metrics/internal
test/java/software/amazon/lambda/powertools/metrics/internal Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -111,11 +111,12 @@ Visit the AWS documentation for a complete explanation for [Amazon CloudWatch co
111111
112112Metrics has three global settings that will be used across all metrics emitted. Use your application or main service as the metric namespace to easily group all metrics:
113113
114- | Setting | Description | Environment variable | Decorator parameter |
115- | ------------------------------ | ------------------------------------------------------------------------------- | ------------------------------ | ------------------- |
116- | ** Metric namespace** | Logical container where all metrics will be placed e.g. ` ServerlessAirline ` | ` POWERTOOLS_METRICS_NAMESPACE ` | ` namespace ` |
117- | ** Service** | Optionally, sets ** service** metric dimension across all metrics e.g. ` payment ` | ` POWERTOOLS_SERVICE_NAME ` | ` service ` |
118- | ** Disable Powertools Metrics** | Optionally, disables all Powertools metrics | ` POWERTOOLS_METRICS_DISABLED ` | N/A |
114+ | Setting | Description | Environment variable | Decorator parameter |
115+ | ------------------------------ | ------------------------------------------------------------------------------- | ---------------------------------- | ------------------- |
116+ | ** Metric namespace** | Logical container where all metrics will be placed e.g. ` ServerlessAirline ` | ` POWERTOOLS_METRICS_NAMESPACE ` | ` namespace ` |
117+ | ** Service** | Optionally, sets ** service** metric dimension across all metrics e.g. ` payment ` | ` POWERTOOLS_SERVICE_NAME ` | ` service ` |
118+ | ** Function name** | Function name used as dimension for the cold start metric | ` POWERTOOLS_METRICS_FUNCTION_NAME ` | ` functionName ` |
119+ | ** Disable Powertools Metrics** | Optionally, disables all Powertools metrics | ` POWERTOOLS_METRICS_DISABLED ` | N/A |
119120
120121!!! tip "Use your application or main service as the metric namespace to easily group all metrics"
121122
Original file line number Diff line number Diff line change @@ -236,10 +236,11 @@ Use the following [dependency matrix](https://github.com/eclipse-aspectj/aspectj
236236 ** Explicit parameters take precedence over environment variables.**
237237
238238| Environment variable | Description | Utility |
239- | ---------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------- |
239+ | -------------------------------------- | -------------------------------------------------------------------------------------- | ------------------------- |
240240| ** POWERTOOLS_SERVICE_NAME** | Sets service name used for tracing namespace, metrics dimension and structured logging | All |
241241| ** POWERTOOLS_METRICS_NAMESPACE** | Sets namespace used for metrics | [ Metrics] ( ./core/metrics ) |
242- | ** POWERTOOLS_METRICS_DISABLED** | Disables all flushing of metrics | [ Metrics] ( ./core/metrics ) |
242+ | ** POWERTOOLS_METRICS_FUNCTION_NAME** | Function name used as dimension for the cold start metric | [ Metrics] ( ./core/metrics ) |
243+ | ** POWERTOOLS_METRICS_DISABLED** | Disables all flushing of metrics | [ Metrics] ( ./core/metrics ) |
243244| ** POWERTOOLS_LOGGER_SAMPLE_RATE** | Debug log sampling | [ Logging] ( ./core/logging ) |
244245| ** POWERTOOLS_LOG_LEVEL** | Sets logging level | [ Logging] ( ./core/logging ) |
245246| ** POWERTOOLS_LOGGER_LOG_EVENT** | Enables/Disables whether to log the incoming event when using the aspect | [ Logging] ( ./core/logging ) |
Original file line number Diff line number Diff line change @@ -37,11 +37,18 @@ public class LambdaMetricsAspect {
3737 public static final String TRACE_ID_PROPERTY = "xray_trace_id" ;
3838 public static final String REQUEST_ID_PROPERTY = "function_request_id" ;
3939 private static final String SERVICE_DIMENSION = "Service" ;
40+ private static final String FUNCTION_NAME_ENV_VAR = "POWERTOOLS_METRICS_FUNCTION_NAME" ;
4041
4142 private String functionName (Metrics metrics , Context context ) {
4243 if (!"" .equals (metrics .functionName ())) {
4344 return metrics .functionName ();
4445 }
46+
47+ String envFunctionName = System .getenv (FUNCTION_NAME_ENV_VAR );
48+ if (envFunctionName != null && !envFunctionName .isEmpty ()) {
49+ return envFunctionName ;
50+ }
51+
4552 return context != null ? context .getFunctionName () : null ;
4653 }
4754
Original file line number Diff line number Diff line change @@ -162,6 +162,7 @@ void shouldCaptureColdStartMetricWhenConfigured() throws Exception {
162162 }
163163
164164 @ Test
165+ @ SetEnvironmentVariable (key = "POWERTOOLS_METRICS_FUNCTION_NAME" , value = "EnvFunctionName" )
165166 void shouldNotIncludeServiceDimensionInColdStartMetricWhenServiceUndefined () throws Exception {
166167 // Given - no service name set, so it will use the default undefined value
167168 RequestHandler <Map <String , Object >, String > handler = new HandlerWithColdStartMetricsAnnotation ();
@@ -187,6 +188,7 @@ void shouldNotIncludeServiceDimensionInColdStartMetricWhenServiceUndefined() thr
187188
188189 // FunctionName dimension should be present
189190 assertThat (coldStartNode .has ("FunctionName" )).isTrue ();
191+ assertThat (coldStartNode .get ("FunctionName" ).asText ()).isEqualTo ("EnvFunctionName" );
190192 }
191193
192194 @ Test
You can’t perform that action at this time.
0 commit comments