|
25 | 25 | import com.google.common.util.concurrent.MoreExecutors;
|
26 | 26 | import io.opentelemetry.api.common.Attributes;
|
27 | 27 | import io.opentelemetry.api.trace.SpanKind;
|
| 28 | +import io.opentelemetry.instrumentation.api.internal.SemconvStability; |
28 | 29 | import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
|
29 | 30 | import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
30 | 31 | import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
| 32 | +import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; |
31 | 33 | import io.opentelemetry.sdk.trace.data.StatusData;
|
32 | 34 | import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
|
33 | 35 | import java.net.InetSocketAddress;
|
34 | 36 | import java.time.Duration;
|
| 37 | +import java.util.ArrayList; |
35 | 38 | import java.util.Arrays;
|
36 | 39 | import java.util.Collection;
|
37 | 40 | import java.util.Collections;
|
38 | 41 | import java.util.HashMap;
|
| 42 | +import java.util.List; |
39 | 43 | import java.util.Map;
|
40 | 44 | import java.util.concurrent.ArrayBlockingQueue;
|
41 | 45 | import java.util.concurrent.BlockingQueue;
|
@@ -259,13 +263,22 @@ void getTimeout() throws InterruptedException {
|
259 | 263 | EXCEPTION_STACKTRACE,
|
260 | 264 | val -> val.isInstanceOf(String.class))))
|
261 | 265 | .hasAttributesSatisfyingExactly(
|
262 |
| - equalTo( |
263 |
| - maybeStable(DB_SYSTEM), |
264 |
| - DbIncubatingAttributes.DbSystemIncubatingValues.MEMCACHED), |
265 |
| - equalTo(maybeStable(DB_OPERATION), "get"), |
266 |
| - equalTo( |
267 |
| - ERROR_TYPE, |
268 |
| - "net.spy.memcached.internal.CheckedOperationTimeoutException")))); |
| 266 | + withErrorType( |
| 267 | + "net.spy.memcached.internal.CheckedOperationTimeoutException", |
| 268 | + equalTo( |
| 269 | + maybeStable(DB_SYSTEM), |
| 270 | + DbIncubatingAttributes.DbSystemIncubatingValues.MEMCACHED), |
| 271 | + equalTo(maybeStable(DB_OPERATION), "get"))))); |
| 272 | + } |
| 273 | + |
| 274 | + private static List<AttributeAssertion> withErrorType( |
| 275 | + String errorType, AttributeAssertion... assertions) { |
| 276 | + List<AttributeAssertion> list = new ArrayList<>(Arrays.asList(assertions)); |
| 277 | + |
| 278 | + if (SemconvStability.emitStableDatabaseSemconv()) { |
| 279 | + list.add(equalTo(ERROR_TYPE, errorType)); |
| 280 | + } |
| 281 | + return list; |
269 | 282 | }
|
270 | 283 |
|
271 | 284 | @Test
|
@@ -883,11 +896,12 @@ void decrException() {
|
883 | 896 | .hasException(
|
884 | 897 | new IllegalArgumentException("Key is too long (maxlen = 250)"))
|
885 | 898 | .hasAttributesSatisfyingExactly(
|
886 |
| - equalTo( |
887 |
| - maybeStable(DB_SYSTEM), |
888 |
| - DbIncubatingAttributes.DbSystemIncubatingValues.MEMCACHED), |
889 |
| - equalTo(maybeStable(DB_OPERATION), "decr"), |
890 |
| - equalTo(ERROR_TYPE, "java.lang.IllegalArgumentException")))); |
| 899 | + withErrorType( |
| 900 | + "java.lang.IllegalArgumentException", |
| 901 | + equalTo( |
| 902 | + maybeStable(DB_SYSTEM), |
| 903 | + DbIncubatingAttributes.DbSystemIncubatingValues.MEMCACHED), |
| 904 | + equalTo(maybeStable(DB_OPERATION), "decr"))))); |
891 | 905 | }
|
892 | 906 |
|
893 | 907 | @Test
|
@@ -970,11 +984,12 @@ void incrException() {
|
970 | 984 | .hasException(
|
971 | 985 | new IllegalArgumentException("Key is too long (maxlen = 250)"))
|
972 | 986 | .hasAttributesSatisfyingExactly(
|
973 |
| - equalTo( |
974 |
| - maybeStable(DB_SYSTEM), |
975 |
| - DbIncubatingAttributes.DbSystemIncubatingValues.MEMCACHED), |
976 |
| - equalTo(maybeStable(DB_OPERATION), "incr"), |
977 |
| - equalTo(ERROR_TYPE, "java.lang.IllegalArgumentException")))); |
| 987 | + withErrorType( |
| 988 | + "java.lang.IllegalArgumentException", |
| 989 | + equalTo( |
| 990 | + maybeStable(DB_SYSTEM), |
| 991 | + DbIncubatingAttributes.DbSystemIncubatingValues.MEMCACHED), |
| 992 | + equalTo(maybeStable(DB_OPERATION), "incr"))))); |
978 | 993 | }
|
979 | 994 |
|
980 | 995 | private static String key(String k) {
|
|
0 commit comments