Skip to content

Commit 8cd97cf

Browse files
committed
wip
1 parent f10d4d5 commit 8cd97cf

File tree

2 files changed

+60
-54
lines changed

2 files changed

+60
-54
lines changed

instrumentation/rxjava/rxjava-2.0/javaagent/src/test/java/BaseRxJava2WithSpanTest.java

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionSuffixAssertions;
67
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
7-
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
8-
import static io.opentelemetry.semconv.CodeAttributes.CODE_FUNCTION_NAME;
98
import static org.assertj.core.api.Assertions.assertThat;
109

1110
import io.opentelemetry.api.common.AttributeKey;
1211
import io.opentelemetry.api.trace.SpanKind;
13-
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
1412
import io.opentelemetry.instrumentation.rxjava.v2_0.AbstractTracedWithSpan;
1513
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
1614
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
1715
import io.opentelemetry.sdk.trace.data.SpanData;
1816
import io.opentelemetry.sdk.trace.data.StatusData;
19-
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
2017
import io.reactivex.Completable;
2118
import io.reactivex.Flowable;
2219
import io.reactivex.Maybe;
@@ -29,7 +26,6 @@
2926
import io.reactivex.subjects.SingleSubject;
3027
import io.reactivex.subjects.UnicastSubject;
3128
import io.reactivex.subscribers.TestSubscriber;
32-
import java.util.ArrayList;
3329
import java.util.List;
3430
import org.junit.jupiter.api.Test;
3531
import org.reactivestreams.Publisher;
@@ -44,26 +40,8 @@ public abstract class BaseRxJava2WithSpanTest {
4440

4541
protected abstract InstrumentationExtension testing();
4642

47-
@SuppressWarnings("deprecation") // testing deprecated code semconv
48-
protected static List<AttributeAssertion> assertCodeFunction(String method) {
49-
List<AttributeAssertion> assertions = new ArrayList<>();
50-
if (SemconvStability.isEmitStableCodeSemconv()) {
51-
assertions.add(
52-
satisfies(CODE_FUNCTION_NAME, val -> val.endsWith(".TracedWithSpan." + method)));
53-
}
54-
if (SemconvStability.isEmitOldCodeSemconv()) {
55-
assertions.add(
56-
satisfies(
57-
CodeIncubatingAttributes.CODE_NAMESPACE,
58-
val -> val.endsWith(".TracedWithSpan" + method)));
59-
assertions.add(equalTo(CodeIncubatingAttributes.CODE_FUNCTION, method));
60-
}
61-
62-
return assertions;
63-
}
64-
6543
private static List<AttributeAssertion> assertCancelled(String method) {
66-
List<AttributeAssertion> assertions = assertCodeFunction(method);
44+
List<AttributeAssertion> assertions = codeFunctionSuffixAssertions("TracedWithSpan", method);
6745
assertions.add(equalTo(RXJAVA_CANCELED, true));
6846
return assertions;
6947
}
@@ -82,7 +60,8 @@ public void captureSpanForCompletedCompletable() {
8260
span.hasName("TracedWithSpan.completable")
8361
.hasKind(SpanKind.INTERNAL)
8462
.hasNoParent()
85-
.hasAttributesSatisfyingExactly(assertCodeFunction("completable"))));
63+
.hasAttributesSatisfyingExactly(
64+
codeFunctionSuffixAssertions("TracedWithSpan", "completable"))));
8665
}
8766

8867
@Test
@@ -107,7 +86,8 @@ public void captureSpanForEventuallyCompletedCompletable() throws InterruptedExc
10786
span.hasName("TracedWithSpan.completable")
10887
.hasKind(SpanKind.INTERNAL)
10988
.hasNoParent()
110-
.hasAttributesSatisfyingExactly(assertCodeFunction("completable"))));
89+
.hasAttributesSatisfyingExactly(
90+
codeFunctionSuffixAssertions("TracedWithSpan", "completable"))));
11191
}
11292

11393
@Test
@@ -127,7 +107,8 @@ public void captureSpanForErrorCompletable() {
127107
.hasNoParent()
128108
.hasStatus(StatusData.error())
129109
.hasException(error)
130-
.hasAttributesSatisfyingExactly(assertCodeFunction("completable"))));
110+
.hasAttributesSatisfyingExactly(
111+
codeFunctionSuffixAssertions("TracedWithSpan", "completable"))));
131112
}
132113

133114
@Test
@@ -154,7 +135,8 @@ public void captureSpanForEventuallyErrorCompletable() throws InterruptedExcepti
154135
.hasNoParent()
155136
.hasStatus(StatusData.error())
156137
.hasException(error)
157-
.hasAttributesSatisfyingExactly(assertCodeFunction("completable"))));
138+
.hasAttributesSatisfyingExactly(
139+
codeFunctionSuffixAssertions("TracedWithSpan", "completable"))));
158140
}
159141

160142
@Test
@@ -195,7 +177,8 @@ public void captureSpanForCompletedMaybe() {
195177
span.hasName("TracedWithSpan.maybe")
196178
.hasKind(SpanKind.INTERNAL)
197179
.hasNoParent()
198-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
180+
.hasAttributesSatisfyingExactly(
181+
codeFunctionSuffixAssertions("TracedWithSpan", "maybe"))));
199182
}
200183

201184
@Test
@@ -212,7 +195,8 @@ public void captureSpanForEmptyMaybe() {
212195
span.hasName("TracedWithSpan.maybe")
213196
.hasKind(SpanKind.INTERNAL)
214197
.hasNoParent()
215-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
198+
.hasAttributesSatisfyingExactly(
199+
codeFunctionSuffixAssertions("TracedWithSpan", "maybe"))));
216200
}
217201

218202
@Test
@@ -238,7 +222,8 @@ public void captureSpanForEventuallyCompletedMaybe() throws InterruptedException
238222
span.hasName("TracedWithSpan.maybe")
239223
.hasKind(SpanKind.INTERNAL)
240224
.hasNoParent()
241-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
225+
.hasAttributesSatisfyingExactly(
226+
codeFunctionSuffixAssertions("TracedWithSpan", "maybe"))));
242227
}
243228

244229
@Test
@@ -258,7 +243,8 @@ public void captureSpanForErrorMaybe() {
258243
.hasNoParent()
259244
.hasStatus(StatusData.error())
260245
.hasException(error)
261-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
246+
.hasAttributesSatisfyingExactly(
247+
codeFunctionSuffixAssertions("TracedWithSpan", "maybe"))));
262248
}
263249

264250
@Test
@@ -286,7 +272,8 @@ public void captureSpanForEventuallyErrorMaybe() throws InterruptedException {
286272
.hasNoParent()
287273
.hasStatus(StatusData.error())
288274
.hasException(error)
289-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
275+
.hasAttributesSatisfyingExactly(
276+
codeFunctionSuffixAssertions("TracedWithSpan", "maybe"))));
290277
}
291278

292279
@Test
@@ -327,7 +314,8 @@ public void captureSpanForCompletedSingle() {
327314
span.hasName("TracedWithSpan.single")
328315
.hasKind(SpanKind.INTERNAL)
329316
.hasNoParent()
330-
.hasAttributesSatisfyingExactly(assertCodeFunction("single"))));
317+
.hasAttributesSatisfyingExactly(
318+
codeFunctionSuffixAssertions("TracedWithSpan", "single"))));
331319
}
332320

333321
@Test
@@ -353,7 +341,8 @@ public void captureSpanForEventuallyCompletedSingle() throws InterruptedExceptio
353341
span.hasName("TracedWithSpan.single")
354342
.hasKind(SpanKind.INTERNAL)
355343
.hasNoParent()
356-
.hasAttributesSatisfyingExactly(assertCodeFunction("single"))));
344+
.hasAttributesSatisfyingExactly(
345+
codeFunctionSuffixAssertions("TracedWithSpan", "single"))));
357346
}
358347

359348
@Test
@@ -373,7 +362,8 @@ public void captureSpanForErrorSingle() {
373362
.hasNoParent()
374363
.hasStatus(StatusData.error())
375364
.hasException(error)
376-
.hasAttributesSatisfyingExactly(assertCodeFunction("single"))));
365+
.hasAttributesSatisfyingExactly(
366+
codeFunctionSuffixAssertions("TracedWithSpan", "single"))));
377367
}
378368

379369
@Test
@@ -401,7 +391,8 @@ public void captureSpanForEventuallyErrorSingle() throws InterruptedException {
401391
.hasNoParent()
402392
.hasStatus(StatusData.error())
403393
.hasException(error)
404-
.hasAttributesSatisfyingExactly(assertCodeFunction("single"))));
394+
.hasAttributesSatisfyingExactly(
395+
codeFunctionSuffixAssertions("TracedWithSpan", "single"))));
405396
}
406397

407398
@Test
@@ -442,7 +433,8 @@ public void captureSpanForCompletedObservable() {
442433
span.hasName("TracedWithSpan.observable")
443434
.hasKind(SpanKind.INTERNAL)
444435
.hasNoParent()
445-
.hasAttributesSatisfyingExactly(assertCodeFunction("observable"))));
436+
.hasAttributesSatisfyingExactly(
437+
codeFunctionSuffixAssertions("TracedWithSpan", "observable"))));
446438
}
447439

448440
@Test
@@ -474,7 +466,8 @@ public void captureSpanForEventuallyCompletedObservable() throws InterruptedExce
474466
span.hasName("TracedWithSpan.observable")
475467
.hasKind(SpanKind.INTERNAL)
476468
.hasNoParent()
477-
.hasAttributesSatisfyingExactly(assertCodeFunction("observable"))));
469+
.hasAttributesSatisfyingExactly(
470+
codeFunctionSuffixAssertions("TracedWithSpan", "observable"))));
478471
}
479472

480473
@Test
@@ -494,7 +487,8 @@ public void captureSpanForErrorObservable() {
494487
.hasNoParent()
495488
.hasStatus(StatusData.error())
496489
.hasException(error)
497-
.hasAttributesSatisfyingExactly(assertCodeFunction("observable"))));
490+
.hasAttributesSatisfyingExactly(
491+
codeFunctionSuffixAssertions("TracedWithSpan", "observable"))));
498492
}
499493

500494
@Test
@@ -530,7 +524,8 @@ public void captureSpanForEventuallyErrorObservable() throws InterruptedExceptio
530524
.hasNoParent()
531525
.hasStatus(StatusData.error())
532526
.hasException(error)
533-
.hasAttributesSatisfyingExactly(assertCodeFunction("observable"))));
527+
.hasAttributesSatisfyingExactly(
528+
codeFunctionSuffixAssertions("TracedWithSpan", "observable"))));
534529
}
535530

536531
@Test
@@ -579,7 +574,8 @@ public void captureSpanForCompletedFlowable() {
579574
span.hasName("TracedWithSpan.flowable")
580575
.hasKind(SpanKind.INTERNAL)
581576
.hasNoParent()
582-
.hasAttributesSatisfyingExactly(assertCodeFunction("flowable"))));
577+
.hasAttributesSatisfyingExactly(
578+
codeFunctionSuffixAssertions("TracedWithSpan", "flowable"))));
583579
}
584580

585581
@Test
@@ -612,7 +608,8 @@ public void captureForEventuallyCompletedFlowable() throws InterruptedException
612608
span.hasName("TracedWithSpan.flowable")
613609
.hasKind(SpanKind.INTERNAL)
614610
.hasNoParent()
615-
.hasAttributesSatisfyingExactly(assertCodeFunction("flowable"))));
611+
.hasAttributesSatisfyingExactly(
612+
codeFunctionSuffixAssertions("TracedWithSpan", "flowable"))));
616613
}
617614

618615
@Test
@@ -631,7 +628,8 @@ public void captureSpanForErrorFlowable() {
631628
.hasNoParent()
632629
.hasStatus(StatusData.error())
633630
.hasException(error)
634-
.hasAttributesSatisfyingExactly(assertCodeFunction("flowable"))));
631+
.hasAttributesSatisfyingExactly(
632+
codeFunctionSuffixAssertions("TracedWithSpan", "flowable"))));
635633
}
636634

637635
@Test
@@ -667,7 +665,8 @@ public void captureSpanForEventuallyErrorFlowable() throws InterruptedException
667665
.hasNoParent()
668666
.hasStatus(StatusData.error())
669667
.hasException(error)
670-
.hasAttributesSatisfyingExactly(assertCodeFunction("flowable"))));
668+
.hasAttributesSatisfyingExactly(
669+
codeFunctionSuffixAssertions("TracedWithSpan", "flowable"))));
671670
}
672671

673672
@Test
@@ -717,7 +716,8 @@ public void captureSpanForCompletedParallelFlowable() {
717716
.hasKind(SpanKind.INTERNAL)
718717
.hasNoParent()
719718
.hasAttributesSatisfyingExactly(
720-
assertCodeFunction("parallelFlowable"))));
719+
codeFunctionSuffixAssertions(
720+
"TracedWithSpan", "parallelFlowable"))));
721721
}
722722

723723
@Test
@@ -751,7 +751,8 @@ public void captureSpanForEventuallyCompletedParallelFlowable() throws Interrupt
751751
.hasKind(SpanKind.INTERNAL)
752752
.hasNoParent()
753753
.hasAttributesSatisfyingExactly(
754-
assertCodeFunction("parallelFlowable"))));
754+
codeFunctionSuffixAssertions(
755+
"TracedWithSpan", "parallelFlowable"))));
755756
}
756757

757758
@Test
@@ -772,7 +773,8 @@ public void captureSpanForErrorParallelFlowable() {
772773
.hasStatus(StatusData.error())
773774
.hasException(error)
774775
.hasAttributesSatisfyingExactly(
775-
assertCodeFunction("parallelFlowable"))));
776+
codeFunctionSuffixAssertions(
777+
"TracedWithSpan", "parallelFlowable"))));
776778
}
777779

778780
@Test
@@ -810,7 +812,8 @@ public void captureSpanForEventuallyErrorParallelFlowable() throws InterruptedEx
810812
.hasStatus(StatusData.error())
811813
.hasException(error)
812814
.hasAttributesSatisfyingExactly(
813-
assertCodeFunction("parallelFlowable"))));
815+
codeFunctionSuffixAssertions(
816+
"TracedWithSpan", "parallelFlowable"))));
814817
}
815818

816819
@Test
@@ -866,7 +869,8 @@ public void captureSpanForEventuallyCompletedPublisher() throws InterruptedExcep
866869
span.hasName("TracedWithSpan.publisher")
867870
.hasKind(SpanKind.INTERNAL)
868871
.hasNoParent()
869-
.hasAttributesSatisfyingExactly(assertCodeFunction("publisher"))));
872+
.hasAttributesSatisfyingExactly(
873+
codeFunctionSuffixAssertions("TracedWithSpan", "publisher"))));
870874
}
871875

872876
@Test
@@ -894,7 +898,8 @@ public void captureSpanForEventuallyErrorPublisher() throws InterruptedException
894898
.hasNoParent()
895899
.hasStatus(StatusData.error())
896900
.hasException(error)
897-
.hasAttributesSatisfyingExactly(assertCodeFunction("publisher"))));
901+
.hasAttributesSatisfyingExactly(
902+
codeFunctionSuffixAssertions("TracedWithSpan", "publisher"))));
898903
}
899904

900905
@Test

instrumentation/spring/spring-webmvc/spring-webmvc-common/testing/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/boot/AbstractSpringBootBasedTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.instrumentation.spring.webmvc.boot;
77

8+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionAssertions;
9+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionSuffixAssertions;
810
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_ERROR;
911
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS;
1012
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
@@ -150,7 +152,7 @@ protected List<Consumer<SpanDataAssert>> errorPageSpanAssertions(
150152
span.hasName("BasicErrorController.error")
151153
.hasKind(SpanKind.INTERNAL)
152154
.hasAttributesSatisfyingExactly(
153-
satisfies(CODE_FUNCTION_NAME, v -> v.endsWith(".BasicErrorController.error"))));
155+
codeFunctionSuffixAssertions(".BasicErrorController", "error")));
154156
return spanAssertions;
155157
}
156158

@@ -210,10 +212,9 @@ protected SpanDataAssert assertHandlerSpan(
210212
codeNamespace = ResourceHttpRequestHandler.class.getName();
211213
}
212214
String codeFunction = handlerSpanName.substring(handlerSpanName.indexOf('.') + 1);
213-
codeFunction = codeNamespace + "." + codeFunction;
214215
span.hasName(handlerSpanName)
215216
.hasKind(SpanKind.INTERNAL)
216-
.hasAttributesSatisfyingExactly(equalTo(CODE_FUNCTION_NAME, codeFunction));
217+
.hasAttributesSatisfyingExactly(codeFunctionAssertions(codeNamespace, codeFunction));
217218
if (endpoint == EXCEPTION) {
218219
span.hasStatus(StatusData.error());
219220
span.hasEventsSatisfyingExactly(

0 commit comments

Comments
 (0)