Class OpenCensusTraceContextDataInjector
- java.lang.Object
-
- io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector
-
- All Implemented Interfaces:
org.apache.logging.log4j.core.ContextDataInjector
public final class OpenCensusTraceContextDataInjector extends java.lang.Object implements org.apache.logging.log4j.core.ContextDataInjectorA Log4jContextDataInjectorthat adds OpenCensus tracing data to log events.This class adds the following key-value pairs:
- "traceId" - the lowercase base16 encoding of the current trace ID
- "spanId" - the lowercase base16 encoding of the current span ID
- "traceSampled" - the sampling decision of the current span (
"true"or"false")
The tracing data can be accessed with
LogEvent.getContextData()or included in aLayout. For example, the following patterns could be used to include the tracing data with a Pattern Layout:%X{traceId}%X{spanId}%X{traceSampled}
- Since:
- 0.17
- See Also:
- org.apache.logging.log4j.core.ContextDataInjector
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSPAN_ID_CONTEXT_KEYContext key for the current span ID.static java.lang.StringTRACE_ID_CONTEXT_KEYContext key for the current trace ID.static java.lang.StringTRACE_SAMPLED_CONTEXT_KEYContext key for the sampling decision of the current span.
-
Constructor Summary
Constructors Constructor Description OpenCensusTraceContextDataInjector()Constructor to be called by Log4j.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.logging.log4j.util.StringMapinjectContextData(java.util.List<org.apache.logging.log4j.core.config.Property> properties, org.apache.logging.log4j.util.StringMap reusable)org.apache.logging.log4j.util.ReadOnlyStringMaprawContextData()
-
-
-
Field Detail
-
TRACE_ID_CONTEXT_KEY
public static final java.lang.String TRACE_ID_CONTEXT_KEY
Context key for the current trace ID. The name is "traceId".- Since:
- 0.17
- See Also:
- Constant Field Values
-
SPAN_ID_CONTEXT_KEY
public static final java.lang.String SPAN_ID_CONTEXT_KEY
Context key for the current span ID. The name is "spanId".- Since:
- 0.17
- See Also:
- Constant Field Values
-
TRACE_SAMPLED_CONTEXT_KEY
public static final java.lang.String TRACE_SAMPLED_CONTEXT_KEY
Context key for the sampling decision of the current span. The name is "traceSampled".- Since:
- 0.17
- See Also:
- Constant Field Values
-
-
Method Detail
-
injectContextData
public org.apache.logging.log4j.util.StringMap injectContextData(@Nullable java.util.List<org.apache.logging.log4j.core.config.Property> properties, org.apache.logging.log4j.util.StringMap reusable)- Specified by:
injectContextDatain interfaceorg.apache.logging.log4j.core.ContextDataInjector
-
rawContextData
public org.apache.logging.log4j.util.ReadOnlyStringMap rawContextData()
- Specified by:
rawContextDatain interfaceorg.apache.logging.log4j.core.ContextDataInjector
-
-