Class OpenCensusTraceContextDataInjector

  • All Implemented Interfaces:
    org.apache.logging.log4j.core.ContextDataInjector

    public final class OpenCensusTraceContextDataInjector
    extends java.lang.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:
    org.apache.logging.log4j.core.ContextDataInjector
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SPAN_ID_CONTEXT_KEY
      Context key for the current span ID.
      static java.lang.String TRACE_ID_CONTEXT_KEY
      Context key for the current trace ID.
      static java.lang.String TRACE_SAMPLED_CONTEXT_KEY
      Context key for the sampling decision of the current span.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.logging.log4j.util.StringMap injectContextData​(java.util.List<org.apache.logging.log4j.core.config.Property> properties, org.apache.logging.log4j.util.StringMap reusable)  
      org.apache.logging.log4j.util.ReadOnlyStringMap rawContextData()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • OpenCensusTraceContextDataInjector

        public OpenCensusTraceContextDataInjector()
        Constructor to be called by Log4j.
        Since:
        0.17
    • 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:
        injectContextData in interface org.apache.logging.log4j.core.ContextDataInjector
      • rawContextData

        public org.apache.logging.log4j.util.ReadOnlyStringMap rawContextData()
        Specified by:
        rawContextData in interface org.apache.logging.log4j.core.ContextDataInjector