use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testSetTraceEntityInjectsCurrentSubsegment.
@Test
public void testSetTraceEntityInjectsCurrentSubsegment() throws Exception {
AWSXRay.beginSegment("test");
Subsegment subsegment = AWSXRay.beginSubsegment("test");
threadExecutor.submit(() -> {
AWSXRay.setTraceEntity(subsegment);
Assert.assertEquals(subsegment, AWSXRay.getThreadLocal());
}).get();
AWSXRay.endSubsegment();
AWSXRay.endSegment();
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class DefaultStreamingStrategy method stream.
private boolean stream(Entity entity, Emitter emitter) {
List<Subsegment> children = entity.getSubsegmentsCopy();
List<Subsegment> streamable = new ArrayList<>();
// Gather children and in the condition they are ready to stream, add them to the streamable list.
if (children.size() > 0) {
for (Subsegment child : children) {
if (stream(child, emitter)) {
streamable.add(child);
}
}
}
// A subsegment is marked streamable if all of its children are streamable and the entity itself is not in progress.
if (children.size() == streamable.size() && !entity.isInProgress()) {
return true;
}
// Stream the subtrees that are ready.
for (Subsegment child : streamable) {
emitter.sendSubsegment(child);
entity.removeSubsegment(child);
}
return false;
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class TracingStatementTest method assertSubsegment.
private void assertSubsegment() {
Subsegment subsegment = AWSXRay.getCurrentSegment().getSubsegments().get(0);
assertEquals(CATALOG + "@" + HOST, subsegment.getName());
assertEquals(Namespace.REMOTE.toString(), subsegment.getNamespace());
assertEquals(expectedSqlParams, subsegment.getSql());
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class LambdaSegmentContextTest method testLeakedSubsegmentsAreCleanedBetweenInvocations.
@Test
public void testLeakedSubsegmentsAreCleanedBetweenInvocations() {
LambdaSegmentContext lsc = new LambdaSegmentContext();
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(TraceHeader.fromString(TRACE_HEADER));
Subsegment firstInvocation = lsc.beginSubsegment(AWSXRay.getGlobalRecorder(), "test");
Assert.assertNotNull(AWSXRay.getTraceEntity());
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(TraceHeader.fromString(TRACE_HEADER_2));
Subsegment secondInvocation = lsc.beginSubsegment(AWSXRay.getGlobalRecorder(), "test");
Assert.assertNotNull(AWSXRay.getTraceEntity());
Assert.assertTrue(FacadeSegment.class.isInstance(firstInvocation.getParent()));
Assert.assertTrue(FacadeSegment.class.isInstance(secondInvocation.getParent()));
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class SqlSubsegmentsTest method testCreateSubsegmentWithoutSql.
@Test
void testCreateSubsegmentWithoutSql() {
expectedSqlParams = new HashMap<>();
expectedSqlParams.put("url", URL);
expectedSqlParams.put("user", USER);
expectedSqlParams.put("driver_version", DRIVER_VERSION);
expectedSqlParams.put("database_type", DB_TYPE);
expectedSqlParams.put("database_version", DB_VERSION);
Subsegment sub = SqlSubsegments.forQuery(connection, null);
assertThat(sub.getName()).isEqualTo(CATALOG + "@" + HOST);
assertThat(sub.getNamespace()).isEqualTo(Namespace.REMOTE.toString());
assertThat(sub.getSql()).containsAllEntriesOf(expectedSqlParams);
}
Aggregations