We deployed DataFlows in Google Cloud. Dataflows are developed using Apache Beam.
Dataflow logging doesn't include the transaction id, which is needed for tracing the transaction in the pipeline.
Any logging pattern used in the logback is being ignored by Google Cloud.
How do we capture the trace id in Google Cloud logging ?
logback.xml
<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>
<includeTraceId>true</includeTraceId>
<includeSpanId>true</includeSpanId>
<includeLevel>true</includeLevel>
<includeThreadName>true</includeThreadName>
<includeMDC>true</includeMDC>
<includeLoggerName>true</includeLoggerName>
<includeFormattedMessage>true</includeFormattedMessage>
<includeExceptionInMessage>true</includeExceptionInMessage>
<includeContextName>true</includeContextName>
<includeMessage>false</includeMessage>
<includeException>false</includeException>
</layout>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE_JSON"/>
</root>
</configuration>
Java:
MDC.put("traceId", "12345");
log.info("Logging from test class");
Google Cloud:
jsonPayload: {
job: "2022-09-08_19_05_07-12432432432"
logger: "TestLogger"
message: "Logging from test class"
stage: "A1"
step: "Test Step"
thread: "49"
work: "3243243"
worker: "test-worker"
}