GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
418 stars 311 forks source link

logging: container_name is not set when using STACKDRIVER appender #1067

Open stellirin opened 2 years ago

stellirin commented 2 years ago

We want to use spring-cloud-gcp-logging with the STACKDRIVER appender from a service that runs in GKE. Our logs go to projects/my-project-id/logs/spring.log as expected, including trace and span. However in the resource.labels section the container_name is not set. All other fields in this section (cluster_name, location, namespace_name, pod_name, project_id) are all set to the expected values.

Is this potentially a bug in the logging library or simply a quirk of how Stackdriver works when not logging to STDOUT? If not a bug, is it possible to manually set this field via some logger configuration? Our intention was to use the container_name in our log search filters.

I'm aware of the CONSOLE_JSON appender, which works great, but we have an unusual business case where we need unfiltered 'standard' logs as well as structured logs.

elefeint commented 2 years ago

It's a GKE-specific enhancement that's not currently part of our autoconfiguration. You can get this metadata with a workaround described here spring-attic/spring-cloud-gcp#2479.

stellirin commented 2 years ago

Thanks for confirming, we can at least use the pod_name field with a bit of regex matching.

I found the MetadataConfig.getContainerName() method but on GKE it returns null. I was also not able to find a configuration class for logging, the class in the linked issue seems to be only for metrics. At least it had no effect on logging when I tried it.

ddixit14 commented 2 years ago

Hi @stellirin, finding the container name in GKE is not supported yet.

elefeint commented 2 years ago

You can track the GKE feature request here: http://issuetracker.google.com/145137070