newrelic/newrelic-python-agent

Agent could not initialize properly

Closed this issue · 3 comments

Description
Agent could not initialize properly due to an error when loading .ini configuration file.

     newrelic.agent.initialize(
   File "/usr/local/lib/python3.12/site-packages/newrelic/config.py", line 4803, in initialize
     _load_configuration(config_file, environment, ignore_errors, log_file, log_level)
   File "/usr/local/lib/python3.12/site-packages/newrelic/config.py", line 1027, in _load_configuration
     if config_file.endswith(".toml"):
        ^^^^^^^^^^^^^^^^^^^^
 AttributeError: 'PosixPath' object has no attribute 'endswith'

Your Environment
Python 3.12
newrelic 10.3.1

Are you manually calling newrelic.initialize() with a config file set as some PosixPath object? Or is this happening while using the newrelic-admin wrapper script?

After upgrading the New Relic Python Agent from version 10.2.0 to 10.3.1, the application initialization setup in my wsgi.py file no longer works as expected. The same setup works perfectly in version 10.2.0. Here’s the relevant part of my wsgi.py file:

from django.conf import settings
import newrelic.agent
from pathlib import Path

# Get New Relic license key from .env file
NEW_RELIC_LICENSE_KEY = settings.NEW_RELIC_LICENSE_KEY

# Initialize New Relic agent from config file and set environment (staging/prod)
config_file = Path(__file__).resolve().parent.parent.parent / "newrelic.ini"

newrelic.agent.initialize(
    config_file=config_file, environment=settings.NEW_RELIC_ENVIRONMENT
)

# Register New Relic application monitoring
newrelic.agent.register_application()