15 June 2023
Tim
Use ray()->trace() to figure out where a call came from
An important problem of a programmer's productivity is finding his way through the code. A good project structure and your IDE can get you a long way, but sometimes it’s not enough. Luckily enough Ray has a bunch of tools to help you out.
The problem
Imagine an example where you have a NotifyUserAction being called, but you are unsure exactly why or where this call happens. Your IDE tells you the action is being used in 10 different files, and you don’t want to walk through all the code paths.
The solution
An easy way to figure this out is to add a call to Ray with the “trace” method.
class NotifyUserAction
{
public function execute(): void
{
ray()->showApp()->trace();
// Some logic to notify the user...
}
}
Now the only thing you have to do is use the application and look at Ray. Once your application hits the trace method, a nice backtrace will be shown in Ray.
The entries in the trace that belong to your application are highlighted in blue, making it easier to visually distinguish them from the code originating from the framework and packages.
If you are unsure what exact user action is triggering this part of your code and you want to click around your app until it shows, you can always chain in the showApp() method, which will bring Ray to the foreground once that part of the code is being hit.
ray()->showApp()->trace();
The trace method is only one of many powerfull tools Ray provides. Make sure to take a look at the documentation if you want to learn more.
Understand and fix bugs faster
Ray is a desktop application that serves as the dedicated home for debugging output. Send, format and filter debug information from both local projects and remote servers.