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

fix(log): avoid duplicated log when there is a subrequest by listening to kernel.terminate #74

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

shavounet
Copy link
Contributor

@shavounet shavounet commented Sep 1, 2022

Description

See #73. We can use kernel.terminate since it is correctly triggered on main requests.

From my tests, it goes fine for valid requests and for failed requests.

Example log for a valid request
[2022-09-01 10:38:06] log_bridge.INFO: Request ------------------------ host                : 127.0.0.1:8000 user-agent          : Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0 accept              : text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 accept-encoding     : gzip, deflate, br accept-language     : fr,en-US;q=0.7,en;q=0.3 dnt                 : 1 sec-fetch-dest      : document sec-fetch-mode      : navigate sec-fetch-site      : none sec-fetch-user      : ?1 te                  : trailers upgrade-insecure-requests: 1 x-forwarded-for     : 127.0.0.1 x-php-ob-level      : 1 ------------------------ Response ------------------------ HTTP 1.1 200 Age:           0 Etag:           Vary:           Cache-Control:      max-age=2, public Content-Type:       text/plain; charset=UTF-8 Date:               Thu, 01 Sep 2022 08:38:06 GMT X-Debug-Token:      413a0d X-Debug-Token-Link: http://127.0.0.1:8000/_profiler/413a0d X-Robots-Tag:       noindex Response body ------------------------ OK  {"project":"*****","environment":"dev","route":"get_status","method":"GET","status":200,"user":"","key":"dev.get_status.GET.200","uri":"http://127.0.0.1:8000/status","request_id":133008276824294,"hostname":"*****"} []
Example log for a failed request
[2022-09-01 10:38:27] log_bridge.CRITICAL: Request ------------------------ host                : 127.0.0.1:8000 user-agent          : Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0 accept              : text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 accept-encoding     : gzip, deflate, br accept-language     : fr,en-US;q=0.7,en;q=0.3 dnt                 : 1 sec-fetch-dest      : document sec-fetch-mode      : navigate sec-fetch-site      : none sec-fetch-user      : ?1 te                  : trailers upgrade-insecure-requests: 1 x-forwarded-for     : 127.0.0.1 x-php-ob-level      : 1 ------------------------ Response ------------------------ HTTP 1.1 500 Age:           0 Etag:           Vary:           Cache-Control:          no-cache, private Content-Type:           application/json Date:                   Thu, 01 Sep 2022 08:38:27 GMT X-Debug-Token:          e8fcfe X-Debug-Token-Link:     http://127.0.0.1:8000/_profiler/e8fcfe X-Previous-Debug-Token: a21fd6 X-Robots-Tag:           noindex Response body ------------------------ {     "code": 500,     "message": "oops" }  Exception class :  ------------------------ RuntimeException  Exception message (1) : ------------------------ oops  Exception trace (1) : ------------------------ #0 /*****/*****/*****/*****/vendor/symfony/http-kernel/HttpKernel.php(158): *****\*****\*****\*****\*****->*****() #1 /*****/*****/*****/*****/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw() #2 /*****/*****/*****/*****/vendor/symfony/http-kernel/Kernel.php(201): Symfony\Component\HttpKernel\HttpKernel->handle() #3 /*****/*****/*****/*****/public/index.php(40): Symfony\Component\HttpKernel\Kernel->handle() #4 {main}  {"project":"*****","environment":"dev","route":"get_status","method":"GET","status":500,"user":"","key":"dev.get_status.GET.500","uri":"http://127.0.0.1:8000/status","request_id":133028436425592,"hostname":"*****"} []

@shavounet shavounet requested a review from a team as a code owner September 1, 2022 08:49
@shavounet shavounet changed the title fix(log): avoid duplicated log where there is a subrequest by listening to kernel.terminate fix(log): avoid duplicated log when there is a subrequest by listening to kernel.terminate Sep 1, 2022
@Oliboy50
Copy link
Member

Oliboy50 commented Sep 1, 2022

don't we have to change this to be kernel.terminate too?

@shavounet shavounet force-pushed the fix/duplicated-log-on-error-with-subrequest branch from c9d80af to 969aba2 Compare September 1, 2022 09:05
@shavounet
Copy link
Contributor Author

Absolutely ! I've manipulated by vendor folder without backporting all changes 😅

Copy link

@titoko titoko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we face the same issue !
thanks for that

@shavounet shavounet mentioned this pull request Sep 6, 2022
@shavounet shavounet merged commit f169f8c into master Sep 6, 2022
@shavounet shavounet deleted the fix/duplicated-log-on-error-with-subrequest branch November 10, 2022 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants