public class TraceIdLoggingEnhancer extends Object implements LoggingEnhancer, LoggingEventEnhancer
Constructor and Description |
---|
TraceIdLoggingEnhancer() |
Modifier and Type | Method and Description |
---|---|
void |
enhanceLogEntry(LogEntry.Builder builder)
Set the trace and span ID fields of the log entry to the current one.
|
void |
enhanceLogEntry(LogEntry.Builder builder,
ch.qos.logback.classic.spi.ILoggingEvent e)
See:
enhanceLogEntry(LogEntry.Builder) This method adds support
for AsyncAppender when retrieving MDC properties. |
static String |
getCurrentTraceId()
Get the current trace id.
|
static void |
setCurrentTraceId(String id)
Sets or removes the current trace ID.
|
public static void setCurrentTraceId(String id)
id
- current ID or null to unsetpublic static String getCurrentTraceId()
setCurrentTraceId(String)
public void enhanceLogEntry(LogEntry.Builder builder)
The current trace ID is either the trace ID stored in the Mapped Diagnostic Context (MDC)
under the "X-B3-TraceId" key or, if none set, the current trace ID set by setCurrentTraceId(String)
. The current span ID is retrieved from the MDC under the
"X-B3-SpanId" key, if set.
The trace ID is set in the log entry in the "projects/[GCP_PROJECT_ID]/traces/[TRACE_ID]" format, in order to be associated to traces by the Google Cloud Console.
If an application is running on Google App Engine, the trace ID is also stored in the "appengine.googleapis.com/trace_id" field, in order to enable log correlation on the logs viewer.
enhanceLogEntry
in interface LoggingEnhancer
builder
- log entry builderpublic void enhanceLogEntry(LogEntry.Builder builder, ch.qos.logback.classic.spi.ILoggingEvent e)
enhanceLogEntry(LogEntry.Builder)
This method adds support
for AsyncAppender
when retrieving MDC properties.enhanceLogEntry
in interface LoggingEventEnhancer
builder
- log entry buildere
- logging eventCopyright © 2022. All rights reserved.