Skip to content

Commit ecff36d

Browse files
committed
Inline JDBC exception log assertion
1 parent 8bd54c6 commit ecff36d

1 file changed

Lines changed: 10 additions & 24 deletions

File tree

instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/testing/AbstractJdbcInstrumentationTest.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.HSQLDB;
3737
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.OTHER_SQL;
3838
import static java.util.Arrays.asList;
39-
import static java.util.stream.Collectors.toList;
4039
import static org.assertj.core.api.Assertions.assertThat;
4140
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4241
import static org.assertj.core.api.Assertions.catchThrowable;
@@ -52,7 +51,6 @@
5251
import io.opentelemetry.instrumentation.jdbc.TestDriver;
5352
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
5453
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
55-
import io.opentelemetry.sdk.logs.data.LogRecordData;
5654
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
5755
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
5856
import io.opentelemetry.sdk.testing.assertj.TraceAssert;
@@ -78,7 +76,6 @@
7876
import org.apache.derby.jdbc.EmbeddedDataSource;
7977
import org.apache.derby.jdbc.EmbeddedDriver;
8078
import org.assertj.core.api.ThrowingConsumer;
81-
import org.awaitility.Awaitility;
8279
import org.h2.jdbcx.JdbcDataSource;
8380
import org.hsqldb.jdbc.JDBCDriver;
8481
import org.junit.jupiter.api.BeforeAll;
@@ -459,30 +456,19 @@ void testFailedStatement() throws SQLException {
459456
.hasException(emitExceptionAsSpanEvents() ? error : null)));
460457

461458
if (emitExceptionAsLogs()) {
462-
assertExceptionLog();
459+
testing()
460+
.waitAndAssertLogRecords(
461+
logRecord ->
462+
logRecord
463+
.hasSeverity(Severity.WARN)
464+
.hasEventName("db.client.operation.exception")
465+
.hasAttributesSatisfyingExactly(
466+
equalTo(EXCEPTION_TYPE, error.getClass().getName()),
467+
equalTo(EXCEPTION_MESSAGE, error.getMessage()),
468+
satisfies(EXCEPTION_STACKTRACE, val -> val.isNotNull())));
463469
}
464470
}
465471

466-
private void assertExceptionLog() {
467-
Awaitility.await()
468-
.untilAsserted(
469-
() -> {
470-
List<LogRecordData> logs =
471-
testing().logRecords().stream()
472-
.filter(log -> "db.client.operation.exception".equals(log.getEventName()))
473-
.collect(toList());
474-
475-
assertThat(logs).hasSize(1);
476-
assertThat(logs.get(0))
477-
.hasSeverity(Severity.WARN)
478-
.hasEventName("db.client.operation.exception")
479-
.hasAttributesSatisfyingExactly(
480-
satisfies(EXCEPTION_TYPE, val -> val.isNotNull()),
481-
satisfies(EXCEPTION_MESSAGE, val -> val.isNotNull()),
482-
satisfies(EXCEPTION_STACKTRACE, val -> val.isNotNull()));
483-
});
484-
}
485-
486472
static Stream<Arguments> preparedStatementStream() throws SQLException {
487473
return Stream.of(
488474
Arguments.of(

0 commit comments

Comments
 (0)