• /
  • EnglishEspañol日本語한국어Português
  • Inicia sesiónComenzar ahora

initialize (Python agent API)

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

config_file

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 environment parameter.

environment

string

Optional. Indicates the name of the environment. If you are using a configuration file, you can override the settings in that file with environment.

ignore_errors

boolean

Optional. Indicates whether to ignore startup errors. Default is True.

log_file

string

Optional. Path to the agent log file. Also accepts stdout and stderr (same as the log_file option in the config file).

log_level

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 log_level option in config file.

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)
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.