spatie / laravel-ray

Debug with Ray to fix problems faster in Laravel apps
https://myray.app
MIT License
291 stars 64 forks source link

Ray still running in production mode #164

Closed S-R0 closed 3 years ago

S-R0 commented 3 years ago

Describe the bug Ray is enabled on production environment if ray.php file is not present.

Versions Ray - 1.12.0 spatie/ray package version: 1.19.4 spatie/laravel-ray package version (if applicable): 1.12.6

PHP version: Laravel version (if applicable): 7.4

To Reproduce Steps to reproduce the behavior:

  1. Comment out the ray.php file or rename it to something like ray.php.bak.
  2. Add APP_ENV=production and APP_DEBUG=false to your .env file.
  3. Add a @ray('something') to one of your views.
  4. Load the view and see ray still reporting.

Expected behavior If no ray.php file is present (gitignored) but ray package is still installed, ray should not report. In my situation I have set an update onto a staging version of one of my sites, which does not have a ray.php file (as its included in .gitignore) but does have ray package installed. The side was physically showing @ray('something') on the frontend as text. Decided to test this locally with Ray open and with the above steps, ray is still reporting even though i've removed my ray.php file and even set the app to production.

Additional context The only was I seem to be able to disable ray running and have nothing show in the view, is if I have a ray.php file present and have RAY_ENABLED=false in either the ray.php or .env file.

I think behaviour of this feature should be as follow

freekmurze commented 3 years ago

If you see @ray('something') in the browser, that means that the ray package isn't installed at all. When the package isn't installed, the directive isn't recognised and the directive is being regarded as just text that should be output.

This line should make sure that, when the package is installed, that on production environments Ray is disabled.

https://github.com/spatie/laravel-ray/blob/2632d01a270838fd105841e5d3c3df9424e2dcf4/src/RayServiceProvider.php#L55

Could you create a minimal app for me where the environment is set to production, and you're still seeing things being transmitted to Ray?

S-R0 commented 3 years ago

Apologies, potentially a caching issue, I am no longer seeing @ray('something') in the browser, but I am still experiencing the issues with ray still reporting even with APP_ENV=production in my .env file.

As an example, I have added the following to one of my views

@ray("app()->environment('production') = " . app()->environment('production'))

and ray is showing

app()->environment('production') = 1

So it can see that the .env file is set to production, but I am still getting that report/output to Ray. Screenshot 2021-02-18 at 14 06 36

freekmurze commented 3 years ago

Please create a minimal app for us to easily recreate the issue.

S-R0 commented 3 years ago

https://github.com/S-R0/laravel-ray-production-test

As you can see its a basic starting laravel project, no ray.php file, but .env has APP_ENV=production and DEBUG_MODE=false.

I have added 2 ray commands (1 to routes and 1 to the view) and both are still being reported in my local ray app.

Just out of curiosity, is this how ray is supposed to act? Even if you have APP_ENV=production, it still reports if there is an instance of ray running on 127.0.0.1:23517 ?

freekmurze commented 3 years ago

Thanks for that app. Using it, I could find a good fix.

Upgrade spatie/ray to v1.20.1 to get the right behaviour.