arkaitzgarro / elastic-apm-laravel

Laravel APM agent for Elastic v2 intake API
MIT License
76 stars 17 forks source link

Use of undefined constant LARAVEL_START - assumed 'LARAVEL_START' (this will throw an Error in a future version of PHP) #146

Closed fr3ddy closed 3 years ago

fr3ddy commented 3 years ago

Hey, after adding the package as describe I've tested it locally and it was working like a charm. Now I did deploy it with Laravel Vapor onto AWS and we are getting the following errors:


@timestamp | 1621524169921

channel | development

context.exception.class | ErrorException

context.exception.code | 0

context.exception.file | /var/task/vendor/arkaitzgarro/elastic-apm-laravel/src/Collectors/FrameworkCollector.php:22

context.exception.message | Use of undefined constant LARAVEL_START - assumed 'LARAVEL_START' (this will throw an Error in a 
future version of PHP)

datetime | 2021-05-20T17:22:49.808326+02:00

level | 400

level_name | ERROR

message | Use of undefined constant LARAVEL_START - assumed 'LARAVEL_START' (this will throw an Error in a future version of PHP)

and the following (but I would assume, they are related).


@timestamp | 1621524169979

channel | development

context.exception.class | Symfony\Component\ErrorHandler\Error\FatalError

context.exception.code | 0

context.exception.file | /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php:835

context.exception.message | Uncaught ReflectionException: Class translator does not exist in
/var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php:833Stack trace:#0 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(833): ReflectionClass->__construct('translator')#1 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build('translator')#2 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve('translator', Array, true)#3 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\Foundation\Application->resolve('translator', Array)#4 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make('translator', Array)#5 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(119): Illuminate\Foundation\Application->make('translator', Array)#6 /var/task/vendor/

datetime | 2021-05-20T17:22:49.979624+02:00

level | 400

level_name | ERROR

message | Uncaught ReflectionException: Class translator does not exist in /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php:833Stack trace:#0 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(833): ReflectionClass->__construct('translator')#1 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build('translator')#2 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve('translator', Array, true)#3 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\Foundation\Application->resolve('translator', Array)#4 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make('translator', Array)#5 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(119): Illuminate\Foundation\Application->make('translator', Array)#6 /var/task/vendor/

In case anybody has experienced the same issue, I would be happy to hear your opinion on how we can solve that. My current assumption is, that due to the fact that the entry point is changing when using Laravel Vapor, the constant LARAVEL_START is not set.

Regards, Frederik

arkaitzgarro commented 3 years ago

My current assumption is, that due to the fact that the entry point is changing when using Laravel Vapor, the constant LARAVEL_START is not set.

I think your assumption is correct. The constant is defined in Laravel's index.php file, which I also assume is not called in Vapor (I don't have experience with the platform). We also had this issue when running the application with Octane.

I'm going to make "a fix" and set the value if the constant is not defined. The timing might not be exact, but better than making the app crash.

arkaitzgarro commented 3 years ago

@fr3ddy I've just released the fix. Could you install the new v3.0.6 version and try again?

fr3ddy commented 3 years ago

Greate support. Thank you. Works like a charm!