Query Tags

Query tags are name-value pairs embedded in query comments. This gives you the flexibility to define arbitrary groupings in your application. Please note though it does not act like a filter to show specific queries which have that tag; the intent of query tags is to show performance by tag. Also note that query tags are currently only available with the On-Host configuration.

For example, suppose you’re considering allocating a dedicated database server to interact exclusively with requests coming from your mobile app, as you suspect traffic coming from it to be significant. You might create a query tag called app, with an application name as the value, to rank applications by the workload they send to the database and thus be able to differentiate them.

You may alter your queries to include the tag embedded in a comment to identify it’s source. Let’s say we would like to differentiate queries coming from the mobile-dedicated infrastructure, which we’ll tag as app=mobile, from the ones originating from other sources, which we’ll simply tag as app=desktop. The exact syntax for query comments is database specific: MySQL, PostgreSQL, and Cassandra implement nested block comments while MongoDB employs a $comment meta-operator. The table below illustrates our example for each of those databases:

Database Example
MySQL SELECT /* app=mobile */ ...
PostgreSQL SELECT /* app=mobile */ ...
MongoDB db.collection.find( { <query> } ).comment('app=mobile' )

Once you have your tags in place you can visit the Profiler page and set it to rank by “Query Tags”. On the “filter by” section set app in the “Tag Name” field and mobile (or desktop) in the “Tag Value” field, then press “Apply”. The result should be similar to the images below:

Queries from mobile app

The default delimiters for query tags are = and a space, but this is configurable through the tag-delimiters agent option: you can use a different 2-character string for representing the delimiters between name-value pairs and tags, respectively. In case you need, there’s also a tag-blacklist agent option, a comma-separated list of tags to be ignored. We automatically blacklist tags whose values have extremely high cardinality, as that data is typically to granular to be useful and does not provide meaningful statistics.

Please note that both MySQL and PostgreSQL command line tools will strip comments. If you are looking at testing this functionality you will need to use a different client to the native ones (or, in the case of MySQL, use option --comments to prevent the client from discarding comments and sending them to the server with the query).