|
6 | 6 | package io.opentelemetry.javaagent.instrumentation.jdbc.test; |
7 | 7 |
|
8 | 8 | import static io.opentelemetry.api.trace.SpanKind.INTERNAL; |
| 9 | +import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv; |
| 10 | +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable; |
| 11 | +import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStableDbSystemName; |
9 | 12 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; |
10 | 13 | import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION; |
11 | 14 | import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE; |
| 15 | +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_CONNECTION_STRING; |
12 | 16 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME; |
13 | 17 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM; |
14 | | -import static org.assertj.core.api.Assertions.assertThat; |
| 18 | +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_USER; |
15 | 19 |
|
16 | 20 | import com.alibaba.druid.pool.DruidDataSource; |
17 | 21 | import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; |
18 | 22 | import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
19 | | -import io.opentelemetry.sdk.trace.data.SpanData; |
20 | 23 | import java.sql.Connection; |
21 | 24 | import java.sql.SQLException; |
22 | | -import java.util.List; |
23 | | -import java.util.stream.Collectors; |
24 | 25 | import javax.sql.DataSource; |
25 | 26 | import org.junit.jupiter.api.AfterEach; |
26 | 27 | import org.junit.jupiter.api.BeforeEach; |
@@ -73,20 +74,14 @@ void testDruidDataSourceGetConnection() throws SQLException { |
73 | 74 | span.hasName("DruidDataSource.getConnection") |
74 | 75 | .hasKind(INTERNAL) |
75 | 76 | .hasParent(trace.getSpan(0)) |
76 | | - .hasAttributesSatisfying( |
| 77 | + .hasAttributesSatisfyingExactly( |
77 | 78 | equalTo(CODE_NAMESPACE, "com.alibaba.druid.pool.DruidDataSource"), |
78 | 79 | equalTo(CODE_FUNCTION, "getConnection"), |
79 | | - equalTo(DB_SYSTEM, "h2"), |
80 | | - equalTo(DB_NAME, "test")))); |
81 | | - |
82 | | - List<SpanData> spans = testing.spans(); |
83 | | - List<SpanData> dataSourceSpans = |
84 | | - spans.stream() |
85 | | - .filter(span -> span.getName().equals("DruidDataSource.getConnection")) |
86 | | - .collect(Collectors.toList()); |
87 | | - |
88 | | - assertThat(dataSourceSpans) |
89 | | - .as("Should have exactly one DruidDataSource.getConnection span, not duplicates") |
90 | | - .hasSize(1); |
| 80 | + equalTo( |
| 81 | + DB_CONNECTION_STRING, |
| 82 | + emitStableDatabaseSemconv() ? null : "h2:mem:"), |
| 83 | + equalTo(maybeStable(DB_NAME), "test"), |
| 84 | + equalTo(maybeStable(DB_SYSTEM), maybeStableDbSystemName("h2")), |
| 85 | + equalTo(DB_USER, emitStableDatabaseSemconv() ? null : "sa")))); |
91 | 86 | } |
92 | 87 | } |
0 commit comments