Syntax
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.
Description
This is called to initialize the Python agent with a specified configuration file when the agent is being manually integrated with a Python application.
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 with the NEW_RELIC_LICENSE_KEY
environment variable. Alternatively, you can set NEW_RELIC_CONFIG_FILE
and NEW_RELIC_ENVIRONMENT
. The agent will then read those values in place of the missing arguments.
Parameters
Parameter | Description |
---|---|
string | 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 |
string | Optional. Indicates the name of the environment. If you are using a configuration file, you can override the settings in that file with |
boolean | Optional. Indicates whether to ignore startup errors. Default is |
string | Optional. Path to the agent log file. Also accepts |
int or applicable logging parameter type | Optional. Sets the logging level. The agent uses Python's logging module. Options are the same as for the |
Return values
None.
Examples
Initializing with config file and environment
Here's an example of initializing the Python agent with a config file and an environment string:
newrelic.agent.initialize('/etc/newrelic/newrelic.ini', 'production')
Using all parameter values
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)