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

MySQL track exceptions

mysql

#1

I’ve got 2 databases running on a MySQL 5.7 database which runs triggers across both to update the data on the other. When there is an issue we throw a MySQL exception, but I can’t see an obvious way to track that in NewRelic?


#2

Hey @matthew.augier - to best help here I’d like to clarify a couple of things.

Can you share details of the environment you are working with here? Is your DB hooked up to an application being monitored in New Relic APM?

Are the exceptions you are throwing from the DB handled? (New Relic by default only captures unhandled exceptions).

Is there any additional information you can add on the parameters you are hoping to track in New Relic?


#3

Yes the DB is hooked up to a PHP app, however for migrations we will be running a conversion by CLI using bash scripts.

We are handling the exceptions manually (in each trigger/procedure) todecide if they should continue or not… When we hit an error then I was hoping to log the issue to new relic manually? We are trying various solutions, at present a session strack trace in a JSON variable… which ultimately would be nice to dump when we hit an error to new relic.


#4

Hi @matthew.augier,

If you are manually handling the MySQL exceptions, you could use the newrelic_notice_error API method, for example:

try {
    //Add your code that may throw an error here.
} catch (Exception $e) {
    if (extension_loaded('newrelic'))
    {
        newrelic_notice_error('MySQL Error', $e);
    }
    //Handle normally.
}

For usage information on this API method, refer to the API documentation:

https://docs.newrelic.com/docs/agents/php-agent/php-agent-api/newrelic_notice_error

Please let us know if that helps solve this issue for you! :slight_smile:


#5

That’s in PHP and we had already planned to do that, however we will be running a BASH script using MySQL command line to run our migrations, so those are the additional errors we need to grab.


#6

Hi @matthew.augier,

Perhaps you can generate some error objects and send those to our Insights API as JSON blobs? If the device you’re running that script from has internet access, you may be able to use our Insights Event Inserter to send those errors to, which would be queryable in the dashboard.

Let us know if that is a solution that will work in your use-case! I look forward to hearing from you!

Regards,
@jlangdon