Our Python agent lets you change the default agent behavior agent using configuration options.
The only required Python agent configuration setting is the license key. The license key identifies the account where the agent reports application data. Depending on how you are hosting your application, the license key can be provided via a configuration file or an environment variable.
The primary way to configure the Python agent is via the configuration file, which is generated as part of the standard install process. It is also possible to set a limited number of configuration options using server-side configuration in the UI or by using environment variables. You can also specify some settings on a per-request basis by passing settings with the WSGI request environ dictionary.
The Python agent follows this order of precedence for configuration:
With the Python agent, per-request options override server-side config. If enabled, server-side config overrides all corresponding values in the agent config file, even if the server-side values are left blank. The agent config file overrides environment variables. Environment variables override the agent defaults.
Here are detailed descriptions of each configuration method:
The agent reads its primary configuration from an agent config section called
newrelic. You can provide overrides for specific deployment environments (for example, Development, Staging, Production) in additional sections. Preface these sections with
environment is replaced with the name of your environment.
To specify that the agent should use an environment-based configuration, use one of these methods:
When you call
newrelic.agent.initialize(), provide the environment name as the second argument.
NEW_RELIC_ENVIRONMENTenvironment variable to the environment name.
If no environment is specified, the agent will use the default settings as specified in the
newrelic agent config section.
The basic structure of the configuration file is:
[newrelic] ... default settings [newrelic:development] ... override settings [newrelic:staging] ... override settings [newrelic:production] ... override settings
These settings are available in the agent configuration file.
Attributes are key-value pairs that provide information for transaction traces, traced errors, browser monitoring, and transaction events. In addition to configuring attributes for all four destinations with the general attribute settings below, they can also be configured on a per-destination basis.
Do not use brackets
[suffix] at the end of your transaction name. The agent automatically strips brackets from the name. Instead, use parentheses
(suffix) or other symbols if needed.
For more information about transaction traces, see Transaction traces.
Here are Transaction segment settings available via the agent configuration file.
Here are error collector settings available via the agent configuration file.
For an overview of error configuration in APM, see Manage errors in APM.
Here are browser monitoring settings available via the agent configuration file.
Here are Transaction events settings available via the agent configuration file.
These configuration settings used to be called
analytic_events. If your configuration file still uses
analytic_events, update your agent to use
Here are custom events settings available via the agent configuration file.
These datastore tracer settings are available via the agent configuration file:
Starting in Python agent version 184.108.40.206 or higher, distributed tracing is enabled by default.
Distributed tracing lets you see the path that a request takes as it travels through a distributed system. Settings include:
Event harvest settings limit the amount of event type data sent to New Relic. When you use these settings, consider these important points:
- Event harvest settings affect the limits for a single instance of the agent, and not across the entire application. See the usage example below for how to set limits across an entire application.
- Real time streaming sends data every five seconds (12 times per minute), but the event harvest settings still affect the rate in events per minute. Enabling or disabling real time streaming does not require changing these settings.
- With real time streaming (enabled by default), New Relic will display the event harvest limits for entities in five second intervals. This means, for example, when you set a limit value of 1200 in the config file, you'll see it as 100 in New Relic.
Let's say an application is deployed across 10 hosts, each running four processes per host. To limit the number of span events to 10,000 events per minute for the entire application, divide that number by 10 hosts. Then divide again by four processes per host.
10000 / (10 * 4) = 250
Based on that calculation, the final setting is:
event_harvest_config.harvest_limits.span_event_data = 250
Event harvest configuration settings include:
Requires Python agent version 220.127.116.11 or higher.
Event loop visibility surfaces information about transactions that block the event loop. The agent will generate information about transactions that have waited a significant amount of time to acquire control of the event loop. Settings include:
Requires Python agent version 18.104.22.168 or higher.
These garbage collection runtime metrics settings are available via the agent configuration file:
Here are assorted other settings available via the agent configuration file.
The Python agent instruments a range of Python packages/modules. This instrumentation only occurs when the target Python package/module is imported by an application.
To disable default instrumentation, provide a special
import-hook section corresponding to the name of the module that triggered instrumentation. Then set the
enabled setting to
false to disable instrumentation of that module.
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.