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 Object
implements org.apache.logging.log4j.core.ContextDataInjector
A Log4j
ContextDataInjector
that 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 a Layout
. 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:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.logging.log4j.util.StringMap
injectContextData
(List<org.apache.logging.log4j.core.config.Property> properties, org.apache.logging.log4j.util.StringMap reusable) org.apache.logging.log4j.util.ReadOnlyStringMap
-
Field Details
-
TRACE_ID_CONTEXT_KEY
Context key for the current trace ID. The name is "traceId".- Since:
- 0.17
- See Also:
-
SPAN_ID_CONTEXT_KEY
Context key for the current span ID. The name is "spanId".- Since:
- 0.17
- See Also:
-
TRACE_SAMPLED_CONTEXT_KEY
Context key for the sampling decision of the current span. The name is "traceSampled".- Since:
- 0.17
- See Also:
-
-
Constructor Details
-
OpenCensusTraceContextDataInjector
public OpenCensusTraceContextDataInjector()Constructor to be called by Log4j.- Since:
- 0.17
-
-
Method Details
-
injectContextData
public org.apache.logging.log4j.util.StringMap injectContextData(@Nullable List<org.apache.logging.log4j.core.config.Property> properties, org.apache.logging.log4j.util.StringMap reusable) - Specified by:
injectContextData
in interfaceorg.apache.logging.log4j.core.ContextDataInjector
-
rawContextData
public org.apache.logging.log4j.util.ReadOnlyStringMap rawContextData()- Specified by:
rawContextData
in interfaceorg.apache.logging.log4j.core.ContextDataInjector
-