Skip to content

Commit d5c1707

Browse files
authored
Remaining hibernate metadata (#14597)
1 parent 3fb18c9 commit d5c1707

File tree

6 files changed

+57
-20
lines changed

6 files changed

+57
-20
lines changed

docs/instrumentation-list.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,13 +3526,34 @@ libraries:
35263526
- name: hibernate.session_id
35273527
type: STRING
35283528
- name: hibernate-procedure-call-4.3
3529+
description: This instrumentation enables the generation of INTERNAL spans for
3530+
Hibernate stored procedure calls.
35293531
source_path: instrumentation/hibernate/hibernate-procedure-call-4.3
35303532
scope:
35313533
name: io.opentelemetry.hibernate-procedure-call-4.3
35323534
target_versions:
35333535
javaagent:
35343536
- org.hibernate:hibernate-core:[4.3.0.Final,)
3537+
configurations:
3538+
- name: otel.instrumentation.hibernate.experimental-span-attributes
3539+
description: Enables the addition of the experimental `hibernate.session_id`
3540+
span attribute.
3541+
type: boolean
3542+
default: false
3543+
telemetry:
3544+
- when: default
3545+
spans:
3546+
- span_kind: INTERNAL
3547+
attributes: []
3548+
- when: otel.instrumentation.hibernate.experimental-span-attributes=true
3549+
spans:
3550+
- span_kind: INTERNAL
3551+
attributes:
3552+
- name: hibernate.session_id
3553+
type: STRING
35353554
- name: hibernate-reactive-1.0
3555+
description: |
3556+
This instrumentation does not emit any telemetry on its own. Instead, it enables context propagation for Hibernate Reactive asynchronous operations.
35363557
source_path: instrumentation/hibernate/hibernate-reactive-1.0
35373558
scope:
35383559
name: io.opentelemetry.hibernate-reactive-1.0

instrumentation-docs/instrumentations.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ readonly INSTRUMENTATIONS=(
149149
"hibernate:hibernate-4.0:javaagent:testExperimental"
150150
"hibernate:hibernate-6.0:javaagent:test"
151151
"hibernate:hibernate-6.0:javaagent:testExperimental"
152+
"hibernate:hibernate-procedure-call-4.3:javaagent:test"
153+
"hibernate:hibernate-procedure-call-4.3:javaagent:testExperimental"
152154
)
153155

154156
# Some instrumentation test suites don't run ARM, so we use colima to run them in an x86_64

instrumentation/hibernate/hibernate-procedure-call-4.3/javaagent/build.gradle.kts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
implementation(project(":instrumentation:hibernate:hibernate-common:javaagent"))
1818

1919
testInstrumentation(project(":instrumentation:jdbc:javaagent"))
20+
testImplementation(project(":instrumentation:hibernate:testing"))
2021
// Added to ensure cross compatibility:
2122
testInstrumentation(project(":instrumentation:hibernate:hibernate-3.3:javaagent"))
2223
testInstrumentation(project(":instrumentation:hibernate:hibernate-4.0:javaagent"))
@@ -33,8 +34,15 @@ dependencies {
3334

3435
tasks {
3536
withType<Test>().configureEach {
36-
// TODO run tests both with and without experimental span attributes
37+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
38+
}
39+
40+
val testExperimental by registering(Test::class) {
41+
testClassesDirs = sourceSets.test.get().output.classesDirs
42+
classpath = sourceSets.test.get().runtimeClasspath
43+
3744
jvmArgs("-Dotel.instrumentation.hibernate.experimental-span-attributes=true")
45+
systemProperty("metadataConfig", "otel.instrumentation.hibernate.experimental-span-attributes=true")
3846
}
3947

4048
val testStableSemconv by registering(Test::class) {
@@ -45,6 +53,6 @@ tasks {
4553
}
4654

4755
check {
48-
dependsOn(testStableSemconv)
56+
dependsOn(testStableSemconv, testExperimental)
4957
}
5058
}

instrumentation/hibernate/hibernate-procedure-call-4.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/hibernate/v4_3/ProcedureCallTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
package io.opentelemetry.javaagent.instrumentation.hibernate.v4_3;
77

8-
import static io.opentelemetry.api.common.AttributeKey.stringKey;
98
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
109
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
1110
import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
1211
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
12+
import static io.opentelemetry.javaagent.instrumentation.hibernate.ExperimentalTestHelper.HIBERNATE_SESSION_ID;
13+
import static io.opentelemetry.javaagent.instrumentation.hibernate.ExperimentalTestHelper.experimental;
14+
import static io.opentelemetry.javaagent.instrumentation.hibernate.ExperimentalTestHelper.experimentalSatisfies;
1315
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
14-
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
1516
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_CONNECTION_STRING;
1617
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME;
1718
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
@@ -113,9 +114,9 @@ void testProcedureCall() {
113114
.hasKind(INTERNAL)
114115
.hasParent(trace.getSpan(0))
115116
.hasAttributesSatisfyingExactly(
116-
satisfies(
117-
stringKey("hibernate.session_id"),
118-
val -> val.isInstanceOf(String.class))),
117+
experimentalSatisfies(
118+
HIBERNATE_SESSION_ID,
119+
val -> assertThat(val).isInstanceOf(String.class))),
119120
span ->
120121
span.hasName("CALL test.TEST_PROC")
121122
.hasKind(CLIENT)
@@ -135,11 +136,9 @@ void testProcedureCall() {
135136
.hasParent(trace.getSpan(0))
136137
.hasAttributesSatisfyingExactly(
137138
equalTo(
138-
stringKey("hibernate.session_id"),
139-
trace
140-
.getSpan(1)
141-
.getAttributes()
142-
.get(stringKey("hibernate.session_id"))))));
139+
HIBERNATE_SESSION_ID,
140+
experimental(
141+
trace.getSpan(1).getAttributes().get(HIBERNATE_SESSION_ID))))));
143142
}
144143

145144
@Test
@@ -181,19 +180,17 @@ void testFailingProcedureCall() {
181180
.hasException(exception)
182181
.hasStatus(StatusData.error())
183182
.hasAttributesSatisfyingExactly(
184-
satisfies(
185-
stringKey("hibernate.session_id"),
186-
val -> val.isInstanceOf(String.class))),
183+
experimentalSatisfies(
184+
HIBERNATE_SESSION_ID,
185+
val -> assertThat(val).isInstanceOf(String.class))),
187186
span ->
188187
span.hasName("Transaction.commit")
189188
.hasKind(INTERNAL)
190189
.hasParent(trace.getSpan(0))
191190
.hasAttributesSatisfyingExactly(
192191
equalTo(
193-
stringKey("hibernate.session_id"),
194-
trace
195-
.getSpan(1)
196-
.getAttributes()
197-
.get(stringKey("hibernate.session_id"))))));
192+
HIBERNATE_SESSION_ID,
193+
experimental(
194+
trace.getSpan(1).getAttributes().get(HIBERNATE_SESSION_ID))))));
198195
}
199196
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: This instrumentation enables the generation of INTERNAL spans for Hibernate stored procedure calls.
2+
configurations:
3+
- name: otel.instrumentation.hibernate.experimental-span-attributes
4+
type: boolean
5+
description: Enables the addition of the experimental `hibernate.session_id` span attribute.
6+
default: false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: >
2+
This instrumentation does not emit any telemetry on its own. Instead, it enables context
3+
propagation for Hibernate Reactive asynchronous operations.

0 commit comments

Comments
 (0)