use of com.amazonaws.xray.entities.SubsegmentImpl in project aws-xray-sdk-java by aws.
the class EntityTest method testEndingSubsegmentImplTwiceThrowsAlreadyEmittedException.
@Test(expected = AlreadyEmittedException.class)
public void testEndingSubsegmentImplTwiceThrowsAlreadyEmittedException() {
SegmentImpl segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test");
segment.getName();
SubsegmentImpl subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
segment.end();
subsegment.end();
subsegment.end();
}
use of com.amazonaws.xray.entities.SubsegmentImpl in project aws-xray-sdk-java by aws.
the class LambdaSegmentContext method beginSubsegment.
@Override
public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) {
if (logger.isDebugEnabled()) {
logger.debug("Beginning subsegment named: " + name);
}
if (null == getTraceEntity()) {
// First subsgment of a subsegment branch.
Segment parentSegment = null;
if (LambdaSegmentContext.isInitializing(LambdaSegmentContext.getTraceHeaderFromEnvironment())) {
logger.warn(LAMBDA_TRACE_HEADER_KEY + " is missing a trace ID, parent ID, or sampling decision. Subsegment " + name + " discarded.");
parentSegment = new FacadeSegment(recorder, new TraceID(), "", SampleDecision.NOT_SAMPLED);
} else {
parentSegment = LambdaSegmentContext.newFacadeSegment(recorder);
}
Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSegment);
subsegment.setParent(parentSegment);
setTraceEntity(subsegment);
return subsegment;
} else {
// Continuation of a subsegment branch.
Subsegment parentSubsegment = (Subsegment) getTraceEntity();
// Ensure customers have not leaked subsegments across invocations
TraceID environmentRootTraceId = LambdaSegmentContext.getTraceHeaderFromEnvironment().getRootTraceId();
if (null != environmentRootTraceId && !environmentRootTraceId.equals(parentSubsegment.getParentSegment().getTraceId())) {
clearTraceEntity();
return beginSubsegment(recorder, name);
}
Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSubsegment.getParentSegment());
subsegment.setParent(parentSubsegment);
parentSubsegment.addSubsegment(subsegment);
setTraceEntity(subsegment);
return subsegment;
}
}
Aggregations