adrianbj / TracyDebugger

The ultimate debugging and development tool for ProcessWire
https://adrianbj.github.io/TracyDebugger/
GNU General Public License v2.0
87 stars 13 forks source link

Option to programmatically enable Tracy for guests #56

Closed teppokoivula closed 2 years ago

teppokoivula commented 3 years ago

Hey @adrianbj!

In some cases I'd like to be able to enable Tracy debug info for guest users in local environment, and while TracyDebugger does indeed have an option for this (guestForceDevelopmentLocal) which I can populate via code in config.php, this only applies to (what TracyDebugger perceives as) local environment.

Now, the problem is that in my case the IP address of the local environment is not what Tracy expects. I don't know how rare this is, but I know it does occur, and I'm afraid that adding every single development IP here would not be a sensible solution (and might even increase the risk of false positives).

What I'm now wondering instead is if it would be possible to add something along these lines into TracyDebugger.module.php:

    public static function isLocal($list = null) {
        if (isset(static::$_data['forceIsLocal'])) {
            return static::$_data['forceIsLocal'];
        }

This would let me override the isLocal check via $config->tracy['forceIsLocal'], which of course means that the responsibility to make sure this is never accidentally set is on me. In our case we've got a special config file only available during development, so this would be a non-issue :)

I did also consider another alternative, which would be overriding $_SERVER['REMOTE_ADDR'], but honestly that seems a bit too hacky, and I have no idea what else it might change and where.

Just for the record, my full dev config for Tracy (with this change in place) would look like this:

$config->tracy = [
    'outputMode' => 'development',
    'guestForceDevelopmentLocal' => true,
    'forceIsLocal' => true,
];

So, what do you think — is this feasible, and do you see downsides here? Or is there, perhaps, already a better solution in place that I just missed? :)

adrianbj commented 3 years ago

Hi @teppokoivula - sorry I have been so long in responding here. Low on bandwidth at the moment I'm afraid. I definitely want to help support this for you - I will try to take a look later this week.

FYI - even though it's not quite the same, I have had a somewhat related request from @Toutouwai so I'll try to handle both together.

teppokoivula commented 3 years ago

Sounds great! And no worries, this is not a super acute issue by any means, one of those "would be nice if..." things :)

On the topic of "would be nice if" (and I know I'm being a bit selfish here9 it'd be great if the solution you end up with would be somehow related to site config. In our case it's trivial to push common config settings to all / multiple sites, while hooks etc. obviously work but may require site-by-site changes.

Anyway, thanks for considering this :)

adrianbj commented 2 years ago

Sorry for taking so long on implementing this, especially given that you figured out a great solution and provided the code for it :)

Added in https://github.com/adrianbj/TracyDebugger/commit/5e8efe417e5064a070ed05f875a942c6c51301a5

teppokoivula commented 2 years ago

Thanks, @adrianbj! :)

netcarver commented 2 years ago

@teppokoivula @adrianbj Thank you, this is just what I was looking for.