Skip to content

Commit 505d0bb

Browse files
committed
refactor
1 parent 06f4804 commit 505d0bb

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import static io.opentelemetry.javaagent.instrumentation.hibernate.ExperimentalTestHelper.experimental;
1414
import static io.opentelemetry.javaagent.instrumentation.hibernate.ExperimentalTestHelper.experimentalSatisfies;
1515
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
16-
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
1716
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_SUMMARY;
1817
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_CONNECTION_STRING;
1918
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME;
@@ -133,12 +132,9 @@ void testProcedureCall() {
133132
DB_CONNECTION_STRING,
134133
emitStableDatabaseSemconv() ? null : "hsqldb:mem:"),
135134
equalTo(maybeStable(DB_OPERATION), "CALL"),
136-
satisfies(
135+
equalTo(
137136
DB_QUERY_SUMMARY,
138-
val ->
139-
val.satisfiesAnyOf(
140-
v -> assertThat(v).isNull(),
141-
v -> assertThat(v).isInstanceOf(String.class)))),
137+
emitStableDatabaseSemconv() ? "CALL TEST_PROC" : null)),
142138
span ->
143139
span.hasName("Transaction.commit")
144140
.hasKind(INTERNAL)

instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/testing/AbstractJdbcInstrumentationTest.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,17 @@ static Stream<Arguments> statementUpdateStream() throws SQLException {
635635
new org.h2.Driver().connect(jdbcUrls.get("h2"), null),
636636
null,
637637
"CREATE TABLE S_H2 (id INTEGER not NULL, PRIMARY KEY ( id ))",
638-
"CREATE TABLE jdbcunittest.S_H2",
638+
emitStableDatabaseSemconv() ? "CREATE TABLE S_H2" : "CREATE TABLE jdbcunittest.S_H2",
639639
"h2:mem:",
640640
"S_H2"),
641641
Arguments.of(
642642
"derby",
643643
new EmbeddedDriver().connect(jdbcUrls.get("derby"), null),
644644
"APP",
645645
"CREATE TABLE S_DERBY (id INTEGER not NULL, PRIMARY KEY ( id ))",
646-
"CREATE TABLE jdbcunittest.S_DERBY",
646+
emitStableDatabaseSemconv()
647+
? "CREATE TABLE S_DERBY"
648+
: "CREATE TABLE jdbcunittest.S_DERBY",
647649
"derby:memory:",
648650
"S_DERBY"),
649651
Arguments.of(
@@ -659,15 +661,19 @@ static Stream<Arguments> statementUpdateStream() throws SQLException {
659661
cpDatasources.get("tomcat").get("h2").getConnection(),
660662
null,
661663
"CREATE TABLE S_H2_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))",
662-
"CREATE TABLE jdbcunittest.S_H2_TOMCAT",
664+
emitStableDatabaseSemconv()
665+
? "CREATE TABLE S_H2_TOMCAT"
666+
: "CREATE TABLE jdbcunittest.S_H2_TOMCAT",
663667
"h2:mem:",
664668
"S_H2_TOMCAT"),
665669
Arguments.of(
666670
"derby",
667671
cpDatasources.get("tomcat").get("derby").getConnection(),
668672
"APP",
669673
"CREATE TABLE S_DERBY_TOMCAT (id INTEGER not NULL, PRIMARY KEY ( id ))",
670-
"CREATE TABLE jdbcunittest.S_DERBY_TOMCAT",
674+
emitStableDatabaseSemconv()
675+
? "CREATE TABLE S_DERBY_TOMCAT"
676+
: "CREATE TABLE jdbcunittest.S_DERBY_TOMCAT",
671677
"derby:memory:",
672678
"S_DERBY_TOMCAT"),
673679
Arguments.of(
@@ -683,15 +689,19 @@ static Stream<Arguments> statementUpdateStream() throws SQLException {
683689
cpDatasources.get("hikari").get("h2").getConnection(),
684690
null,
685691
"CREATE TABLE S_H2_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))",
686-
"CREATE TABLE jdbcunittest.S_H2_HIKARI",
692+
emitStableDatabaseSemconv()
693+
? "CREATE TABLE S_H2_HIKARI"
694+
: "CREATE TABLE jdbcunittest.S_H2_HIKARI",
687695
"h2:mem:",
688696
"S_H2_HIKARI"),
689697
Arguments.of(
690698
"derby",
691699
cpDatasources.get("hikari").get("derby").getConnection(),
692700
"APP",
693701
"CREATE TABLE S_DERBY_HIKARI (id INTEGER not NULL, PRIMARY KEY ( id ))",
694-
"CREATE TABLE jdbcunittest.S_DERBY_HIKARI",
702+
emitStableDatabaseSemconv()
703+
? "CREATE TABLE S_DERBY_HIKARI"
704+
: "CREATE TABLE jdbcunittest.S_DERBY_HIKARI",
695705
"derby:memory:",
696706
"S_DERBY_HIKARI"),
697707
Arguments.of(
@@ -707,15 +717,19 @@ static Stream<Arguments> statementUpdateStream() throws SQLException {
707717
cpDatasources.get("c3p0").get("h2").getConnection(),
708718
null,
709719
"CREATE TABLE S_H2_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))",
710-
"CREATE TABLE jdbcunittest.S_H2_C3P0",
720+
emitStableDatabaseSemconv()
721+
? "CREATE TABLE S_H2_C3P0"
722+
: "CREATE TABLE jdbcunittest.S_H2_C3P0",
711723
"h2:mem:",
712724
"S_H2_C3P0"),
713725
Arguments.of(
714726
"derby",
715727
cpDatasources.get("c3p0").get("derby").getConnection(),
716728
"APP",
717729
"CREATE TABLE S_DERBY_C3P0 (id INTEGER not NULL, PRIMARY KEY ( id ))",
718-
"CREATE TABLE jdbcunittest.S_DERBY_C3P0",
730+
emitStableDatabaseSemconv()
731+
? "CREATE TABLE S_DERBY_C3P0"
732+
: "CREATE TABLE jdbcunittest.S_DERBY_C3P0",
719733
"derby:memory:",
720734
"S_DERBY_C3P0"),
721735
Arguments.of(
@@ -753,8 +767,7 @@ void testStatementUpdate(
753767
trace.hasSpansSatisfyingExactly(
754768
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
755769
span ->
756-
span.hasName(
757-
emitStableDatabaseSemconv() ? "CREATE TABLE " + table : spanName)
770+
span.hasName(spanName)
758771
.hasKind(SpanKind.CLIENT)
759772
.hasParent(trace.getSpan(0))
760773
.hasAttributesSatisfyingExactly(
@@ -768,9 +781,7 @@ DB_CONNECTION_STRING, emitStableDatabaseSemconv() ? null : url),
768781
equalTo(maybeStable(DB_SQL_TABLE), table),
769782
equalTo(
770783
DB_QUERY_SUMMARY,
771-
emitStableDatabaseSemconv()
772-
? "CREATE TABLE " + table
773-
: null))));
784+
emitStableDatabaseSemconv() ? spanName : null))));
774785
}
775786

776787
static Stream<Arguments> preparedStatementUpdateStream() throws SQLException {

instrumentation/r2dbc-1.0/testing/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/AbstractR2dbcStatementTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,13 @@ void testQueries(Parameter parameter) {
162162
.blockLast(Duration.ofMinutes(1));
163163
});
164164

165-
String spanName =
166-
emitStableDatabaseSemconv()
167-
? parameter.operation + (parameter.table != null ? " " + parameter.table : "")
168-
: parameter.spanName;
169-
170165
getTesting()
171166
.waitAndAssertTraces(
172167
trace ->
173168
trace.hasSpansSatisfyingExactly(
174169
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL),
175170
span ->
176-
span.hasName(spanName)
171+
span.hasName(parameter.spanName)
177172
.hasKind(SpanKind.CLIENT)
178173
.hasParent(trace.getSpan(0))
179174
.hasAttributesSatisfyingExactly(
@@ -190,7 +185,7 @@ void testQueries(Parameter parameter) {
190185
equalTo(maybeStable(DB_SQL_TABLE), parameter.table),
191186
equalTo(
192187
DB_QUERY_SUMMARY,
193-
emitStableDatabaseSemconv() ? spanName : null),
188+
emitStableDatabaseSemconv() ? parameter.spanName : null),
194189
equalTo(PEER_SERVICE, "test-peer-service"),
195190
equalTo(SERVER_ADDRESS, container.getHost()),
196191
equalTo(SERVER_PORT, port)),
@@ -212,7 +207,7 @@ private static Stream<Arguments> provideParameters() {
212207
system.system,
213208
"SELECT 3",
214209
"SELECT ?",
215-
"SELECT " + DB,
210+
emitStableDatabaseSemconv() ? "SELECT" : "SELECT " + DB,
216211
null,
217212
"SELECT"))),
218213
Arguments.of(
@@ -222,7 +217,9 @@ private static Stream<Arguments> provideParameters() {
222217
system.system,
223218
"CREATE TABLE person (id SERIAL PRIMARY KEY, first_name VARCHAR(255), last_name VARCHAR(255))",
224219
"CREATE TABLE person (id SERIAL PRIMARY KEY, first_name VARCHAR(?), last_name VARCHAR(?))",
225-
"CREATE TABLE " + DB + ".person",
220+
emitStableDatabaseSemconv()
221+
? "CREATE TABLE person"
222+
: "CREATE TABLE " + DB + ".person",
226223
"person",
227224
"CREATE TABLE"))),
228225
Arguments.of(
@@ -232,7 +229,9 @@ private static Stream<Arguments> provideParameters() {
232229
system.system,
233230
"INSERT INTO person (id, first_name, last_name) values (1, 'tom', 'johnson')",
234231
"INSERT INTO person (id, first_name, last_name) values (?, ?, ?)",
235-
"INSERT " + DB + ".person",
232+
emitStableDatabaseSemconv()
233+
? "INSERT person"
234+
: "INSERT " + DB + ".person",
236235
"person",
237236
"INSERT"))),
238237
Arguments.of(
@@ -242,7 +241,9 @@ private static Stream<Arguments> provideParameters() {
242241
system.system,
243242
"SELECT * FROM person where first_name = 'tom'",
244243
"SELECT * FROM person where first_name = ?",
245-
"SELECT " + DB + ".person",
244+
emitStableDatabaseSemconv()
245+
? "SELECT person"
246+
: "SELECT " + DB + ".person",
246247
"person",
247248
"SELECT")))));
248249
}

0 commit comments

Comments
 (0)