33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6+ import static io .opentelemetry .instrumentation .testing .junit .code .SemconvCodeStabilityUtil .codeFunctionSuffixAssertions ;
67import 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 ;
98import static org .assertj .core .api .Assertions .assertThat ;
109
1110import io .opentelemetry .api .common .AttributeKey ;
1211import io .opentelemetry .api .trace .SpanKind ;
13- import io .opentelemetry .instrumentation .api .internal .SemconvStability ;
1412import io .opentelemetry .instrumentation .rxjava .v2_0 .AbstractTracedWithSpan ;
1513import io .opentelemetry .instrumentation .testing .junit .InstrumentationExtension ;
1614import io .opentelemetry .sdk .testing .assertj .AttributeAssertion ;
1715import io .opentelemetry .sdk .trace .data .SpanData ;
1816import io .opentelemetry .sdk .trace .data .StatusData ;
19- import io .opentelemetry .semconv .incubating .CodeIncubatingAttributes ;
2017import io .reactivex .Completable ;
2118import io .reactivex .Flowable ;
2219import io .reactivex .Maybe ;
2926import io .reactivex .subjects .SingleSubject ;
3027import io .reactivex .subjects .UnicastSubject ;
3128import io .reactivex .subscribers .TestSubscriber ;
32- import java .util .ArrayList ;
3329import java .util .List ;
3430import org .junit .jupiter .api .Test ;
3531import 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
0 commit comments