You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once the MDC is populated with `trace_id` and `span_id`, the Google Cloud Logging Logback appender automatically maps these to the trace and span fields in Cloud Logging, allowing you to view correlated logs and traces in the Google Cloud Console.
97
+
Google Cloud Java client libraries provide two complementary ways to correlate logs with Cloud Trace:
98
+
99
+
1.**Automatic Context Extraction in Cloud Logging**:
100
+
When writing logs via `google-cloud-logging` (including via the Google Cloud Logging Logback appender), the client library automatically inspects the active thread's OpenTelemetry context (`Span.current()`). If a valid span is active, the `trace`, `spanId`, and `traceSampled` fields are automatically populated on the written `LogEntry`, linking the log directly to Cloud Trace in the Google Cloud Console.
To also include `trace_id` and `span_id` in formatted log messages (such as console or file pattern layouts via `%X{trace_id}`) and attach them as labels in Logback, propagate the OpenTelemetry context to SLF4J MDC:
104
+
-**OpenTelemetry Javaagent**: Use the [OpenTelemetry Javaagent](https://opentelemetry.io/docs/zero-code/java/agent/), which automatically instruments logging frameworks.
105
+
-**Logback MDC Dependency**: Or add the Logback MDC instrumentation dependency to your project:
0 commit comments