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

Relic Solution: Record Custom Event Troubleshooting



With our Python Agent API, the record_custom_event API method records a custom event that can be viewed and queried in Insights. This post will provide some troubleshooting steps you can take if the event is not appearing in Insights.

In some cases, the Python Agent will log if there is an issue with recording the event. For example, if an integer is passed instead of a required string, the Python Agent will log that the custom event was dropped:

2018-01-18 14:11:37,223 (20343/MainThread) newrelic.core.custom_event DEBUG - Event type must be a string. Dropping event: 1

The easiest way to get the Python agent to write to a log is to edit the newrelic.ini and uncomment the line: log_file = /tmp/newrelic-python-agent.log then follow these steps:

  1. Change the log_level setting to debug.
  2. Restart your app server, retry sending the custom event and examine the log file for any entries that could indicate the reason for the event not sending.

NOTE: As these logs are highly verbose, once you’ve finished gathering logs for us, don’t forget to reset the log_level to info and restart your app server again to pick up the change. You can read more about Python agent logging here.

Another reason for events not sending is that the API method is being called outside of a Transaction. In this case it is necessary to pass an application object to record_custom_event. For example:

import newrelic.agent

app = newrelic.agent.register_application()

newrelic.agent.record_custom_event('MyCustomEvent', {}, application=app)

Another reason why a custom event may fail to send is that your script executes really quickly and our Python agent does not have enough time to register. In this case, you can add startup_timeout and shutdown_timeout to your newrelic.ini file, for example:

startup_timeout = 10.0
shutdown_timeout = 10.0

startup_timeout adds a delay in the time it takes the agent to register before executing your script. shutdown_timeout will allow the agent to shutdown gracefully ensuring data is sent. Adding a value of 10 for the startup_timeout doesn’t necessarily mean that the agent will add 10 seconds to the time of your script. It means it will wait for a maximum of 10 seconds before executing your script. The same applies for the shutdown_timeout setting.

In most cases, the agent will exit well within that time. This setting is useful if you have a script that executes quickly and want to ensure that your data gets sent! For more information on this, refer to the Python agent configuration documentation.

I hope you find this useful! :slight_smile: