-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Adjust GcpLayout JSON to latest format #3586
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
base: 2.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you contribution.
Did you test it on an actual Google Cloud instance? I am not a GCP user, but some of the changes you propose differ from the documented log format.
Let's wait for @vy's review. @ViliusS, in this repository we require signed commits, so you need to:
|
First, it formats the log timestamp field to the correct format recognized by Fluent-Bit (component of Google Cloud Logging) and Google Ops Agent. Secondly, severity field now must be prefixed with logging.googleapis.com. Third, counter cannot be used for insertId as it is duplicated on different threads. And the last but not the least, exception, thread and logger fields are pretty standard when logging via Logback's JSON layout and Google's Spring GCP libraries. Field name changes now match these other loggers.
718ccbd
to
5e0656e
Compare
Done. |
One particular thing that is bothering me about this fix is... it breaks backward compatibility. We can say we're fixing the schema, but for users who have already been using the broken schema, we are gonna create trouble. We can
@ppkarwasz, thoughts? @ViliusS, would you mind adding a changelog entry file (i.e., |
I would call the new format However, I am not entirely sure that this template file belongs to Log4j. The only users that can profit from it are Google Ops Agent users, so we might consider moving the file to that project instead. See also GoogleCloudPlatform/ops-agent#1920 (comment) |
Changelog added. Regarding backward compatibility I see it this way. The proposed changes are not really fixes, they are changes/improvements. Old schema probably worked in some sense, but required a little bit tinkering for proper GCP field mapping on Google side. It is natural that schemas change and they need to be re-adjusted, there is no way to avoid that when dealing with 3rd party services. The real question is when backward compatibility and how it should be broken.
Considering that new adjustments makes it a lot easier to send logs to GCP now without major processing in between, and if they are included in 2.25.0, I think it is fair. @ppkarwasz I wouldn't call it |
This is my first contribution to Log4J so I'm not 100% sure if I did everything right, but here it goes.
This PR adjusts GcpLayout JSON formatting to match what is expected by GCP.
First, it formats the log timestamp field to the correct format recognized by Fluent-Bit (component of Google Cloud Logging) and Google Ops Agent. I'm not sure how it worked before, probably it didn't, but Google Cloud Logging expects timestampSecond + timestampNanos format. Ops Agent, which also can be used to feed the logs from external Log4J environment via Socket or RollingFile into GCP, also expects the same format. More over, the same timestamp format is always used in Spring GCP libraries.
Secondly, severity field now must be prefixed with
logging.googleapis.com
. I'm not 100% sure regarding this, because Spring GCP libraries are still using justseverity
field name. However Ops Agent (link above) already useslogging.googleapis.com/severity
, and simpleseverity
name is only described in legacy logging agent which is deprecated.Third, counter cannot be used for
logging.googleapis.com/insertId
as it is duplicated on different threads. I've chosen to use time-based UUID, but if that increases garbage collection issues it safely can be removed. GCP will generate their own IDs anyway.And the last but not the least, I have renamed
exception
,thread
andlogger
fields. I saw the PR discussion in #543, however these fields are pretty standard when logging via Logback's JSON layout and then they are reused in Google's Spring GCP libraries. Sadly, I didn't find how to completely removeexception
field from JSON output if it's empty. Looks like all empty fields are removed except forpattern
type. I also found https://issues.apache.org/jira/browse/LOG4J2-3053 regarding that, but not sure about its state. This is not a big issue but is preferable for GCP.By the way, Log4J docs are a little bit incorrect. If
message
field exist, having separateexception
does nothing to catch the error in Google Error Reporting. According to Google docs, ifmessage
field exist it must contain stack trace and only that stack trace is used in the Error Reporting UI. I tested this extensively. But I left separateexception
field if one wants to filter it in the logs.All in all, this should provide much better JSON field mapping experience on GCP. If you think this PR is usable I then will go ahead and fix tests for timestamp processing.