Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hibernate 6 latest dep test #8189

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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