in codeguru_profiler_agent/sdk_reporter/sdk_reporter.py [0:0]
def report(self, profile):
"""
Report profile to the profiler backend service.
:param profile: Profile to be encoded and reported to the profiler backend service.
:return: True if profile gets reported successfully; False otherwise.
Note:
For an agent running on AWS Lambda, if the environment variables for Profiling using
Lambda layers are set, it tries to create a Profiling Group whenever a ResourceNotFoundException
is encountered.
"""
try:
profile_stream = self._encode_profile(profile)
self.codeguru_client_builder.codeguru_client.post_agent_profile(
agentProfile=profile_stream,
contentType='application/json',
profilingGroupName=self.profiling_group_name
)
logger.info("Reported profile successfully")
return True
except ClientError as error:
if error.response['Error']['Code'] == 'ResourceNotFoundException':
if self.should_auto_create_profiling_group():
self.__class__.is_create_pg_called_during_submit_profile = True
self.errors_metadata.record_sdk_error("postAgentProfileRnfeAutoCreateEnabledErrors")
logger.info(
"Profiling group not found. Will try to create a profiling group "
"with name = {} and compute platform = {} and retry reporting during next invocation. "
"Make sure that Lambda's execution role has AmazonCodeGuruProfilerAgentAccess policy added."
.format(self.profiling_group_name, 'AWSLambda'))
self.create_profiling_group()
else:
self.errors_metadata.record_sdk_error("postAgentProfileErrors")
else:
self.errors_metadata.record_sdk_error("postAgentProfileErrors")
return False
except Exception as e:
self._log_request_failed(operation="post_agent_profile", exception=e)
return False