use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class SqlSubsegmentsTest method testCreateSubsegmentWhenConnectionThrowsException.
@Test
void testCreateSubsegmentWhenConnectionThrowsException() throws SQLException {
when(connection.getMetaData()).thenThrow(new SQLException());
Subsegment sub = SqlSubsegments.forQuery(connection, SQL);
assertThat(AWSXRay.getCurrentSubsegment()).isEqualTo(sub);
assertThat(sub.getName()).isEqualTo(SqlSubsegments.DEFAULT_DATABASE_NAME);
assertThat(sub.isInProgress()).isTrue();
assertThat(sub.getParentSegment().getSubsegments()).contains(sub);
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class SqlSubsegmentsTest method testCreateSubsegmentWithSql.
@Test
void testCreateSubsegmentWithSql() {
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);
expectedSqlParams.put("sanitized_query", SQL);
Subsegment sub = SqlSubsegments.forQuery(connection, SQL);
assertThat(sub.getName()).isEqualTo(CATALOG + "@" + HOST);
assertThat(sub.getNamespace()).isEqualTo(Namespace.REMOTE.toString());
assertThat(sub.getSql()).containsAllEntriesOf(expectedSqlParams);
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class SqlSubsegmentsTest method testDbNameIsNotNull.
@Test
void testDbNameIsNotNull() throws SQLException {
when(connection.getCatalog()).thenReturn(null);
Subsegment sub = SqlSubsegments.forQuery(connection, SQL);
assertThat(sub.getName()).isEqualTo(SqlSubsegments.DEFAULT_DATABASE_NAME + "@" + HOST);
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class SLF4JSegmentListenerTest method testSubsegmentInjection.
@Test
public void testSubsegmentInjection() {
SLF4JSegmentListener listener = (SLF4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
listener.setPrefix("");
Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceID);
listener.onSetEntity(null, seg);
Subsegment sub = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", seg);
listener.onSetEntity(seg, sub);
Assert.assertEquals(traceID.toString() + "@" + sub.getId(), MDC.get(TRACE_ID_KEY));
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class BaseAbstractXRayInterceptor method processXRayTrace.
protected Object processXRayTrace(ProceedingJoinPoint pjp) throws Throwable {
try {
Subsegment subsegment = AWSXRay.beginSubsegment(pjp.getSignature().getName());
if (subsegment != null) {
subsegment.setMetadata(generateMetadata(pjp, subsegment));
}
return XRayInterceptorUtils.conditionalProceed(pjp);
} catch (Exception e) {
AWSXRay.getCurrentSegmentOptional().ifPresent(x -> x.addException(e));
throw e;
} finally {
logger.trace("Ending Subsegment");
AWSXRay.endSubsegment();
}
}
Aggregations