|
@@ -5,6 +5,7 @@
|
|
|
|
|
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
|
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
|
|
+import static org.assertj.core.api.Assertions.catchThrowableOfType;
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
@@ -15,11 +16,14 @@ import io.opentelemetry.api.trace.SpanKind;
|
|
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
|
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
|
|
import io.opentelemetry.sdk.testing.assertj.TraceAssert;
|
|
|
+import io.opentelemetry.sdk.trace.data.StatusData;
|
|
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
import org.hibernate.Version;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
|
|
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
|
|
|
|
public abstract class AbstractSpringJpaTest<
|
|
@@ -42,6 +46,8 @@ public abstract class AbstractSpringJpaTest<
|
|
|
|
|
|
abstract List<ENTITY> findSpecialCustomers(REPOSITORY repository);
|
|
|
|
|
|
+ abstract Optional<ENTITY> findOneByLastName(REPOSITORY repository, String lastName);
|
|
|
+
|
|
|
void clearData() {
|
|
|
testing.clearData();
|
|
|
}
|
|
@@ -319,4 +325,52 @@ public abstract class AbstractSpringJpaTest<
|
|
|
equalTo(SemanticAttributes.DB_OPERATION, "SELECT"),
|
|
|
equalTo(SemanticAttributes.DB_SQL_TABLE, "JpaCustomer"))));
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testFailedRepositoryMethod() {
|
|
|
+ // given
|
|
|
+ REPOSITORY repo = repository();
|
|
|
+ String repoClassName = repositoryClass().getName();
|
|
|
+
|
|
|
+ String commonLastName = "Smith";
|
|
|
+ repo.save(newCustomer("Alice", commonLastName));
|
|
|
+ repo.save(newCustomer("Bob", commonLastName));
|
|
|
+ clearData();
|
|
|
+
|
|
|
+ // when
|
|
|
+ IncorrectResultSizeDataAccessException expectedException =
|
|
|
+ catchThrowableOfType(
|
|
|
+ () -> findOneByLastName(repo, commonLastName),
|
|
|
+ IncorrectResultSizeDataAccessException.class);
|
|
|
+
|
|
|
+ // then
|
|
|
+ assertNotNull(expectedException);
|
|
|
+ testing.waitAndAssertTraces(
|
|
|
+ trace ->
|
|
|
+ trace
|
|
|
+ .hasSize(2)
|
|
|
+ .hasSpansSatisfyingExactly(
|
|
|
+ span ->
|
|
|
+ span.hasName("JpaCustomerRepository.findOneByLastName")
|
|
|
+ .hasKind(SpanKind.INTERNAL)
|
|
|
+ .hasStatus(StatusData.error())
|
|
|
+ .hasException(expectedException)
|
|
|
+ .hasAttributesSatisfyingExactly(
|
|
|
+ equalTo(SemanticAttributes.CODE_NAMESPACE, repoClassName),
|
|
|
+ equalTo(SemanticAttributes.CODE_FUNCTION, "findOneByLastName")),
|
|
|
+ span ->
|
|
|
+ span.hasName("SELECT test.JpaCustomer")
|
|
|
+ .hasKind(SpanKind.CLIENT)
|
|
|
+ .hasParent(trace.getSpan(0))
|
|
|
+ .hasAttributesSatisfyingExactly(
|
|
|
+ equalTo(SemanticAttributes.DB_SYSTEM, "hsqldb"),
|
|
|
+ equalTo(SemanticAttributes.DB_NAME, "test"),
|
|
|
+ equalTo(SemanticAttributes.DB_USER, "sa"),
|
|
|
+ equalTo(SemanticAttributes.DB_CONNECTION_STRING, "hsqldb:mem:"),
|
|
|
+ satisfies(
|
|
|
+ SemanticAttributes.DB_STATEMENT,
|
|
|
+ val -> val.startsWith("select ")),
|
|
|
+ equalTo(SemanticAttributes.DB_OPERATION, "SELECT"),
|
|
|
+ equalTo(SemanticAttributes.DB_SQL_TABLE, "JpaCustomer"))));
|
|
|
+ }
|
|
|
}
|