Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

The Python Agent is not enabled

insights

#1

Hello everyone,

I have new relic as an add-on on Heroku, my app’s framework is Flask. I am trying to send custom events on my background jobs so I can chart them on Insights.

Here’s the sample script I am playing around.

import newrelic.agent


@newrelic.agent.background_task()
def complete_sync():
    app = newrelic.agent.application()
    s = newrelic.agent.record_custom_event('inventory_image', {}, application=app)
    print(s)

Whenever I execute that, I get this error:

2018-11-17T14:12:33.735287+00:00 app[worker.1]: 2018-11-17 14:12:33,735 (28/MainThread) newrelic.core.agent INFO - New Relic Python Agent (4.4.0.103)

2018-11-17T14:12:33.736981+00:00 app[worker.1]: 2018-11-17 14:12:33,736 (28/MainThread) newrelic.core.agent WARNING - The Python Agent is not enabled.

I also tried running this command :
heroku run newrelic-admin validate-config - stdout

But gave me the following errors.

  File "/app/.heroku/python/bin/newrelic-admin", line 11, in <module>
    load_entry_point('newrelic==4.4.0.103', 'console_scripts', 'newrelic-admin')()
  File "/app/.heroku/python/lib/python2.7/site-packages/newrelic/admin/__init__.py", line 140, in main
    callback(sys.argv[2:])
  File "/app/.heroku/python/lib/python2.7/site-packages/newrelic/admin/validate_config.py", line 162, in validate_config
    log_file=log_file, log_level=log_level)
  File "/app/.heroku/python/lib/python2.7/site-packages/newrelic/config.py", line 2753, in initialize
    log_file, log_level)
  File "/app/.heroku/python/lib/python2.7/site-packages/newrelic/config.py", line 922, in _load_configuration
    'Unable to open configuration file %s.' % config_file)
newrelic.api.exceptions.ConfigurationError: Unable to open configuration file stdout.

Any idea what’s going on here? I have the license key as an Environment Variable on Heroku and am successfully receiving data on my APM overview page.
Thanks!


#2

Hello!

I noticed your application is missing a few key components. You will need to initialize and register_application. Below you can find a snippet of code that should work for you. Let me know if this solves your issue!

import newrelic.agent
newrelic.agent.initialize()
app = newrelic.agent.register_application(timeout=10.0)

@newrelic.agent.background_task()
def complete_sync():
    s = newrelic.agent.record_custom_event('inventory_image', {}, application=app)
    print(s)

Thanks,
Robert