brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.05k stars 364 forks source link

Brefv2 500 Errors Not In Logs #1794

Open eroltoker opened 2 months ago

eroltoker commented 2 months ago

Description: Since upgrading to brefv2, i'm no longer seeing error messages in the cloudwatch logs.

For example:

This only started happening after the upgrade from brefv1 to brefv2.

Am I doing something wrong?

serverless.yml plugins:

mnapoli commented 2 months ago

With the FPM runtime, just like on any server, nothing is logged by default. You have to set up an error handler. You can use a framework or a library like Monolog.

eroltoker commented 2 months ago

Hi @mnapoli -

First, I implemented bref logger with brefv1: https://github.com/brefphp/logger This seems to be working fine

The issue is with native PHP errors for example things that result in default 500 http response codes (fatal exceptions, syntax errors, etc) are not visible in cloudwatch logs.

According to the documentation here: https://bref.sh/docs/environment/logs

"By default, all PHP errors, warnings and notices emitted by PHP will be forwarded into CloudWatch. That means that you don't have to configure anything to log errors, warnings or uncaught exceptions."

With v1, I didn't need to do anything to get this to show up in the logs.

Here is an example of a request served by the php-fpm-83 runtime in v2 that results in a 500 error (because it is in fact a syntax error), but it doesn't show up in the cloudwatch logs

image

Could you help point me to what I'm missing?

eroltoker commented 2 months ago

I was able to reproduce the v1 behavior by creating a custom php.ini file in my project and adding these settings.

; Turn off displaying errors display_errors = Off

; Log errors to the server's error log (stderr) log_errors = On error_log = /dev/stderr

; Set the level of error reporting error_reporting = E_ALL

mnapoli commented 1 week ago

I'm going to reopen this because I'm not sure whether we want to change that, I want to keep the idea in mind.

eroltoker commented 1 week ago

I think it would make sense, at the very least, to have this as a reminder in the documentation for people getting started. Especially if they are coming into this from a background where php-fpm wasn't what they were using (as was in my case).