question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logging with google-cloud-logging-logback on K8S: resources.labels are empty

See original GitHub issue

I’m trying the used structured logging with google-cloud-logging-logback on Kubernetes. Most of the resource labels are empty, except project_id and zone:

 resource: {
  labels: {
   cluster_name: ""    
   container_name: ""    
   instance_id: ""    
   namespace_id: ""    
   pod_id: ""    
   project_id: "<project ID>"    
   zone: "<zone>"    
  }
  type: "container"   
 }

I guess the reason for this is that only project_id and zone are configured for resource of type container:

https://github.com/GoogleCloudPlatform/google-cloud-java/blob/937e49d7159c9327255e167f6339c51bb7372c37/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java#L95

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
yannscommented, Mar 1, 2018

@jabubake @saturnism I just tried using stdout with json, and it looks to work well. Thx for the info!

In case anyone is interested in the solution I took: I added this library: https://github.com/logstash/logstash-logback-encoder

I configured logback that way:

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <target>System.out</target>
        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <timestamp><fieldName>timestamp</fieldName></timestamp>
                <loggerName/>
                <logLevel><fieldName>severity</fieldName></logLevel>
                <message />
                <stackHash />
                <stackTrace>
                    <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                        <maxDepthPerThrowable>30</maxDepthPerThrowable>
                        <maxLength>2048</maxLength>
                        <shortenedClassNameLength>20</shortenedClassNameLength>
                        <rootCauseFirst>true</rootCauseFirst>
                    </throwableConverter>
                </stackTrace>
            </providers>
        </encoder>
    </appender>

    <appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="STDOUT"/>
    </appender>

This may evolve in the future, but fulfills the first use-cases. The field severity is correctly parsed by the stackdriver agent.

2reactions
ocervellcommented, Mar 29, 2018

+1 I’m running into the same and opened a separate issue #3109 because the docs are incomplete. Having the log level in Stackdriver is essential if you want to make log-based metrics based on the ‘severity’ field.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting Up Cloud Logging for Java | Google Cloud
The Logback appender and the java.util.logging handler provide automatic resource type detection of your App Engine, Compute Engine, and Google Kubernetes ...
Read more >
Logging Architecture | Kubernetes
Application logs can help you understand what is happening inside your application. The logs are particularly useful for debugging problems ...
Read more >
Kubectl Logs | Kubectl Cheat Sheet | Sumo Logic
Logs in Kubernetes can give you insight into resources such as nodes, ... When you use “kubectl run”, it will automatically apply a...
Read more >
The Guide to Kubernetes Labels - - Kubecost blog
Labeling Best Practices; What You Should NOT Do With Kubernetes Labels. Tagging MethodsPermalink. To help organize cluster resources, Kubernetes ...
Read more >
Viewing logs for a specific resource - OpenShift Documentation
Resource logs do not access the OpenShift Logging log store. Viewing resource logs. You can view the log for various resources in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found