@@ -94,35 +94,7 @@ public Object around(ProceedingJoinPoint pjp,
9494 LambdaHandlerProcessor .getXrayTraceId ()
9595 .ifPresent (traceId -> metricsInstance .addMetadata (TRACE_ID_PROPERTY , traceId ));
9696
97- Context extractedContext = extractContext (pjp );
98-
99- if (null != extractedContext ) {
100- metricsInstance .addMetadata (REQUEST_ID_PROPERTY , extractedContext .getAwsRequestId ());
101-
102- // Only capture cold start metrics if configured
103- if (metrics .captureColdStart ()) {
104- // Get function name from annotation or context
105- String funcName = functionName (metrics , extractedContext );
106-
107- DimensionSet coldStartDimensions = new DimensionSet ();
108-
109- // Get service name from metrics instance default dimensions or fallback
110- String serviceName = metricsInstance .getDefaultDimensions ().getDimensions ().getOrDefault (
111- SERVICE_DIMENSION ,
112- serviceNameWithFallback (metrics ));
113-
114- // Only add service if it is not undefined
115- if (!LambdaConstants .SERVICE_UNDEFINED .equals (serviceName )) {
116- coldStartDimensions .addDimension (SERVICE_DIMENSION , serviceName );
117- }
118-
119- // Add function name
120- coldStartDimensions .addDimension ("FunctionName" ,
121- funcName != null ? funcName : extractedContext .getFunctionName ());
122-
123- metricsInstance .captureColdStartMetric (extractedContext , coldStartDimensions );
124- }
125- }
97+ captureColdStartMetricIfEnabled (extractContext (pjp ), metrics );
12698
12799 try {
128100 return pjp .proceed (proceedArgs );
@@ -134,4 +106,37 @@ public Object around(ProceedingJoinPoint pjp,
134106
135107 return pjp .proceed (proceedArgs );
136108 }
109+
110+ private void captureColdStartMetricIfEnabled (Context extractedContext , FlushMetrics metrics ) {
111+ if (extractedContext == null ) {
112+ return ;
113+ }
114+
115+ Metrics metricsInstance = MetricsFactory .getMetricsInstance ();
116+ metricsInstance .addMetadata (REQUEST_ID_PROPERTY , extractedContext .getAwsRequestId ());
117+
118+ // Only capture cold start metrics if enabled on annotation
119+ if (metrics .captureColdStart ()) {
120+ // Get function name from annotation or context
121+ String funcName = functionName (metrics , extractedContext );
122+
123+ DimensionSet coldStartDimensions = new DimensionSet ();
124+
125+ // Get service name from metrics instance default dimensions or fallback
126+ String serviceName = metricsInstance .getDefaultDimensions ().getDimensions ().getOrDefault (
127+ SERVICE_DIMENSION ,
128+ serviceNameWithFallback (metrics ));
129+
130+ // Only add service if it is not undefined
131+ if (!LambdaConstants .SERVICE_UNDEFINED .equals (serviceName )) {
132+ coldStartDimensions .addDimension (SERVICE_DIMENSION , serviceName );
133+ }
134+
135+ // Add function name
136+ coldStartDimensions .addDimension ("FunctionName" ,
137+ funcName != null ? funcName : extractedContext .getFunctionName ());
138+
139+ metricsInstance .captureColdStartMetric (extractedContext , coldStartDimensions );
140+ }
141+ }
137142}
0 commit comments