Clickable Stack Traces and Function Names in Query Monitor

Many panels in Query Monitor display function names or stack traces. Wouldn’t it be great if you could click the function name and the file opens up in your text editor or IDE at the correct position? With the clickable file links feature you can, and you’ll wonder how you lived without it:

Screenshot of clickable function names in Query Monitor

You just need to open up the Settings panel in Query Monitor (click the cog next to the Close icon) and choose your editor in the “Editor” section. That’s it!

If you use an editor other than VS Code or PhpStorm then you may first need to configure it so it opens when a certain URL scheme is encountered:

Remote File Path Mapping

If you’re debugging a remote site or using Docker or a virtual machine, you’ll need to map the path on the server to its path on your local machine so your editor doesn’t try to load a non-existent file. You can do this using a filter on the qm/output/file_path_map hook which accepts an array of remote paths and the local path they map to.

For example, if you use the Docker-based development environment that’s built in to WordPress core, your path mapping needs to look like this:

add_filter( 'qm/output/file_path_map', function( $map ) {
	$map['/var/www/'] = '/path/to/wordpress/';
	return $map;
} );

If you use VVV your path mapping needs to look like this:

add_filter( 'qm/output/file_path_map', function( $map ) {
	$map['/srv/'] = '/path/to/vvv/';
	return $map;
} );

If you use Chassis or another Vagrant-based VM, your path mapping needs to look like this:

add_filter( 'qm/output/file_path_map', function( $map ) {
	$map['/vagrant/'] = '/path/to/local/project/';
	return $map;
} );

If you’ve changed the paths configuration in Chassis, you may need to map the /chassis directory instead:

add_filter( 'qm/output/file_path_map', function( $map ) {
	$map['/chassis/'] = '/path/to/local/project/';
	return $map;
} );

That’s It!

I hope you enjoy clicking on your newly-clickable file links.

4 thoughts on “Clickable Stack Traces and Function Names in Query Monitor”

  1. My links are showing as “vscode://file//home/cpanel_user/public_html/development/wp-content/themes/salient/nectar/helpers/woocommerce.php:359”
    How do I change that to work with “C:\Repos\project_dir”?

    Reply
  2. Hi, I’m using Lando on Linux and my local web folder is called ‘wordpress’.

    The filter that I use does not seem to work:

    add_filter( ‘qm/output/file_path_map’, function( $map ) {
    $map[‘/app/wordpress/’] = ‘/app/wordpress/’;
    return $map;
    } );

    The link I’m getting now eg is vscode://file/%2Fwordpress%2Fwp-includes%2Fformatting.php:934 but that one fails.

    Any tips on how I can fix this?

    Reply
    • Mapping `/app/wordpress` to `/app/wordpress` isn’t going to achieve anything. You need to map the the remote path to your local one, eg. `/app/wordpress` to `/my/documents/wordpress`.

      Reply

Leave a comment