spatie / laravel-ray

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

Class "Spatie\Ray\Payloads\ApplicationLogPayload" not found #237

Closed domthomas-dev closed 2 years ago

domthomas-dev commented 2 years ago

Describe the bug The class "Spatie\Ray\Payloads\ApplicationLogPayload" not found

PHP version: 8.1.0 Laravel version: 8.78.1

Capture d’écran de 2022-01-11 15-24-52

NB : I see this site, but ..... https://php-download.com/package/spatie/laravel-ray/file/src/Watchers/ApplicationLogWatcher.php

Tarpsvo commented 2 years ago

I also invested quite a bit in trying to reproduce this issue locally, but to no avail. This happens for me only on the production environment, even though it's dockerized. The same docker image on local works as expected. I think it's something to do with PHP 8.1 and JIT. 🤷

chelev commented 2 years ago

We have encounter the same issue on a local env and on a production one afterwards.

The local one was fixed after restarting valet.

On production restarting fpm and nginx didn't help, so was forced to move it to the composer dev only.

What I can say is that even when the error occurs, the file is located on the correct place in the vendor directory. I would suspect it actually have to do something with the opcache.

P.S it happens when we try to use the Log facade.

jrmypttrsn commented 2 years ago

Also having this issue. Tried installing ext-redis as mentioned above, restarted Valet, still getting the error instead of the exception I'm expecting.

On the plus side, I just renewed my Ray license.

fullstackfool commented 2 years ago

I wonder if it has something to do with composer. If you report further errors, do mention the composer version number as well.

@freekmurze the issue is transient on my machine but seems to coincide with a recurring platform-check PHP error that I have with Composer and certain PHP git-hooks. Could this be an issue with Composer not always using the correct version of PHP (maybe a PATH problem)?

It would explain why this is so hard to debug/reproduce, given a manual php -v would show the correct version.

KennedyTedesco commented 2 years ago

Same issue here. For instance, I don't have JIT enabled. I'm using PHP 8.1.

Error Class "Spatie\Ray\Payloads\ApplicationLogPayload" not found 
    vendor/spatie/laravel-ray/src/Watchers/ApplicationLogWatcher.php:24 Spatie\LaravelRay\Watchers\ApplicationLogWatcher::Spatie\LaravelRay\Watchers\{closure}
    vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:421 Illuminate\Events\Dispatcher::Illuminate\Events\{closure}
    vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:249 Illuminate\Events\Dispatcher::dispatch
    vendor/laravel/framework/src/Illuminate/Log/Logger.php:245 Illuminate\Log\Logger::fireLogEvent
    vendor/laravel/framework/src/Illuminate/Log/Logger.php:186 Illuminate\Log\Logger::writeLog
    vendor/laravel/framework/src/Illuminate/Log/Logger.php:106 Illuminate\Log\Logger::warning
    vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:102 Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}
    vendor/laravel/framework/src/Illuminate/Support/helpers.php:418 with
    vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:105 Illuminate\Foundation\Bootstrap\HandleExceptions::handleDeprecation
    vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:72 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
    vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:228 Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}
    vendor/composer/ClassLoader.php:571 include
    vendor/composer/ClassLoader.php:571 Composer\Autoload\includeFile
    vendor/composer/ClassLoader.php:428 Composer\Autoload\ClassLoader::loadClass
    vendor/spatie/laravel-ray/src/Watchers/ApplicationLogWatcher.php:24 Spatie\LaravelRay\Watchers\ApplicationLogWatcher::Spatie\LaravelRay\Watchers\{closure}
    vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:421 Illuminate\Events\Dispatcher::Illuminate\Events\{closure}
    vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:249 Illuminate\Events\Dispatcher::dispatch
    vendor/laravel/framework/src/Illuminate/Log/Logger.php:245 Illuminate\Log\Logger::fireLogEvent
    vendor/laravel/framework/src/Illuminate/Log/Logger.php:186 Illuminate\Log\Logger::writeLog
    vendor/laravel/framework/src/Illuminate/Log/Logger.php:94 Illuminate\Log\Logger::error
    vendor/laravel/framework/src/Illuminate/Log/LogManager.php:590 Illuminate\Log\LogManager::error
    vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:249 Illuminate\Foundation\Exceptions\Handler::report
    vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:49 Illuminate\Routing\Pipeline::handleException
    vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:130 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
szhorvath commented 2 years ago

Any progress on this? I had to remove ray from all platforms as I could not find a solution. But I love using ray. 😢

ThomasEnssner commented 2 years ago

This PR is a workaround. It isn't a real solution, but it solves the issue. And many of us are struggling with this for over six weeks.

freekmurze commented 2 years ago

I agree that this has been going on too long. Thanks for the temporary fix. I do hope we'll find the real problem and proper solution in the future.

judgej commented 2 years ago

Using Laravel 8.83, started for us moving from PHP 8.0 to 8.1.1

Fixed by updating the ray.php config file, that was published some versions earlier, so lacked some entries.

How the old config can create what looks like a composer autoloader problem, I can't explain, but hopefully useful evidence to add to the pile.

dejagersh commented 2 years ago

It's not only ApplicationLogPayload, got a similar error now on ColorPayload

image
freekmurze commented 2 years ago

@thejager Do you perhaps have an idea on how to reproduce this?

kg-bot commented 2 years ago

I had the same issue, solved with updating spatie/ray to version 1.34 composer update spatie/laravel-ray --with-dependencies

Nielsvanpach commented 2 years ago

which composer version are you using?

kg-bot commented 2 years ago

@Nielsvanpach

which composer version are you using?

Composer version 2.0.11 2021-02-24 14:57:23

EDIT: I forgot to mention this also happened in production where we use different composer version Composer version 2.2.7 2022-02-25 11:12:27

voicecode-bv commented 2 years ago

Got another one, Class "Spatie\LaravelRay\OriginFactory" not found.

Sorry to say so, but as much as I love this tool, it's getting useless.

freekmurze commented 2 years ago

@voicecode-bv Please try to keep comments constructive.

I'm using Ray myself extensively, and I've come across this problem only once. I believe that there is indeed a problem somewhere. The hard part is getting it reproducible. Still welcoming any tips and help for this.

kg-bot commented 2 years ago

Back to this, updating spatie/ray didn't solve the issue, it does happen less often but it still happens.

I noticed that issue Error: Class "Spatie\Ray\Payloads\ColorPayload" not found only happens when I try to use Log:: facade so it might help you during the debugging.

marickvantuil commented 2 years ago

Also getting this in a personal project. In our situation, the issue was solved by disabling OPCache. The data is a bit preliminary - I have yet to see if the issue actually stays away. Imo it would really explain some of the issues other users have reported: it happening occasionally or disappearing after renaming the file.

When the issue occurred I tried to manually let OPCache compile the file by using this line of code:

opcache_compile_file(__DIR__.'/../vendor/spatie/ray/src/Payloads/ColorPayload.php');

And that throws the following error:

Screenshot 2022-03-08 at 19 10 17

Yet with another random file it does not throw that same error:

opcache_compile_file(__DIR__.'/../vendor/laravel/framework/src/Illuminate/Database/ClassMorphViolationException.php');

Wondering if other people can confirm or disprove this?

Anyway, I cannot reproduce this in a new Laravel app, but can do it in the personal project and don't mind having a small debug session though video call if that helps find the issue.

voicecode-bv commented 2 years ago

@voicecode-bv Please try to keep comments constructive.

I'm using Ray myself extensively, and I've come across this problem only once. I believe that there is indeed a problem somewhere. The hard part is getting it reproducible. Still welcoming any tips and help for this.

Sorry if my response was a bit harsh, I was not my intention, probably the Dutch direct mentality ;-) I was just a bit frustrated because I had to remove this tool from 8 projects already in the last couple of months, because it was causing all kinds of trouble. I think sometimes we should all be a bit critical, only with good intentions. Especially when it comes to a a paid tool. (Yes I know it's still good value for money).

To be more constructive, the Class "Spatie\LaravelRay\OriginFactory" not found was thrown after an Exact api call throwing a 400 error.

fullstackfool commented 2 years ago

Hi @freekmurze posting my situation, hopefully may help narrow this down:

[2022-03-09 09:41:56] local.ERROR: Class "Illuminate\Support\Optional" not found {"exception":"[object] (Error(code: 0): Class \"Illuminate\\Support\\Optional\" not found at vendor/laravel/framework/src/Illuminate/Support/helpers.php:187)
[stacktrace]
#0 vendor/spatie/laravel-ray/src/OriginFactory.php(31): optional(Object(Spatie\\Backtrace\\Frame))
#1 vendor/spatie/ray/src/Payloads/Payload.php(56): Spatie\\LaravelRay\\OriginFactory->getOrigin()
#2 vendor/spatie/ray/src/Payloads/Payload.php(42): Spatie\\Ray\\Payloads\\Payload->getOrigin()
#3 vendor/spatie/ray/src/Request.php(30): Spatie\\Ray\\Payloads\\Payload->toArray()
#4 [internal function]: Spatie\\Ray\\Request->Spatie\\Ray\\{closure}(Object(Spatie\\Ray\\Payloads\\ApplicationLogPayload))
#5 vendor/spatie/ray/src/Request.php(31): array_map(Object(Closure), Array)
#6 vendor/spatie/ray/src/Request.php(42): Spatie\\Ray\\Request->toArray()
#7 vendor/spatie/ray/src/Client.php(77): Spatie\\Ray\\Request->toJson()
#8 vendor/spatie/ray/src/Ray.php(760): Spatie\\Ray\\Client->send(Object(Spatie\\Ray\\Request))
#9 vendor/spatie/laravel-ray/src/Ray.php(507): Spatie\\Ray\\Ray->sendRequest(Array, Array)
#10 vendor/spatie/laravel-ray/src/Watchers/ApplicationLogWatcher.php(33): Spatie\\LaravelRay\\Ray->sendRequest(Object(Spatie\\Ray\\Payloads\\ApplicationLogPayload))
#11 vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(404): Spatie\\LaravelRay\\Watchers\\ApplicationLogWatcher->Spatie\\LaravelRay\\Watchers\\{closure}(Object(Illuminate\\Log\\Events\\MessageLogged))
#12 vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(249): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Illuminate\\\\Log\\\\...', Array)
#13 vendor/laravel/framework/src/Illuminate/Log/Logger.php(245): Illuminate\\Events\\Dispatcher->dispatch('Illuminate\\\\Log\\\\...')
#14 vendor/laravel/framework/src/Illuminate/Log/Logger.php(186): Illuminate\\Log\\Logger->fireLogEvent('warning', 'Return type of ...', Array)
#15 vendor/laravel/framework/src/Illuminate/Log/Logger.php(106): Illuminate\\Log\\Logger->writeLog('warning', 'Return type of ...', Array)
#16 vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(105): Illuminate\\Log\\Logger->warning('Return type of ...')
#17 vendor/laravel/framework/src/Illuminate/Support/helpers.php(377): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}(Object(Illuminate\\Log\\Logger))
#18 vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(108): with(Object(Illuminate\\Log\\Logger), Object(Closure))
#19 vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(71): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleDeprecation('Return type of ...', '/Users/fsf...', 63)
#20 vendor/composer/ClassLoader.php(571): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8192, 'Return type of ...', '/Users/fsf...', 63)
#21 vendor/composer/ClassLoader.php(571): include('/Users/fsf...')
#22 vendor/composer/ClassLoader.php(428): Composer\\Autoload\\includeFile('/Users/fsf...')
#23 vendor/laravel/framework/src/Illuminate/Support/helpers.php(187): Composer\\Autoload\\ClassLoader->loadClass('Illuminate\\\\Supp...')
#24 app/Providers/RouteServiceProvider.php(51): optional(NULL)
... etc, etc (Standard laravel routing & middleware calls)

EDIT:

roberttolton commented 2 years ago

Am experiencing this as well, but am curious if OPCache has anything to do with it.

Have migrated a project off of Laravel Vapor (AWS Lamba) to Laravel Forge with OPCache enabled, and only now have I seen these errors. The Vapor dockerfiles I was basing my environment off have OPCache enabled too, so I don't know why this issue would now present itself running on Forge (with all the same PHP versions) but not Vapor / Lamba.

masterix21 commented 2 years ago

I had the issue in my development environment and the OPCache was off.

brain82 commented 2 years ago

I don't know if this will help anyone, but every time I've had this problem, restarting php and nginx resolves the issue. I tend to get this error when I update the laravel-ray package via composer.

dejagersh commented 2 years ago

Definitely a problem with OPCache. I am having the same problem with spatie/laravel-ignition:

[2022-04-17 18:38:54] development.ERROR: Class "Spatie\LaravelIgnition\Recorders\LogRecorder\LogMessage" not found {"userId":2,"exception":"[object] (Error(code: 0): Class \"Spatie\\LaravelIgnition\\Recorders\\LogRecorder\\LogMessage\" not found at /Users/johandejager/Projects/Laptify/salonbase/vendor/spatie/laravel-ignition/src/Recorders/LogRecorder/LogRecorder.php:39)

I added opcache_reset() to my index.php and it worked again.

freekmurze commented 2 years ago

I've not seen this exception now for quite some time. Maybe it was fixed in Composer?

Do any of you get this exception still?

fullstackfool commented 2 years ago

I've not seem this exception now for quite some time. Maybe it was fixed in Composer?

Do any of you get this exception still?

Nothing for while now. Stable for me in L8 & L9 projects @freekmurze

3rgo commented 2 years ago

Happening to me too... After some trials, I found out that it happens when I have any error, in my case in a controller if that helps (though I think it won't...). Any error triggering an exception will do (syntax error, missing translation, ...). The weird thing is that in the action code, I do not call ray at all.

Versions :

  • Ubuntu 20.04
  • PHP 8.1.1
  • Composer 2.2.4
  • Laravel 8.78.1
  • Laravel Sail 1.12.12
  • spatie/ray 1.33.1
  • spatie/laravel-ray 1.29.0
  • Docker 20.10.12
  • Docker-Compose 1.25.4
  • Ray 1.19.0 (with published docker config file)

Hope it helps fixing it

Yeah seems OK for me too, hasn't happened in a long while. Versions diff :

voicecode-bv commented 2 years ago

We're good here 👍 🙏 Thanks @freekmurze!

roberttolton commented 2 years ago

I've not had it show up recently either..!

freekmurze commented 2 years ago

Going to close this for now.

If you are experiencing this error try upgrading composer to the latest version.