Skip to content

Commit f10d4d5

Browse files
committed
wip
1 parent 90b0b91 commit f10d4d5

File tree

1 file changed

+70
-42
lines changed

1 file changed

+70
-42
lines changed

instrumentation/rxjava/rxjava-3-common/testing/src/main/java/io/opentelemetry/instrumentation/rxjava/v3/common/AbstractRxJava3WithSpanTest.java

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
package io.opentelemetry.instrumentation.rxjava.v3.common;
77

8+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionSuffixAssertions;
89
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
9-
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
10-
import static io.opentelemetry.semconv.CodeAttributes.CODE_FUNCTION_NAME;
1110
import static org.assertj.core.api.Assertions.assertThat;
1211

1312
import io.opentelemetry.api.common.AttributeKey;
@@ -42,10 +41,6 @@ public abstract class AbstractRxJava3WithSpanTest {
4241

4342
protected abstract InstrumentationExtension testing();
4443

45-
protected static AttributeAssertion assertCodeFunction(String method) {
46-
return satisfies(CODE_FUNCTION_NAME, val -> val.endsWith(".TracedWithSpan." + method));
47-
}
48-
4944
@Test
5045
public void captureSpanForCompletedCompletable() {
5146
TestObserver<Object> observer = new TestObserver<>();
@@ -60,7 +55,8 @@ public void captureSpanForCompletedCompletable() {
6055
span.hasName("TracedWithSpan.completable")
6156
.hasKind(SpanKind.INTERNAL)
6257
.hasNoParent()
63-
.hasAttributesSatisfyingExactly(assertCodeFunction("completable"))));
58+
.hasAttributesSatisfyingExactly(
59+
codeFunctionSuffixAssertions(".TracedWithSpan", "completable"))));
6460
}
6561

6662
@Test
@@ -85,7 +81,8 @@ public void captureSpanForEventuallyCompletedCompletable() throws InterruptedExc
8581
span.hasName("TracedWithSpan.completable")
8682
.hasKind(SpanKind.INTERNAL)
8783
.hasNoParent()
88-
.hasAttributesSatisfyingExactly(assertCodeFunction("completable"))));
84+
.hasAttributesSatisfyingExactly(
85+
codeFunctionSuffixAssertions(".TracedWithSpan", "completable"))));
8986
}
9087

9188
@Test
@@ -105,7 +102,8 @@ public void captureSpanForErrorCompletable() {
105102
.hasNoParent()
106103
.hasStatus(StatusData.error())
107104
.hasException(error)
108-
.hasAttributesSatisfyingExactly(assertCodeFunction("completable"))));
105+
.hasAttributesSatisfyingExactly(
106+
codeFunctionSuffixAssertions(".TracedWithSpan", "completable"))));
109107
}
110108

111109
@Test
@@ -132,7 +130,8 @@ public void captureSpanForEventuallyErrorCompletable() throws InterruptedExcepti
132130
.hasNoParent()
133131
.hasStatus(StatusData.error())
134132
.hasException(error)
135-
.hasAttributesSatisfyingExactly(assertCodeFunction("completable"))));
133+
.hasAttributesSatisfyingExactly(
134+
codeFunctionSuffixAssertions(".TracedWithSpan", "completable"))));
136135
}
137136

138137
@Test
@@ -147,6 +146,7 @@ public void captureSpanForCanceledCompletable() throws InterruptedException {
147146
assertThat(traces).isEmpty();
148147

149148
observer.dispose();
149+
150150
testing()
151151
.waitAndAssertTraces(
152152
trace ->
@@ -156,8 +156,14 @@ public void captureSpanForCanceledCompletable() throws InterruptedException {
156156
.hasKind(SpanKind.INTERNAL)
157157
.hasNoParent()
158158
.hasAttributesSatisfyingExactly(
159-
assertCodeFunction("completable"),
160-
equalTo(RXJAVA_CANCELED, true))));
159+
canceledAttributesAssertions("completable"))));
160+
}
161+
162+
private static List<AttributeAssertion> canceledAttributesAssertions(String methodName) {
163+
List<AttributeAssertion> assertions =
164+
codeFunctionSuffixAssertions(".TracedWithSpan", methodName);
165+
assertions.add(equalTo(RXJAVA_CANCELED, true));
166+
return assertions;
161167
}
162168

163169
@Test
@@ -175,7 +181,8 @@ public void captureSpanForCompletedMaybe() {
175181
span.hasName("TracedWithSpan.maybe")
176182
.hasKind(SpanKind.INTERNAL)
177183
.hasNoParent()
178-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
184+
.hasAttributesSatisfyingExactly(
185+
codeFunctionSuffixAssertions(".TracedWithSpan", "maybe"))));
179186
}
180187

181188
@Test
@@ -192,7 +199,8 @@ public void captureSpanForEmptyMaybe() {
192199
span.hasName("TracedWithSpan.maybe")
193200
.hasKind(SpanKind.INTERNAL)
194201
.hasNoParent()
195-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
202+
.hasAttributesSatisfyingExactly(
203+
codeFunctionSuffixAssertions(".TracedWithSpan", "maybe"))));
196204
}
197205

198206
@Test
@@ -218,7 +226,8 @@ public void captureSpanForEventuallyCompletedMaybe() throws InterruptedException
218226
span.hasName("TracedWithSpan.maybe")
219227
.hasKind(SpanKind.INTERNAL)
220228
.hasNoParent()
221-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
229+
.hasAttributesSatisfyingExactly(
230+
codeFunctionSuffixAssertions(".TracedWithSpan", "maybe"))));
222231
}
223232

224233
@Test
@@ -238,7 +247,8 @@ public void captureSpanForErrorMaybe() {
238247
.hasNoParent()
239248
.hasStatus(StatusData.error())
240249
.hasException(error)
241-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
250+
.hasAttributesSatisfyingExactly(
251+
codeFunctionSuffixAssertions(".TracedWithSpan", "maybe"))));
242252
}
243253

244254
@Test
@@ -266,7 +276,8 @@ public void captureSpanForEventuallyErrorMaybe() throws InterruptedException {
266276
.hasNoParent()
267277
.hasStatus(StatusData.error())
268278
.hasException(error)
269-
.hasAttributesSatisfyingExactly(assertCodeFunction("maybe"))));
279+
.hasAttributesSatisfyingExactly(
280+
codeFunctionSuffixAssertions(".TracedWithSpan", "maybe"))));
270281
}
271282

272283
@Test
@@ -290,7 +301,7 @@ public void captureSpanForCanceledMaybe() throws InterruptedException {
290301
.hasKind(SpanKind.INTERNAL)
291302
.hasNoParent()
292303
.hasAttributesSatisfyingExactly(
293-
assertCodeFunction("maybe"), equalTo(RXJAVA_CANCELED, true))));
304+
canceledAttributesAssertions("maybe"))));
294305
}
295306

296307
@Test
@@ -308,7 +319,8 @@ public void captureSpanForCompletedSingle() {
308319
span.hasName("TracedWithSpan.single")
309320
.hasKind(SpanKind.INTERNAL)
310321
.hasNoParent()
311-
.hasAttributesSatisfyingExactly(assertCodeFunction("single"))));
322+
.hasAttributesSatisfyingExactly(
323+
codeFunctionSuffixAssertions(".TracedWithSpan", "single"))));
312324
}
313325

314326
@Test
@@ -334,7 +346,8 @@ public void captureSpanForEventuallyCompletedSingle() throws InterruptedExceptio
334346
span.hasName("TracedWithSpan.single")
335347
.hasKind(SpanKind.INTERNAL)
336348
.hasNoParent()
337-
.hasAttributesSatisfyingExactly(assertCodeFunction("single"))));
349+
.hasAttributesSatisfyingExactly(
350+
codeFunctionSuffixAssertions(".TracedWithSpan", "single"))));
338351
}
339352

340353
@Test
@@ -354,7 +367,8 @@ public void captureSpanForErrorSingle() {
354367
.hasNoParent()
355368
.hasStatus(StatusData.error())
356369
.hasException(error)
357-
.hasAttributesSatisfyingExactly(assertCodeFunction("single"))));
370+
.hasAttributesSatisfyingExactly(
371+
codeFunctionSuffixAssertions(".TracedWithSpan", "single"))));
358372
}
359373

360374
@Test
@@ -382,7 +396,8 @@ public void captureSpanForEventuallyErrorSingle() throws InterruptedException {
382396
.hasNoParent()
383397
.hasStatus(StatusData.error())
384398
.hasException(error)
385-
.hasAttributesSatisfyingExactly(assertCodeFunction("single"))));
399+
.hasAttributesSatisfyingExactly(
400+
codeFunctionSuffixAssertions(".TracedWithSpan", "single"))));
386401
}
387402

388403
@Test
@@ -406,7 +421,7 @@ public void captureSpanForCanceledSingle() throws InterruptedException {
406421
.hasKind(SpanKind.INTERNAL)
407422
.hasNoParent()
408423
.hasAttributesSatisfyingExactly(
409-
assertCodeFunction("single"), equalTo(RXJAVA_CANCELED, true))));
424+
canceledAttributesAssertions("single"))));
410425
}
411426

412427
@Test
@@ -424,7 +439,8 @@ public void captureSpanForCompletedObservable() {
424439
span.hasName("TracedWithSpan.observable")
425440
.hasKind(SpanKind.INTERNAL)
426441
.hasNoParent()
427-
.hasAttributesSatisfyingExactly(assertCodeFunction("observable"))));
442+
.hasAttributesSatisfyingExactly(
443+
codeFunctionSuffixAssertions(".TracedWithSpan", "observable"))));
428444
}
429445

430446
@Test
@@ -456,7 +472,8 @@ public void captureSpanForEventuallyCompletedObservable() throws InterruptedExce
456472
span.hasName("TracedWithSpan.observable")
457473
.hasKind(SpanKind.INTERNAL)
458474
.hasNoParent()
459-
.hasAttributesSatisfyingExactly(assertCodeFunction("observable"))));
475+
.hasAttributesSatisfyingExactly(
476+
codeFunctionSuffixAssertions(".TracedWithSpan", "observable"))));
460477
}
461478

462479
@Test
@@ -476,7 +493,8 @@ public void captureSpanForErrorObservable() {
476493
.hasNoParent()
477494
.hasStatus(StatusData.error())
478495
.hasException(error)
479-
.hasAttributesSatisfyingExactly(assertCodeFunction("observable"))));
496+
.hasAttributesSatisfyingExactly(
497+
codeFunctionSuffixAssertions(".TracedWithSpan", "observable"))));
480498
}
481499

482500
@Test
@@ -512,7 +530,8 @@ public void captureSpanForEventuallyErrorObservable() throws InterruptedExceptio
512530
.hasNoParent()
513531
.hasStatus(StatusData.error())
514532
.hasException(error)
515-
.hasAttributesSatisfyingExactly(assertCodeFunction("observable"))));
533+
.hasAttributesSatisfyingExactly(
534+
codeFunctionSuffixAssertions(".TracedWithSpan", "observable"))));
516535
}
517536

518537
@Test
@@ -544,7 +563,7 @@ public void captureSpanForCanceledObservable() throws InterruptedException {
544563
.hasKind(SpanKind.INTERNAL)
545564
.hasNoParent()
546565
.hasAttributesSatisfyingExactly(
547-
assertCodeFunction("observable"), equalTo(RXJAVA_CANCELED, true))));
566+
canceledAttributesAssertions("observable"))));
548567
}
549568

550569
@Test
@@ -562,7 +581,8 @@ public void captureSpanForCompletedFlowable() {
562581
span.hasName("TracedWithSpan.flowable")
563582
.hasKind(SpanKind.INTERNAL)
564583
.hasNoParent()
565-
.hasAttributesSatisfyingExactly(assertCodeFunction("flowable"))));
584+
.hasAttributesSatisfyingExactly(
585+
codeFunctionSuffixAssertions(".TracedWithSpan", "flowable"))));
566586
}
567587

568588
@Test
@@ -595,7 +615,8 @@ public void captureForEventuallyCompletedFlowable() throws InterruptedException
595615
span.hasName("TracedWithSpan.flowable")
596616
.hasKind(SpanKind.INTERNAL)
597617
.hasNoParent()
598-
.hasAttributesSatisfyingExactly(assertCodeFunction("flowable"))));
618+
.hasAttributesSatisfyingExactly(
619+
codeFunctionSuffixAssertions(".TracedWithSpan", "flowable"))));
599620
}
600621

601622
@Test
@@ -614,7 +635,8 @@ public void captureSpanForErrorFlowable() {
614635
.hasNoParent()
615636
.hasStatus(StatusData.error())
616637
.hasException(error)
617-
.hasAttributesSatisfyingExactly(assertCodeFunction("flowable"))));
638+
.hasAttributesSatisfyingExactly(
639+
codeFunctionSuffixAssertions(".TracedWithSpan", "flowable"))));
618640
}
619641

620642
@Test
@@ -650,7 +672,8 @@ public void captureSpanForEventuallyErrorFlowable() throws InterruptedException
650672
.hasNoParent()
651673
.hasStatus(StatusData.error())
652674
.hasException(error)
653-
.hasAttributesSatisfyingExactly(assertCodeFunction("flowable"))));
675+
.hasAttributesSatisfyingExactly(
676+
codeFunctionSuffixAssertions(".TracedWithSpan", "flowable"))));
654677
}
655678

656679
@Test
@@ -682,7 +705,7 @@ public void captureSpanForCanceledFlowable() throws InterruptedException {
682705
.hasKind(SpanKind.INTERNAL)
683706
.hasNoParent()
684707
.hasAttributesSatisfyingExactly(
685-
assertCodeFunction("flowable"), equalTo(RXJAVA_CANCELED, true))));
708+
canceledAttributesAssertions("flowable"))));
686709
}
687710

688711
@Test
@@ -701,7 +724,8 @@ public void captureSpanForCompletedParallelFlowable() {
701724
.hasKind(SpanKind.INTERNAL)
702725
.hasNoParent()
703726
.hasAttributesSatisfyingExactly(
704-
assertCodeFunction("parallelFlowable"))));
727+
codeFunctionSuffixAssertions(
728+
".TracedWithSpan", "parallelFlowable"))));
705729
}
706730

707731
@Test
@@ -735,7 +759,8 @@ public void captureSpanForEventuallyCompletedParallelFlowable() throws Interrupt
735759
.hasKind(SpanKind.INTERNAL)
736760
.hasNoParent()
737761
.hasAttributesSatisfyingExactly(
738-
assertCodeFunction("parallelFlowable"))));
762+
codeFunctionSuffixAssertions(
763+
".TracedWithSpan", "parallelFlowable"))));
739764
}
740765

741766
@Test
@@ -756,7 +781,8 @@ public void captureSpanForErrorParallelFlowable() {
756781
.hasStatus(StatusData.error())
757782
.hasException(error)
758783
.hasAttributesSatisfyingExactly(
759-
assertCodeFunction("parallelFlowable"))));
784+
codeFunctionSuffixAssertions(
785+
".TracedWithSpan", "parallelFlowable"))));
760786
}
761787

762788
@Test
@@ -794,7 +820,8 @@ public void captureSpanForEventuallyErrorParallelFlowable() throws InterruptedEx
794820
.hasStatus(StatusData.error())
795821
.hasException(error)
796822
.hasAttributesSatisfyingExactly(
797-
assertCodeFunction("parallelFlowable"))));
823+
codeFunctionSuffixAssertions(
824+
".TracedWithSpan", "parallelFlowable"))));
798825
}
799826

800827
@Test
@@ -827,8 +854,7 @@ public void captureSpanForCanceledParallelFlowable() throws InterruptedException
827854
.hasKind(SpanKind.INTERNAL)
828855
.hasNoParent()
829856
.hasAttributesSatisfyingExactly(
830-
assertCodeFunction("parallelFlowable"),
831-
equalTo(RXJAVA_CANCELED, true))));
857+
canceledAttributesAssertions("parallelFlowable"))));
832858
}
833859

834860
@Test
@@ -852,7 +878,8 @@ public void captureSpanForEventuallyCompletedPublisher() throws InterruptedExcep
852878
span.hasName("TracedWithSpan.publisher")
853879
.hasKind(SpanKind.INTERNAL)
854880
.hasNoParent()
855-
.hasAttributesSatisfyingExactly(assertCodeFunction("publisher"))));
881+
.hasAttributesSatisfyingExactly(
882+
codeFunctionSuffixAssertions(".TracedWithSpan", "publisher"))));
856883
}
857884

858885
@Test
@@ -880,7 +907,8 @@ public void captureSpanForEventuallyErrorPublisher() throws InterruptedException
880907
.hasNoParent()
881908
.hasStatus(StatusData.error())
882909
.hasException(error)
883-
.hasAttributesSatisfyingExactly(assertCodeFunction("publisher"))));
910+
.hasAttributesSatisfyingExactly(
911+
codeFunctionSuffixAssertions(".TracedWithSpan", "publisher"))));
884912
}
885913

886914
@Test
@@ -904,7 +932,7 @@ public void captureSpanForCanceledPublisher() throws InterruptedException {
904932
.hasKind(SpanKind.INTERNAL)
905933
.hasNoParent()
906934
.hasAttributesSatisfyingExactly(
907-
assertCodeFunction("publisher"), equalTo(RXJAVA_CANCELED, true))));
935+
canceledAttributesAssertions("publisher"))));
908936
}
909937

910938
static class CustomPublisher implements Publisher<String>, Subscription {

0 commit comments

Comments
 (0)