use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class EntityTest method testModifyingSegmentAfterEndingThrowsAlreadyEmittedException.
@SuppressWarnings("resource")
@Test(expected = AlreadyEmittedException.class)
public void testModifyingSegmentAfterEndingThrowsAlreadyEmittedException() {
TraceID traceId = new TraceID();
Segment segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceId);
segment.end();
segment.setStartTime(1.0);
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class CustomSegmentContextTest method testGlobalMapSegmentContext.
@Test
public void testGlobalMapSegmentContext() {
Segment test = AWSXRay.beginSegment("test");
List<Integer> list = new ArrayList<>();
for (int i = 0; i < 100; i++) {
list.add(new Integer(i));
}
list.parallelStream().forEach(e -> {
AWSXRay.setTraceEntity(test);
AWSXRay.createSubsegment("parallelPrint", (subsegment) -> {
});
});
Assert.assertEquals(100, test.getTotalSize().intValue());
AWSXRay.endSegment();
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class AWSXRayServletFilterTest method testNameOverrideSystemProperty.
@Test
public void testNameOverrideSystemProperty() throws IOException, ServletException {
System.setProperty(SegmentNamingStrategy.NAME_OVERRIDE_SYSTEM_PROPERTY_KEY, "pass");
AWSXRayServletFilter servletFilter = new AWSXRayServletFilter("fail");
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("test_url"));
Mockito.when(request.getMethod()).thenReturn("TEST_METHOD");
Mockito.when(request.isAsyncStarted()).thenReturn(false);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
FilterChain chain = Mockito.mock(FilterChain.class);
servletFilter.doFilter(request, response, chain);
ArgumentCaptor<Segment> emittedSegment = ArgumentCaptor.forClass(Segment.class);
Mockito.verify(AWSXRay.getGlobalRecorder().getEmitter(), Mockito.times(1)).sendSegment(emittedSegment.capture());
Assert.assertEquals("pass", emittedSegment.getValue().getName());
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class AbstractXRayInterceptor method getCurrentSegment.
private static Segment getCurrentSegment() {
Optional<Segment> segment = getCurrentSegmentOptional();
if (segment.isPresent()) {
return segment.get();
}
ContextMissingStrategy contextMissingStrategy = getContextMissingStrategy();
contextMissingStrategy.contextMissing("No segment in progress.", SegmentNotFoundException.class);
return null;
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class TracedHttpClient method addRequestInformation.
public static void addRequestInformation(Subsegment subsegment, HttpRequest request, String url) {
subsegment.setNamespace(Namespace.REMOTE.toString());
Segment parentSegment = subsegment.getParentSegment();
TraceHeader header = new TraceHeader(parentSegment.getTraceId(), parentSegment.isSampled() ? subsegment.getId() : null, parentSegment.isSampled() ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED);
request.addHeader(TraceHeader.HEADER_KEY, header.toString());
Map<String, Object> requestInformation = new HashMap<>();
requestInformation.put("url", url);
requestInformation.put("method", request.getRequestLine().getMethod());
subsegment.putHttp("request", requestInformation);
}
Aggregations