Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brefv2 500 Errors Not In Logs #1794

Open
eroltoker opened this issue Apr 25, 2024 · 5 comments
Open

Brefv2 500 Errors Not In Logs #1794

eroltoker opened this issue Apr 25, 2024 · 5 comments
Labels

Comments

@eroltoker
Copy link

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

For example:

  • I introduce a syntax error in one of my endpoints
  • I hit an endpoint to invoke the php script via http handler
  • The client gets a 500 error, but there's no error message that's sent to both the client and the cloudwatch logs. I can see a default error setting suppressing errors in prod, but without these going to cloudwatch I have no idea what the error is.

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

Am I doing something wrong?

serverless.yml
plugins:
- ./vendor/bref/bref
- ./vendor/bref/extra-php-extensions
functions:
api:
handler: lambdaHandler.php
description: ''
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
memorySize: 256
runtime: php-83-fpm
layers:
- ${bref-extra:redis-php-83}
events:
- httpApi: '*'

@eroltoker eroltoker added the bug label Apr 25, 2024
@mnapoli
Copy link
Member

mnapoli commented Apr 25, 2024

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.

@mnapoli mnapoli closed this as completed Apr 25, 2024
@eroltoker
Copy link
Author

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
Copy link
Author

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
Copy link
Member

mnapoli commented Jun 26, 2024

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.

@mnapoli mnapoli reopened this Jun 26, 2024
@eroltoker
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants