mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-27 08:35:53 +03:00
[GH-ISSUE #1754] GoogleCloudLoggingFormatter timestamp does not work with Google Cloud Run #741
Labels
No labels
Bug
Documentation
Feature
Needs Work
Support
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/monolog#741
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rpkamp on GitHub (Aug 26, 2022).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1754
Monolog version 2 and 3.
In our application we have a fingers crossed handler that passes to a stream handler that writes to
php://stderrusing the Google Cloud Logging Formatter. This mostly works fine, except that Google Cloud Run does not use thetimestampsent from monolog as the timestamp of the message. It seems to be taking the time it received the message instead.Most notably when we logged several messages, sleeping for 1 second between those messages, they all more or less the same timestamp in Google Cloud Logging, they certainly weren't a second apart.
Diving into it, it turns out sending messages through
php://stderris different than sending them through the logging API. Instead oftimestampthe fieldtimemust be used, and the time must be in UTC.We found that the following works for us when writing to
php://stderron Google Cloud Run (in Monolog 2):With this in place the messages were logged seconds apart, even though they were still logged all at once by the fingers crossed handler.
I do wonder whether this should be changed in Monolog, because I don't know if the current implementation has a use case that I'm unaware off that uses the format that is now in the code (something else than Cloud Run and/or writing to
php://stderr).@lcobucci since you wrote the formatter in Monolog, do you have ideas on this?
@lcobucci commented on GitHub (Aug 26, 2022):
I'm running this via Google Kubernetes Engine (relying on
php://stderrtoo) and it seems to be working fine. It's interesting that Cloud Run and GKE diverge... well, maybe it's just Google being Google idk 🤷♂️I don't see a reason not to support both, though... maybe
$record['time'] = $record['timestamp'] = $record['datetime']->...?@Seldaek commented on GitHub (Aug 31, 2022):
Seems kinda silly to log the time twice there, but if it's gotta be done ..
Any chance that
timewould also work for GKE @lcobucci ?@lcobucci commented on GitHub (Aug 31, 2022):
I'll test it and come back to you 👍
@rpkamp commented on GitHub (Sep 4, 2022):
@lcobucci Please also check if it works when logging in UTC time. Cloud Run doesn't like our default timezone (CEST).
(see my first post for how we're doing it now)
@lcobucci commented on GitHub (Sep 8, 2022):
Hey folks, sorry about the delay.
We've tested the format by writing straight to
STDERR:The result is that
timeis indeed the field that respected both skews (both future and past) and different timezones (UTC,CEST, andEurope/Amsterdam).Looking at https://cloud.google.com/logging/docs/agent/logging/configuration#timestamp-processing the
timestampfield has other expectations.I'll send a PR to fix it, thanks @rpkamp for reporting the issue!
@lcobucci commented on GitHub (Sep 8, 2022):
Alright, fixes sent... I hope that helps, sorry for the inconvenience!
@ryokomy commented on GitHub (Sep 13, 2022):
Anyone who uses Laravel with Monolog v2?
I can't see any logs on Google Cloud Logging...
I can see them with Monolog v1.
I hope someone helps me and those who are in the same situation.
@lcobucci commented on GitHub (Sep 13, 2022):
@ryokomy that seems like a completely different thing (this formatter is only available for monolog v2 and v3).