Laravel + Datadog APM: ddtrace.request_init_hook has run [Failed]
Hi everyone,
Our team and I are currently working on a Laravel API for the backend of our application. We have enabled Datadog APM with our server hosting provider a short while ago to trace our PHP code and find slow parts for us to take another look at.
Now Datadog's APM is supposed to work out of the box with frameworks like Laravel, since it simply hooks into the PHP runtime and wraps functions there. For us, however, this did not work out of the box. Some troubleshooting on our hosting provider's side of things showed that the error causing this issue is ddtrace.request_init_hook has run [Failed]. They tested a workaround by adding require_once(ini_get('ddtrace.request_init_hook')); to the top of a phpinfo test file, which worked and enabled tracing. Adding this to our Laravel index.php did not enable the tracing, though. Our hosting provider said that this could be because the Laravel index.php only points towards other code, and that we may have to add the require_once(ini_get('ddtrace.request_init_hook')); line to other PHP files as well. Doing this would result in very messy code, though, as we'd have to add it to hundreds of files.
If anyone knows how we can make sure that Laravel can run the ddtrace.request_init_hook, that would be much appreciated!
Not sure if your hosting provider is correct here. It should be added to the public/index.php file. This is the first file that will be loaded on every request and initiates the rest of the application. So that file should perform the require_once correctly for you.
You also need to add it to the artisan file to make sure you can run commands and run php artisan tinker successfully on the server.
Another thing you can try is adding it to the bootstrap/app.php file. That is the first file that is loaded by Laravel to initiate the application.