Enabling the agent with code - Amazon CodeGuru Profiler

Enabling the agent with code

If your application runs on a platform other than Lambda, install codeguru_profiler_agent through pip.

pip install codeguru_profiler_agent

You can configure the agent by passing different parameters to the Profiler object.

Option Constructor argument Details

Profiling group name (required)

profiling_group_name="MyProfilingGroup"

The name of the profiling group to send the data into. The Profiling group must exist.

Region

region_name="eu-west-2"

Use this if your application is not running in the same region as the one where the profiling group was created.

AWS session

aws_session=boto3.session.Session()

The session object that should be used to target the CodeGuru Profiler backends. Use this if you want to use different credentials or region than the default one. See boto3 session for more information.

Start the agent from one place in your application. We recommend you start the agent in your startup code. Only one Profiler object can be started at the time. The following is a runtime example.

from codeguru_profiler_agent import Profiler from boto3.session import Session ... custom_session = Session(profile_name='dev', region_name='us-east-1') Profiler(profiling_group_name='MyProfilingGroup', aws_session=custom_session).start() start_application() ...

You can find the sample code for the following examples in Amazon CodeGuru Profiler Python Demo Applications.

The following is an example of a simple application that sets your profiling group name to MyProfilingGroup.

from codeguru_profiler_agent import Profiler if __name__ == '__main__': Profiler(profiling_group_name='MyProfilingGroup').start() start_application()

Supported web components

The following topics provide code that you can add to your application to enable the Amazon CodeGuru Profiler agent.

Topics