Package com.amazonaws.xray.slf4j
Class SLF4JSegmentListener
- java.lang.Object
-
- com.amazonaws.xray.slf4j.SLF4JSegmentListener
-
- All Implemented Interfaces:
SegmentListener
public class SLF4JSegmentListener extends java.lang.Object implements SegmentListener
Implementation of SegmentListener that's used for Trace ID injection into logs that are recorded using the SLF4J frontend API. To inject the X-Ray trace ID into your logging events, insert%X{AWS-XRAY-TRACE-ID}
wherever you feel comfortable in thePatternLayout
of your logging events. For applications that use the Logback backend for SLF4J (the default implementation), refer to the Logback layouts documentation for how to do this. For applications using Log4J as their backend, refer to the Log4j configuration documentation.
-
-
Constructor Summary
Constructors Constructor Description SLF4JSegmentListener()
Returns a defaultSLF4JSegmentListener
usingAWS-XRAY-TRACE-ID
as the prefix for trace ID injectionsSLF4JSegmentListener(java.lang.String prefix)
Returns aSLF4JSegmentListener
using the provided prefix for trace ID injections
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getPrefix()
void
onClearEntity(Entity entity)
Removes the AWS-XRAY-TRACE-ID key from the MDC upon the completion of each segment.void
onSetEntity(Entity oldEntity, Entity newEntity)
Maps the AWS-XRAY-TRACE-ID key to the trace ID of the entity that's just been created in the MDC.void
setPrefix(java.lang.String prefix)
Sets the trace ID injection prefix to provided value.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.amazonaws.xray.listeners.SegmentListener
afterEndSegment, afterEndSubsegment, beforeEndSegment, beforeEndSubsegment, onBeginSegment, onBeginSubsegment
-
-
-
-
Constructor Detail
-
SLF4JSegmentListener
public SLF4JSegmentListener()
Returns a defaultSLF4JSegmentListener
usingAWS-XRAY-TRACE-ID
as the prefix for trace ID injections
-
SLF4JSegmentListener
public SLF4JSegmentListener(java.lang.String prefix)
Returns aSLF4JSegmentListener
using the provided prefix for trace ID injections- Parameters:
prefix
-
-
-
Method Detail
-
getPrefix
public java.lang.String getPrefix()
-
setPrefix
public void setPrefix(java.lang.String prefix)
Sets the trace ID injection prefix to provided value. A colon and space separate the prefix and trace ID, unless theprefix
is null or blank.- Parameters:
prefix
-
-
onSetEntity
public void onSetEntity(Entity oldEntity, Entity newEntity)
Maps the AWS-XRAY-TRACE-ID key to the trace ID of the entity that's just been created in the MDC. Does not perform injection if entity is not available or not sampled, since then the given entity would not be displayed in X-Ray console.- Specified by:
onSetEntity
in interfaceSegmentListener
- Parameters:
oldEntity
- the previous entity or nullnewEntity
- the new entity, either a subsegment or segment
-
onClearEntity
public void onClearEntity(Entity entity)
Removes the AWS-XRAY-TRACE-ID key from the MDC upon the completion of each segment.- Specified by:
onClearEntity
in interfaceSegmentListener
- Parameters:
entity
- The segment that has just ended
-
-