diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/LambdaSegmentContext.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/LambdaSegmentContext.java index 85d690fe..bb92a166 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/LambdaSegmentContext.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/LambdaSegmentContext.java @@ -23,7 +23,6 @@ import com.amazonaws.xray.entities.Subsegment; import com.amazonaws.xray.entities.SubsegmentImpl; import com.amazonaws.xray.entities.TraceHeader; -import com.amazonaws.xray.entities.TraceHeader.SampleDecision; import com.amazonaws.xray.entities.TraceID; import com.amazonaws.xray.exceptions.SubsegmentNotFoundException; import com.amazonaws.xray.listeners.SegmentListener; @@ -36,14 +35,14 @@ public class LambdaSegmentContext implements SegmentContext { private static final Log logger = LogFactory.getLog(LambdaSegmentContext.class); private static final String LAMBDA_TRACE_HEADER_KEY = "_X_AMZN_TRACE_ID"; - + // See: https://github.com/aws/aws-xray-sdk-java/issues/251 private static final String LAMBDA_TRACE_HEADER_PROP = "com.amazonaws.xray.traceHeader"; private static TraceHeader getTraceHeaderFromEnvironment() { String lambdaTraceHeaderKey = System.getenv(LAMBDA_TRACE_HEADER_KEY); - return TraceHeader.fromString(lambdaTraceHeaderKey != null && lambdaTraceHeaderKey.length() > 0 - ? lambdaTraceHeaderKey + return TraceHeader.fromString(lambdaTraceHeaderKey != null && lambdaTraceHeaderKey.length() > 0 + ? lambdaTraceHeaderKey : System.getProperty(LAMBDA_TRACE_HEADER_PROP)); } @@ -67,7 +66,12 @@ public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) { } parentSegment = Segment.noOp(TraceID.create(recorder), recorder); } else { - parentSegment = new FacadeSegment(recorder, traceHeader.getRootTraceId(), traceHeader.getParentId(), traceHeader.getSampled()); + parentSegment = new FacadeSegment( + recorder, + traceHeader.getRootTraceId(), + traceHeader.getParentId(), + traceHeader.getSampled() + ); } boolean isRecording = parentSegment.isRecording(); @@ -145,8 +149,7 @@ public void endSubsegment(AWSXRayRecorder recorder) { current.getCreator().getEmitter().sendSubsegment((Subsegment) current); } clearTraceEntity(); - } - else if (parentEntity instanceof NoOpSegment) { + } else if (parentEntity instanceof NoOpSegment) { clearTraceEntity(); } else { setTraceEntity(current.getParent());