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

No data going to APM (Python)


#1

When I run a manage command I don’t get activity in New Relic.

I used newrelic-admin validate-config and I saw data

I have tried various things but I don’t get data into APM

newrelic.agent.initialize('/var/www/code/catalogue_app/newrelic.ini', 'grantdev', ignore_errors=False, log_level=logging.DEBUG)
application = newrelic.agent.register_application(timeout=10.0)


event_type = "Killed_Query"
params = {'query_info': 'select * from all_things;', 'killed_time': '2016-05-18 00:59:00', 'host': 'my_host'}
newrelic.agent.record_custom_event(event_type, params, application=application)

I get the custom event data but that is it

I run this command

NEW_RELIC_ENVIRONMENT=grantdev NEW_RELIC_CONFIG_FILE=/var/www/code/catalogue_app/newrelic.ini /var/www/venv/bin/newrelic-admin run-python manage.py push_to_shop --settings=catalogue_app.settings.development_settings

The log file does’t give errors, it suggest that data is being collected.

Am I missing something

Thanks

Grant


#2

Hi Grant,

From what you have provided it looks like you’re trying to record a background transaction, is that correct? If that’s the case, you should use the background_task decorator. This Python decorator can be used to instrument background tasks or other non-web transactions.

This is typically used to instrument non-web activity like worker processes, job-based systems, and standalone scripts. Transactions marked as background tasks are displayed as non-web transactions in the APM UI and separated from web transactions.

Here’s an example of using the decorator:

@newrelic.agent.background_task()
def push_to_shop():
    ...

Refer to the background_task API method for more information.

Hope that helps you! :slight_smile:


#3

That was it, I did this in the end

import newrelic.agent
newrelic.agent.initialize(settings.NEW_RELIC_INI_PATH, settings.NEW_RELIC_APP, ignore_errors=False)
@newrelic.agent.background_task(application=None)
def push_to_shop():

Thanks

Grant


#4

Happy to hear that @grant.donovan! :slight_smile: