⚡️ Ray 3.0 launch sale! Discounts and lifetime licenses available for d h m s
Back to overview

Use ray()->trace() to figure out where a call came from

15 June 2023

Image of Tim

Tim

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.

Stay in the loop with updates & promotions for Ray

We only send a few emails a year.

Debug without breaking your flow

Ray keeps all your debug output neatly organized in a dedicated desktop app.

Launch sale! Lifetime licenses also available

Licenses are valid for 1 year and managed through Spatie. Licenses purchased before Ray 3 remain valid. VAT is calculated at checkout.