newrelic.agent.initialize(config_file=None, environment=None, ignore_errors=None, log_file=None, log_level=None)
Initializes the Python agent with a specified config file during a manual integration process.
For best instrumentation results, make this call as early as possible in your app code. Unlike typical Python functionality, the order of import matters. For WSGI and application script files, place the
initialize call before all imports, with the exception of the
sys import and updates to the
sys.path. If you call
initialize multiple times, the agent ignores calls after the first if the configuration file and environment options are the same. If the options differ, an exception is raised.
If you call
initialize with no arguments, you must have already specified your license key with the
NEW_RELIC_LICENSE_KEY environment variable. Alternatively, you can set
NEW_RELIC_ENVIRONMENT. The agent will then read those values in place of the missing arguments.
Optional. The path to the agent config file. If you supply a configuration file, you can override elements of that config file with the optional
Optional. Indicates the name of the environment. If you are using a configuration file, you can override the settings in that file with
Optional. Indicates whether to ignore startup errors. Default is
Optional. Path to the agent log file. Also accepts
int or applicable logging parameter type
Here's an example of initializing the Python agent with a config file and an environment string:
Calling with all parameter values:
newrelic.agent.initialize('/etc/newrelic/newrelic.ini', 'production', ignore_errors=False, log_file='/var/log/newrelic.log', log_level=logging.DEBUG)
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.