I've been doing this on high traffic PHP sites for years. It makes mytop very informative and easy to understand, and I even occasionally use them for cheapo memcache caching instructions (built into db layer) when it's not worth precaching or coming up with a more sophisticated scheme. Highly recommended.<p>One difference though: I prepend the comment instead of appending it.
A similar thing I've tried to get implemented at a number of previous jobs is to dump the session ID in a SQL comment when issuing a query. We've had the session ID in application logs forever, but no way of correlating DB activity with application activity; this would fix that and allow <i>a posteriori</i> full-stack instrumentation.
Note that adding comments to otherwise identical queries will typically cause the MySQL query cache to not realize they are the same. See: <a href="http://www.mysqlperformanceblog.com/2008/03/20/mysql-query-cache-whitespace-and-comments/" rel="nofollow">http://www.mysqlperformanceblog.com/2008/03/20/mysql-query-c...</a><p>Otherwise, neat idea, I like it.
Does Rails not have an equivalent to the Django-Debug-Toolbar to easily debug stuff like this in development?<p>As for production, going with a fleshed-out service like NewRelic makes more sense to me. If I see slow queries start happening I'd want a broader report of what's going on in my system, not just a map of the query to a controller/action.