use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class TracedHttpClient method execute.
@Override
public CloseableHttpResponse execute(final HttpHost target, final HttpRequest request) throws IOException, ClientProtocolException {
Subsegment subsegment = recorder.beginSubsegment(target.getHostName());
return wrapHttpSupplier(subsegment, () -> {
TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(target, request));
CloseableHttpResponse response = wrappedClient.execute(target, request);
TracedResponseHandler.addResponseInformation(subsegment, response);
return response;
});
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class TracedHttpClient method execute.
@Override
public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException {
Subsegment subsegment = recorder.beginSubsegment(determineTarget(request).getHostName());
return wrapHttpSupplier(subsegment, () -> {
TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(request));
CloseableHttpResponse response = wrappedClient.execute(request);
TracedResponseHandler.addResponseInformation(subsegment, response);
return response;
});
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class TracedHttpClient method execute.
@Override
public CloseableHttpResponse execute(final HttpHost target, final HttpRequest request, final HttpContext context) throws IOException, ClientProtocolException {
Subsegment subsegment = recorder.beginSubsegment(target.getHostName());
return wrapHttpSupplier(subsegment, () -> {
TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(target, request));
CloseableHttpResponse response = wrappedClient.execute(target, request, context);
TracedResponseHandler.addResponseInformation(subsegment, response);
return response;
});
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testNoOpSubsegment.
@Test
public void testNoOpSubsegment() throws Exception {
Subsegment subsegment = Subsegment.noOp(AWSXRay.getGlobalRecorder(), true);
Map<String, Object> map = new HashMap<>();
map.put("dog", "bark");
// Semantically relevant
assertThat(subsegment.end()).isFalse();
assertThat(subsegment.getName()).isEmpty();
subsegment.setId("foo");
assertThat(subsegment.getId()).isEmpty();
subsegment.setStartTime(100);
assertThat(subsegment.getStartTime()).isZero();
subsegment.setEndTime(100);
assertThat(subsegment.getEndTime()).isZero();
subsegment.setFault(true);
assertThat(subsegment.isFault()).isFalse();
subsegment.setError(true);
assertThat(subsegment.isError()).isFalse();
subsegment.setNamespace("foo");
assertThat(subsegment.getNamespace()).isEmpty();
subsegment.setSubsegmentsLock(new ReentrantLock());
Thread thread = new Thread(() -> subsegment.getSubsegmentsLock().lock());
thread.start();
thread.join();
// No-op lock so we can lock again!
subsegment.getSubsegmentsLock().lock();
assertThat(subsegment.getCause()).isNotNull();
subsegment.setHttp(new HashMap<>());
subsegment.getHttp().put("foo", "bar");
subsegment.putHttp("cat", "meow");
subsegment.putAllHttp(map);
assertThat(subsegment.getHttp()).isEmpty();
subsegment.setAws(new HashMap<>());
subsegment.getAws().put("foo", "bar");
subsegment.putAws("cat", "meow");
subsegment.putAllAws(map);
assertThat(subsegment.getAws()).isEmpty();
subsegment.setSql(new HashMap<>());
subsegment.getSql().put("foo", "bar");
subsegment.putSql("cat", "meow");
subsegment.putAllSql(map);
assertThat(subsegment.getSql()).isEmpty();
subsegment.setMetadata(new HashMap<>());
subsegment.getMetadata().put("foo", new HashMap<>());
subsegment.putMetadata("cat", new HashMap<>());
subsegment.putMetadata("animal", "dog", new HashMap<>());
assertThat(subsegment.getMetadata()).isEmpty();
subsegment.setAnnotations(new HashMap<>());
subsegment.getAnnotations().put("foo", "bar");
subsegment.putAnnotation("cat", "meow");
subsegment.putAnnotation("lives", 9);
subsegment.putAnnotation("alive", true);
assertThat(subsegment.getAnnotations()).isEmpty();
assertThat(subsegment.getParent()).isInstanceOfSatisfying(Segment.class, segment -> assertThat(segment.getTraceId()).isEqualTo(TraceID.invalid()));
subsegment.setThrottle(true);
// Not Full
assertThat(subsegment.isThrottle()).isFalse();
subsegment.setInProgress(true);
assertThat(subsegment.isInProgress()).isFalse();
subsegment.setTraceId(TraceID.create());
assertThat(subsegment.getTraceId()).isEqualTo(TraceID.invalid());
subsegment.setParentId("foo");
assertThat(subsegment.getParentId()).isNull();
subsegment.setCreator(AWSXRayRecorderBuilder.standard().build());
assertThat(subsegment.getCreator()).isEqualTo(AWSXRay.getGlobalRecorder());
assertThat(subsegment.getParentSegment().getTraceId()).isEqualTo(TraceID.invalid());
subsegment.getSubsegments().add(Subsegment.noOp(AWSXRay.getGlobalRecorder(), true));
subsegment.addSubsegment(Subsegment.noOp(AWSXRay.getGlobalRecorder(), true));
assertThat(subsegment.getSubsegments()).isEmpty();
subsegment.addException(new IllegalStateException());
assertThat(subsegment.getReferenceCount()).isZero();
assertThat(subsegment.getTotalSize()).hasValue(0);
assertThat(subsegment.getTotalSize()).hasValue(0);
subsegment.incrementReferenceCount();
assertThat(subsegment.getReferenceCount()).isZero();
subsegment.decrementReferenceCount();
assertThat(subsegment.getReferenceCount()).isZero();
subsegment.removeSubsegment(Subsegment.noOp(AWSXRay.getGlobalRecorder(), true));
subsegment.setEmitted(true);
subsegment.compareAndSetEmitted(false, true);
assertThat(subsegment.isEmitted()).isFalse();
assertThat(subsegment.serialize()).isEmpty();
assertThat(subsegment.prettySerialize()).isEmpty();
assertThat(subsegment.streamSerialize()).isEmpty();
assertThat(subsegment.prettyStreamSerialize()).isEmpty();
subsegment.close();
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testSubsequentSubsegmentBranchesEmittedInLambdaContext.
@Test
public void testSubsequentSubsegmentBranchesEmittedInLambdaContext() {
TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
Emitter mockEmitter = Mockito.mock(Emitter.class);
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
recorder.createSubsegment("testTogether", () -> {
recorder.createSubsegment("testTogether2", () -> {
});
});
recorder.createSubsegment("testTogether3", () -> {
recorder.createSubsegment("testTogether4", () -> {
});
});
ArgumentCaptor<Subsegment> emittedSubsegments = ArgumentCaptor.forClass(Subsegment.class);
Mockito.verify(mockEmitter, Mockito.times(2)).sendSubsegment(emittedSubsegments.capture());
List<Subsegment> captured = emittedSubsegments.getAllValues();
captured.forEach((capturedSubsegment) -> {
Assert.assertEquals(1, capturedSubsegment.getSubsegments().size());
});
}
Aggregations