2

I have a spring boot app that's deployed in google cloud and I face a rather odd problem. The X-Cloud-Trace-Context is set by google (load balancer I suppose) but the traceId of the app level logs have a different traceId (different from the one I see in the response headers in postman).

enter image description here

So in this photo you can see the postman headers including the traceId ending in 54e11 (with o=1).

enter image description here

In this one you can that the request log entry has the traceId ending in 54e11 but the entry above (the one you can't see but it's the one from the app log) has a traceId ending in 992da (which is different from the one in the POST request log).

Why is it different between request log and app log ? Do I need to write a custom filter to extract the traceId from the headers (if found) and do something with it like put it in the MDC map ?

My pom has the following dependency :

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-gcp-starter-logging</artifactId>
</dependency>

My appender configuration (logback-spring.xml) is pretty basic :

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="projectId" value="${projectId:-${GOOGLE_CLOUD_PROJECT}}"/>

    <appender name="CONSOLE_JSON" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="org.springframework.cloud.gcp.logging.StackdriverJsonLayout">
                <projectId>${projectId}</projectId>
                <includeException>true</includeException>
            </layout>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="CONSOLE_JSON" />
    </root>
</configuration>

Thanks in advance for your time.

I want to also add that I followed the upvoted solution from this post but I still have the same problem Spring Boot Logging and Google Cloud Platform Log Viewer

XII
  • 420
  • 4
  • 16
  • I was not using cloud run but this answer fixed my issue https://stackoverflow.com/a/71343735/2088039. Basically you cannot pass the span ID in that header but you have just to set the traceId as header value. If the span ID is considered invalid, the whole trace / span id will be overwritten – Tonino Mar 29 '22 at 16:39
  • Can you elaborate a bit more on your answer. Should I override the value of X-Cloud-Trace-Context with a new value or I need to pass an extra header in the request ? Also I do not have the problem that this link refers to (this refers to separate requests , my problem is that the request log has different traceId from the app logs , so my problem is with a single request , not multiple requests). – XII Apr 01 '22 at 09:07
  • you pass a custom X-Cloud-Trace-Context in postman with the 'traceID/SpanId;o=1' format. The X-Cloud-Trace-Context header should be set only with the trace ID as value, avoiding to pass the spanId;o=1 as well. in your case just set the traceID ending with 54e11 as value – Tonino Apr 01 '22 at 12:44

0 Answers0