Skip to content

Commit

Permalink
Fix hibernate 6 latest dep test (#8189)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Mar 31, 2023
1 parent 5a14788 commit a9905a2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public void transform(TypeTransformer transformer) {
isMethod()
.and(namedOneOf("openSession", "openStatelessSession"))
.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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public void transform(TypeTransformer transformer) {

transformer.applyAdviceToMethod(
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");
}

Expand Down Expand Up @@ -150,7 +152,11 @@ public static class GetQueryAdvice {

@Advice.OnMethodExit(suppress = Throwable.class)
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.find(SharedSessionContract.class, SessionInfo.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ProcedureCallTest extends AgentInstrumentationSpecification {
kind INTERNAL
childOf span(0)
status ERROR
errorEvent(SQLGrammarException, "could not prepare statement")
errorEvent(SQLGrammarException, ~/could not prepare statement/)
attributes {
"hibernate.session_id" {
sessionId = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id("otel.javaagent-testing")
}

val springAgent by configurations.creating

dependencies {
library("org.hibernate:hibernate-core:6.0.0.Final")

Expand All @@ -14,13 +16,17 @@ dependencies {

testImplementation("org.hsqldb:hsqldb:2.0.0")
testImplementation("org.springframework.data:spring-data-jpa:3.0.0")

springAgent("org.springframework:spring-instrument:6.0.7")
}

otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_17)
}

tasks.withType<Test>().configureEach {
jvmArgs("-javaagent:" + springAgent.singleFile.absolutePath)

// TODO run tests both with and without experimental span attributes
jvmArgs("-Dotel.instrumentation.hibernate.experimental-span-attributes=true")
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_NAME" "test"
"$SemanticAttributes.DB_USER" "sa"
"$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_SQL_TABLE" "Customer"
}
Expand All @@ -156,7 +156,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_NAME" "test"
"$SemanticAttributes.DB_USER" "sa"
"$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_SQL_TABLE" "Customer"
}
Expand Down Expand Up @@ -232,7 +232,7 @@ class SpringJpaTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.DB_NAME" "test"
"$SemanticAttributes.DB_USER" "sa"
"$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_SQL_TABLE" "Customer"
}
Expand Down

0 comments on commit a9905a2

Please sign in to comment.