|
16 | 16 | import static io.opentelemetry.instrumentation.testing.util.TestLatestDeps.testLatestDeps; |
17 | 17 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; |
18 | 18 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; |
19 | | -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; |
20 | 19 | import static io.opentelemetry.semconv.DbAttributes.DB_NAMESPACE; |
21 | 20 | import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE; |
22 | 21 | import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_SUMMARY; |
23 | 22 | import static io.opentelemetry.semconv.DbAttributes.DB_STORED_PROCEDURE_NAME; |
24 | 23 | import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME; |
25 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE; |
26 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE; |
27 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE; |
28 | 24 | import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS; |
29 | 25 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_CONNECTION_STRING; |
30 | 26 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME; |
|
36 | 32 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.HSQLDB; |
37 | 33 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.OTHER_SQL; |
38 | 34 | import static java.util.Arrays.asList; |
39 | | -import static java.util.stream.Collectors.toList; |
40 | 35 | import static org.assertj.core.api.Assertions.assertThat; |
41 | 36 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
42 | 37 | import static org.assertj.core.api.Assertions.catchThrowable; |
|
52 | 47 | import io.opentelemetry.instrumentation.jdbc.TestDriver; |
53 | 48 | import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; |
54 | 49 | import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
55 | | -import io.opentelemetry.sdk.logs.data.LogRecordData; |
56 | 50 | import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; |
57 | 51 | import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; |
58 | 52 | import io.opentelemetry.sdk.testing.assertj.TraceAssert; |
|
78 | 72 | import org.apache.derby.jdbc.EmbeddedDataSource; |
79 | 73 | import org.apache.derby.jdbc.EmbeddedDriver; |
80 | 74 | import org.assertj.core.api.ThrowingConsumer; |
81 | | -import org.awaitility.Awaitility; |
82 | 75 | import org.h2.jdbcx.JdbcDataSource; |
83 | 76 | import org.hsqldb.jdbc.JDBCDriver; |
84 | 77 | import org.junit.jupiter.api.BeforeAll; |
@@ -459,30 +452,23 @@ void testFailedStatement() throws SQLException { |
459 | 452 | .hasException(emitExceptionAsSpanEvents() ? error : null))); |
460 | 453 |
|
461 | 454 | if (emitExceptionAsLogs()) { |
462 | | - assertExceptionLog(); |
| 455 | + testing() |
| 456 | + .waitAndAssertLogRecords( |
| 457 | + logRecord -> |
| 458 | + logRecord |
| 459 | + .hasSeverity(Severity.WARN) |
| 460 | + .hasEventName("db.client.operation.exception") |
| 461 | + .hasException(error) |
| 462 | + .hasTotalAttributeCount(3), |
| 463 | + logRecord -> |
| 464 | + logRecord |
| 465 | + .hasSeverity(Severity.WARN) |
| 466 | + .hasEventName("exception") |
| 467 | + .hasException(error) |
| 468 | + .hasTotalAttributeCount(3)); |
463 | 469 | } |
464 | 470 | } |
465 | 471 |
|
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 | | - |
486 | 472 | static Stream<Arguments> preparedStatementStream() throws SQLException { |
487 | 473 | return Stream.of( |
488 | 474 | Arguments.of( |
|
0 commit comments