1515logger = logging .getLogger (__name__ )
1616AWS_EXECUTION_ENV_KEY = "AWS_EXECUTION_ENV"
1717
18+
1819class SdkReporter (Reporter ):
1920 """
2021 Handles communication with the CodeGuru Profiler Service backend.
2122 Encodes profiles using the ProfilerEncoder and reports them using the CodeGuru profiler SDK.
2223 """
2324 is_create_pg_called_during_submit_profile = False
25+
2426 def __init__ (self , environment ):
2527 """
2628 :param environment: dependency container dictionary for the current profiler.
@@ -35,6 +37,7 @@ def __init__(self, environment):
3537 self .timer = environment .get ("timer" )
3638 self .metadata = environment ["agent_metadata" ]
3739 self .agent_config_merger = environment ["agent_config_merger" ]
40+ self .errors_metadata = environment ["errors_metadata" ]
3841
3942 def _encode_profile (self , profile ):
4043 output_profile_stream = io .BytesIO ()
@@ -76,18 +79,23 @@ def refresh_configuration(self):
7679 # We handle service exceptions like this in boto3
7780 # see https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html
7881 if error .response ['Error' ]['Code' ] == 'ValidationException' :
82+ self .errors_metadata .record_sdk_error ("configureAgentErrors" )
7983 self .agent_config_merger .disable_profiling ()
8084 self ._log_request_failed (operation = "configure_agent" , exception = error )
81- if error .response ['Error' ]['Code' ] == 'ResourceNotFoundException' :
85+ elif error .response ['Error' ]['Code' ] == 'ResourceNotFoundException' :
8286 if self .should_auto_create_profiling_group ():
87+ self .errors_metadata .record_sdk_error ("configureAgentRnfeAutoCreateEnabledErrors" )
8388 logger .info (
8489 "Profiling group not found. Will try to create a profiling group "
8590 "with name = {} and compute platform = {} and retry calling configure agent after 5 minutes. "
8691 "Make sure that Lambda's execution role has AmazonCodeGuruProfilerAgentAccess policy added."
8792 .format (self .profiling_group_name , 'AWSLambda' ))
8893 self .create_profiling_group ()
8994 else :
95+ self .errors_metadata .record_sdk_error ("configureAgentErrors" )
9096 self .agent_config_merger .disable_profiling ()
97+ else :
98+ self .errors_metadata .record_sdk_error ("configureAgentErrors" )
9199 except Exception as e :
92100 self ._log_request_failed (operation = "configure_agent" , exception = e )
93101
@@ -117,12 +125,17 @@ def report(self, profile):
117125 if error .response ['Error' ]['Code' ] == 'ResourceNotFoundException' :
118126 if self .should_auto_create_profiling_group ():
119127 self .__class__ .is_create_pg_called_during_submit_profile = True
128+ self .errors_metadata .record_sdk_error ("postAgentProfileRnfeAutoCreateEnabledErrors" )
120129 logger .info (
121130 "Profiling group not found. Will try to create a profiling group "
122131 "with name = {} and compute platform = {} and retry reporting during next invocation. "
123132 "Make sure that Lambda's execution role has AmazonCodeGuruProfilerAgentAccess policy added."
124133 .format (self .profiling_group_name , 'AWSLambda' ))
125134 self .create_profiling_group ()
135+ else :
136+ self .errors_metadata .record_sdk_error ("postAgentProfileErrors" )
137+ else :
138+ self .errors_metadata .record_sdk_error ("postAgentProfileErrors" )
126139 return False
127140 except Exception as e :
128141 self ._log_request_failed (operation = "post_agent_profile" , exception = e )
@@ -143,6 +156,8 @@ def create_profiling_group(self):
143156 if error .response ['Error' ]['Code' ] == 'ConflictException' :
144157 logger .info ("Profiling Group with name {} already exists. Please use a different name."
145158 .format (self .profiling_group_name ))
159+ else :
160+ self .errors_metadata .record_sdk_error ("createProfilingGroupErrors" )
146161 except Exception as e :
147162 self ._log_request_failed (operation = "create_profiling_group" , exception = e )
148163
0 commit comments