Fix hibernate 6 latest dep test (#8189)

This commit is contained in:
Lauri Tulmin 2023-03-31 15:39:02 +03:00 committed by GitHub
parent 5a14788fc1
commit a9905a22ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 7 deletions

View File

@ -40,7 +40,12 @@ public class SessionFactoryInstrumentation implements TypeInstrumentation {
isMethod() isMethod()
.and(namedOneOf("openSession", "openStatelessSession")) .and(namedOneOf("openSession", "openStatelessSession"))
.and(takesArguments(0)) .and(takesArguments(0))
.and(returns(namedOneOf("org.hibernate.Session", "org.hibernate.StatelessSession"))), .and(
returns(
namedOneOf(
"org.hibernate.Session",
"org.hibernate.StatelessSession",
"org.hibernate.internal.SessionImpl"))),
SessionFactoryInstrumentation.class.getName() + "$SessionFactoryAdvice"); SessionFactoryInstrumentation.class.getName() + "$SessionFactoryAdvice");
} }

View File

@ -85,7 +85,9 @@ public class SessionInstrumentation implements TypeInstrumentation {
transformer.applyAdviceToMethod( transformer.applyAdviceToMethod(
isMethod() isMethod()
.and(returns(implementsInterface(named("org.hibernate.query.CommonQueryContract")))), .and(
returns(implementsInterface(named("org.hibernate.query.CommonQueryContract")))
.or(named("org.hibernate.query.spi.QueryImplementor"))),
SessionInstrumentation.class.getName() + "$GetQueryAdvice"); SessionInstrumentation.class.getName() + "$GetQueryAdvice");
} }
@ -150,7 +152,11 @@ public class SessionInstrumentation implements TypeInstrumentation {
@Advice.OnMethodExit(suppress = Throwable.class) @Advice.OnMethodExit(suppress = Throwable.class)
public static void getQuery( public static void getQuery(
@Advice.This SharedSessionContract session, @Advice.Return CommonQueryContract query) { @Advice.This SharedSessionContract session, @Advice.Return Object queryObject) {
if (!(queryObject instanceof CommonQueryContract)) {
return;
}
CommonQueryContract query = (CommonQueryContract) queryObject;
VirtualField<SharedSessionContract, SessionInfo> sessionVirtualField = VirtualField<SharedSessionContract, SessionInfo> sessionVirtualField =
VirtualField.find(SharedSessionContract.class, SessionInfo.class); VirtualField.find(SharedSessionContract.class, SessionInfo.class);

View File

@ -153,7 +153,7 @@ class ProcedureCallTest extends AgentInstrumentationSpecification {
kind INTERNAL kind INTERNAL
childOf span(0) childOf span(0)
status ERROR status ERROR
errorEvent(SQLGrammarException, "could not prepare statement") errorEvent(SQLGrammarException, ~/could not prepare statement/)
attributes { attributes {
"hibernate.session_id" { "hibernate.session_id" {
sessionId = it sessionId = it

View File

@ -2,6 +2,8 @@ plugins {
id("otel.javaagent-testing") id("otel.javaagent-testing")
} }
val springAgent by configurations.creating
dependencies { dependencies {
library("org.hibernate:hibernate-core:6.0.0.Final") library("org.hibernate:hibernate-core:6.0.0.Final")
@ -14,6 +16,8 @@ dependencies {
testImplementation("org.hsqldb:hsqldb:2.0.0") testImplementation("org.hsqldb:hsqldb:2.0.0")
testImplementation("org.springframework.data:spring-data-jpa:3.0.0") testImplementation("org.springframework.data:spring-data-jpa:3.0.0")
springAgent("org.springframework:spring-instrument:6.0.7")
} }
otelJava { otelJava {
@ -21,6 +25,8 @@ otelJava {
} }
tasks.withType<Test>().configureEach { tasks.withType<Test>().configureEach {
jvmArgs("-javaagent:" + springAgent.singleFile.absolutePath)
// TODO run tests both with and without experimental span attributes // TODO run tests both with and without experimental span attributes
jvmArgs("-Dotel.instrumentation.hibernate.experimental-span-attributes=true") jvmArgs("-Dotel.instrumentation.hibernate.experimental-span-attributes=true")
} }

View File

@ -141,7 +141,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_NAME" "test" "$SemanticAttributes.DB_NAME" "test"
"$SemanticAttributes.DB_USER" "sa" "$SemanticAttributes.DB_USER" "sa"
"$SemanticAttributes.DB_CONNECTION_STRING" "hsqldb:mem:" "$SemanticAttributes.DB_CONNECTION_STRING" "hsqldb:mem:"
"$SemanticAttributes.DB_STATEMENT" ~/insert into Customer \(.*\) values \(.*, \?, \?\)/ "$SemanticAttributes.DB_STATEMENT" ~/insert into Customer \(.*\) values \(.*\)/
"$SemanticAttributes.DB_OPERATION" "INSERT" "$SemanticAttributes.DB_OPERATION" "INSERT"
"$SemanticAttributes.DB_SQL_TABLE" "Customer" "$SemanticAttributes.DB_SQL_TABLE" "Customer"
} }
@ -156,7 +156,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_NAME" "test" "$SemanticAttributes.DB_NAME" "test"
"$SemanticAttributes.DB_USER" "sa" "$SemanticAttributes.DB_USER" "sa"
"$SemanticAttributes.DB_CONNECTION_STRING" "hsqldb:mem:" "$SemanticAttributes.DB_CONNECTION_STRING" "hsqldb:mem:"
"$SemanticAttributes.DB_STATEMENT" ~/insert into Customer \(.*\) values \(.*, \?, \?\)/ "$SemanticAttributes.DB_STATEMENT" ~/insert into Customer \(.*\) values \(.*\)/
"$SemanticAttributes.DB_OPERATION" "INSERT" "$SemanticAttributes.DB_OPERATION" "INSERT"
"$SemanticAttributes.DB_SQL_TABLE" "Customer" "$SemanticAttributes.DB_SQL_TABLE" "Customer"
} }
@ -232,7 +232,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_NAME" "test" "$SemanticAttributes.DB_NAME" "test"
"$SemanticAttributes.DB_USER" "sa" "$SemanticAttributes.DB_USER" "sa"
"$SemanticAttributes.DB_CONNECTION_STRING" "hsqldb:mem:" "$SemanticAttributes.DB_CONNECTION_STRING" "hsqldb:mem:"
"$SemanticAttributes.DB_STATEMENT" "update Customer set firstName=?, lastName=? where id=?" "$SemanticAttributes.DB_STATEMENT" ~/update Customer set firstName=\?,(.*)lastName=\? where id=\?/
"$SemanticAttributes.DB_OPERATION" "UPDATE" "$SemanticAttributes.DB_OPERATION" "UPDATE"
"$SemanticAttributes.DB_SQL_TABLE" "Customer" "$SemanticAttributes.DB_SQL_TABLE" "Customer"
} }