Why multi-line Stacktraces are shown as individual logs on GCP Log Explorer?

Viewed 557

I'm having an issue with a JAVA App running in GKE where Stacktraces are shown in GCP's Log Explorer as individual logs:

Example of GCP Log Explorer

The expected behavior would be that GCP show one entry per Stacktrace.

I tried generating logs using JUL and Log4J and the outcome is the same.

So I suspect there is something wrong on how logs are imported into GCP. Traditionally Stacktraces lines are separated by newline chars, so I'm guessing this is why GCP recognizes each line as a different log entry.

I also had a quick glance at the docs and there is no specific configuration for handling stacktraces.

So the question is, how can I make GCP understand that Stacktraces are a single log entry?

UPDATE: I'm guessing this would be the right way. Instead of using the default ingest, I should explicitly write the events following these docs

But again, I was wondering if there is an easier out-of-the-box config, or another approach.

Thanks!

1 Answers

-"For what it's worth, I too have wondered the same. I think your suspicions are likely accurate that the messages we are seeing are being "injected" into Cloud Logging by scraping the existing log files written to the local machine/image and each line in the "file" is resulting in a new GCP Cloud Console log entry." @Kolban

-"Yeah, I'm thinking of pre-processing them on the pod with a side-car but I was wondering if there is an out-of-the-box configuration before going that way." @Diego M.

-"I'm guessing this would be the right way. Instead of using the default ingest, I should explicitly write the events following these docs: cloud.google.com/error-reporting/docs/formatting-error-messages" @Diego M.

Related