use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class ThreadLocalSegmentContext method beginSubsegment.
@Override
public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) {
Entity current = getTraceEntity();
if (null == current) {
recorder.getContextMissingStrategy().contextMissing("Failed to begin subsegment named '" + name + "': segment cannot be found.", SegmentNotFoundException.class);
return null;
}
if (logger.isDebugEnabled()) {
logger.debug("Beginning subsegment named: " + name);
}
Segment parentSegment = getTraceEntity().getParentSegment();
Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSegment);
subsegment.setParent(current);
current.addSubsegment(subsegment);
setTraceEntity(subsegment);
return subsegment;
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testSetTraceEntityInjectsCurrentSegment.
@Test
public void testSetTraceEntityInjectsCurrentSegment() {
Segment segment = AWSXRay.beginSegment("test");
Thread thread = new Thread() {
public void run() {
AWSXRay.setTraceEntity(segment);
Assert.assertEquals(segment, AWSXRay.getTraceEntity());
}
};
thread.start();
try {
thread.join();
} catch (InterruptedException ie) {
}
AWSXRay.endSegment();
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testEmittingSegmentTwiceThrowsSegmentAlreadyEmittedException.
@Test(expected = AlreadyEmittedException.class)
public void testEmittingSegmentTwiceThrowsSegmentAlreadyEmittedException() {
Segment s = AWSXRay.beginSegment("test");
AWSXRay.endSegment();
AWSXRay.injectThreadLocal(s);
AWSXRay.endSegment();
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class EntityTest method testSegmentWithSubsegment.
@Test
public void testSegmentWithSubsegment() throws JSONException {
TraceID traceId = new TraceID();
Segment segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceId);
Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
segment.addSubsegment(subsegment);
segment.setStartTime(1.0);
subsegment.setStartTime(1.0);
subsegment.end();
segment.end();
String expected = expectedCompletedSegmentWithSubsegment(traceId, segment.getId(), subsegment.getId(), 1.0, subsegment.getEndTime(), segment.getEndTime()).toString();
JSONAssert.assertEquals(expected, segment.serialize(), JSONCompareMode.NON_EXTENSIBLE);
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class EntityTest method testInProgressSubsegment.
@Test
public void testInProgressSubsegment() throws JSONException {
Segment parent = AWSXRay.beginSegment("test");
Subsegment subsegment = AWSXRay.beginSubsegment("test");
subsegment.setStartTime(1.0);
String expected = expectedInProgressSubsegment(parent.getTraceId(), parent.getId(), subsegment.getId(), subsegment.getStartTime()).toString();
JSONAssert.assertEquals(expected, subsegment.streamSerialize(), JSONCompareMode.NON_EXTENSIBLE);
}
Aggregations