How to specify unique database query names for PHP APM

I’m having some trouble isolating specific queries in the ‘Databases’ page within the APM console.

I’m not certain, but it seems to me like the report groups/names the queries based off the type of query and first table in the SQL statement (e.g. SELECT products). This works well for 80% of the queries, but there are a few complex queries that I would like to track independently which share the same report name as less important queries.

Is there a way I can give specific queries a custom name so I can have an easier time tracking them within the APM? Currently I have the following thoughts:

  1. Use the newrelic_record_datastore_segment API request - but am not sure if this is what it was intended for.
  2. Create custom metrics/events to track the queries

I’m currently using the PHP Agent version: (just noticed it is a bit dated so I will probably update to the newest version later this week), and am using MySQL.

Any advice is appreciated.

This is indeed how we name database metrics that you see in your Databases page for the PHP Agent and for other language Agents (though I can’t say I’ve personally investigated this feature for each language!). The logic here is kept simple as a balance between getting data that will be useful to display and performance. Queries can get pretty long so parsing them can get expensive as the logic gets more complicated.

That said, I think this is a good feature request for possibly an API call similar to newrelic_name_transaction() that would let you override our automatic naming. The newrelic_record_datastore_segment() is for adding detail to transaction traces and is separate from the Database tab.

I’d recommend creating a post in our Feature Ideas section. This will let other customers voice their support for the feature as well as adding their use cases to help us deliver useful features: