1010import static io .opentelemetry .api .trace .SpanKind .INTERNAL ;
1111import static io .opentelemetry .instrumentation .testing .util .TelemetryDataUtil .orderByRootSpanName ;
1212import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .equalTo ;
13+ import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .satisfies ;
1314import static io .opentelemetry .sdk .testing .assertj .TracesAssert .assertThat ;
14- import static io .opentelemetry .semconv .incubating .CodeIncubatingAttributes .CODE_FUNCTION ;
15- import static io .opentelemetry .semconv .incubating .CodeIncubatingAttributes .CODE_NAMESPACE ;
15+ import static io .opentelemetry .semconv .incubating .CodeIncubatingAttributes .CODE_FUNCTION_NAME ;
1616import static org .assertj .core .api .Assertions .assertThatThrownBy ;
1717
1818import io .opentelemetry .api .OpenTelemetry ;
1919import io .opentelemetry .instrumentation .annotations .SpanAttribute ;
2020import io .opentelemetry .instrumentation .annotations .WithSpan ;
2121import io .opentelemetry .instrumentation .testing .junit .LibraryInstrumentationExtension ;
22+ import io .opentelemetry .sdk .testing .assertj .AttributeAssertion ;
2223import io .opentelemetry .sdk .trace .data .SpanData ;
2324import io .opentelemetry .sdk .trace .data .StatusData ;
2425import java .lang .reflect .Constructor ;
@@ -49,6 +50,11 @@ WithSpanAspect newWithSpanAspect(
4950 return new InstrumentationWithSpanAspect (openTelemetry , parameterNameDiscoverer );
5051 }
5152
53+ protected AttributeAssertion assertCodeAttributes (String method ) {
54+ return satisfies (
55+ CODE_FUNCTION_NAME , val -> val .endsWith (unproxiedTesterClassName + "." + method ));
56+ }
57+
5258 @ BeforeEach
5359 void setup () {
5460 InstrumentationWithSpanTester unproxiedTester = new InstrumentationWithSpanTester ();
@@ -91,9 +97,7 @@ void withSpanWithDefaults() {
9197 span .hasName (unproxiedTesterSimpleClassName + ".testWithSpan" )
9298 .hasKind (INTERNAL )
9399 .hasParent (trace .getSpan (0 ))
94- .hasAttributesSatisfyingExactly (
95- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
96- equalTo (CODE_FUNCTION , "testWithSpan" ))));
100+ .hasAttributesSatisfyingExactly (assertCodeAttributes ("testWithSpan" ))));
97101 }
98102
99103 @ Test
@@ -115,8 +119,7 @@ void withSpanName() {
115119 .hasKind (INTERNAL )
116120 .hasParent (trace .getSpan (0 ))
117121 .hasAttributesSatisfyingExactly (
118- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
119- equalTo (CODE_FUNCTION , "testWithSpanWithValue" ))));
122+ assertCodeAttributes ("testWithSpanWithValue" ))));
120123 }
121124
122125 @ Test
@@ -134,8 +137,7 @@ void withSpanError() {
134137 .hasKind (INTERNAL )
135138 .hasStatus (StatusData .error ())
136139 .hasAttributesSatisfyingExactly (
137- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
138- equalTo (CODE_FUNCTION , "testWithSpanWithException" ))));
140+ assertCodeAttributes ("testWithSpanWithException" ))));
139141 }
140142
141143 @ Test
@@ -155,8 +157,7 @@ void withSpanKind() {
155157 .hasKind (CLIENT )
156158 .hasParent (trace .getSpan (0 ))
157159 .hasAttributesSatisfyingExactly (
158- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
159- equalTo (CODE_FUNCTION , "testWithClientSpan" ))));
160+ assertCodeAttributes ("testWithClientSpan" ))));
160161 }
161162
162163 @ Test
@@ -175,8 +176,7 @@ void withSpanAttributes() {
175176 .hasKind (INTERNAL )
176177 .hasParent (trace .getSpan (0 ))
177178 .hasAttributesSatisfyingExactly (
178- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
179- equalTo (CODE_FUNCTION , "withSpanAttributes" ),
179+ assertCodeAttributes ("withSpanAttributes" ),
180180 equalTo (stringKey ("discoveredName" ), "foo" ),
181181 equalTo (stringKey ("implicitName" ), "bar" ),
182182 equalTo (stringKey ("explicitName" ), "baz" ))));
@@ -200,8 +200,7 @@ void withSpanWithoutParent() {
200200 .hasKind (INTERNAL )
201201 .hasNoParent ()
202202 .hasAttributesSatisfyingExactly (
203- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
204- equalTo (CODE_FUNCTION , "testWithoutParentSpan" ))));
203+ assertCodeAttributes ("testWithoutParentSpan" ))));
205204 }
206205
207206 static class InstrumentationWithSpanTester {
@@ -284,8 +283,7 @@ void onComplete() {
284283 .hasKind (INTERNAL )
285284 .hasParent (trace .getSpan (0 ))
286285 .hasAttributesSatisfyingExactly (
287- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
288- equalTo (CODE_FUNCTION , "testAsyncCompletionStage" ))));
286+ assertCodeAttributes ("testAsyncCompletionStage" ))));
289287 }
290288
291289 @ Test
@@ -317,8 +315,7 @@ void onCompleteExceptionally() {
317315 .hasStatus (StatusData .error ())
318316 .hasParent (trace .getSpan (0 ))
319317 .hasAttributesSatisfyingExactly (
320- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
321- equalTo (CODE_FUNCTION , "testAsyncCompletionStage" ))));
318+ assertCodeAttributes ("testAsyncCompletionStage" ))));
322319 }
323320
324321 @ Test
@@ -337,8 +334,7 @@ void onIncompatibleReturnValue() {
337334 .hasKind (INTERNAL )
338335 .hasParent (trace .getSpan (0 ))
339336 .hasAttributesSatisfyingExactly (
340- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
341- equalTo (CODE_FUNCTION , "testAsyncCompletionStage" ))));
337+ assertCodeAttributes ("testAsyncCompletionStage" ))));
342338 }
343339 }
344340
@@ -374,8 +370,7 @@ void onComplete() {
374370 .hasKind (INTERNAL )
375371 .hasParent (trace .getSpan (0 ))
376372 .hasAttributesSatisfyingExactly (
377- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
378- equalTo (CODE_FUNCTION , "testAsyncCompletableFuture" ))));
373+ assertCodeAttributes ("testAsyncCompletableFuture" ))));
379374 }
380375
381376 @ Test
@@ -407,8 +402,7 @@ void onCompleteExceptionally() {
407402 .hasStatus (StatusData .error ())
408403 .hasParent (trace .getSpan (0 ))
409404 .hasAttributesSatisfyingExactly (
410- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
411- equalTo (CODE_FUNCTION , "testAsyncCompletableFuture" ))));
405+ assertCodeAttributes ("testAsyncCompletableFuture" ))));
412406 }
413407
414408 @ Test
@@ -429,8 +423,7 @@ void onCompletedFuture() {
429423 .hasKind (INTERNAL )
430424 .hasParent (trace .getSpan (0 ))
431425 .hasAttributesSatisfyingExactly (
432- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
433- equalTo (CODE_FUNCTION , "testAsyncCompletableFuture" ))));
426+ assertCodeAttributes ("testAsyncCompletableFuture" ))));
434427 }
435428
436429 @ Test
@@ -453,8 +446,7 @@ void onFailedFuture() {
453446 .hasStatus (StatusData .error ())
454447 .hasParent (trace .getSpan (0 ))
455448 .hasAttributesSatisfyingExactly (
456- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
457- equalTo (CODE_FUNCTION , "testAsyncCompletableFuture" ))));
449+ assertCodeAttributes ("testAsyncCompletableFuture" ))));
458450 }
459451
460452 @ Test
@@ -473,8 +465,7 @@ void onIncompatibleReturnValue() {
473465 .hasKind (INTERNAL )
474466 .hasParent (trace .getSpan (0 ))
475467 .hasAttributesSatisfyingExactly (
476- equalTo (CODE_NAMESPACE , unproxiedTesterClassName ),
477- equalTo (CODE_FUNCTION , "testAsyncCompletableFuture" ))));
468+ assertCodeAttributes ("testAsyncCompletableFuture" ))));
478469 }
479470 }
480471}
0 commit comments