Skip to content

Commit 6cea7d7

Browse files
committed
wip
1 parent 4e4fd26 commit 6cea7d7

File tree

5 files changed

+56
-54
lines changed
  • instrumentation
    • jaxrs/jaxrs-common/testing/src/main/java/io/opentelemetry/instrumentation/jaxrs
    • opentelemetry-api/opentelemetry-api-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi
    • spring
      • spring-data/spring-data-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data
      • spring-scheduling-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/v3_1
      • spring-webmvc/spring-webmvc-6.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/boot

5 files changed

+56
-54
lines changed

instrumentation/jaxrs/jaxrs-common/testing/src/main/java/io/opentelemetry/instrumentation/jaxrs/AbstractJaxRsHttpServerTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
package io.opentelemetry.instrumentation.jaxrs;
77

8+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionAssertions;
89
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
10-
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
11-
import static io.opentelemetry.semconv.CodeAttributes.CODE_FUNCTION_NAME;
1211
import static java.util.concurrent.TimeUnit.SECONDS;
1312
import static org.assertj.core.api.Assertions.assertThat;
1413
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@@ -18,6 +17,7 @@
1817
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
1918
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
2019
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
20+
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
2121
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
2222
import io.opentelemetry.sdk.trace.data.StatusData;
2323
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse;
@@ -189,6 +189,14 @@ void shouldHandleAsyncResponse(AsyncResponseTestKind testKind) throws Exception
189189
assertThat(response.status().code()).isEqualTo(testKind.statusCode);
190190
testKind.assertBody(response.contentUtf8());
191191

192+
List<AttributeAssertion> attributeAssertions =
193+
codeFunctionAssertions(
194+
"io.opentelemetry.instrumentation.jaxrs.v2_0.test.JaxRsTestResource", "asyncOp");
195+
196+
if (testKind == AsyncResponseTestKind.CANCELED) {
197+
attributeAssertions.add(equalTo(AttributeKey.booleanKey("jaxrs.canceled"), true));
198+
}
199+
192200
testing()
193201
.waitAndAssertTraces(
194202
trace -> {
@@ -210,13 +218,7 @@ void shouldHandleAsyncResponse(AsyncResponseTestKind testKind) throws Exception
210218
span.hasName("JaxRsTestResource.asyncOp")
211219
.hasKind(SpanKind.INTERNAL)
212220
.hasParent(trace.getSpan(0))
213-
.hasAttributesSatisfyingExactly(
214-
satisfies(
215-
CODE_FUNCTION_NAME,
216-
name -> name.endsWith("JaxRsTestResource.asyncOp")),
217-
equalTo(
218-
AttributeKey.booleanKey("jaxrs.canceled"),
219-
testKind == AsyncResponseTestKind.CANCELED ? true : null));
221+
.hasAttributesSatisfyingExactly(attributeAssertions);
220222
if (testKind == AsyncResponseTestKind.FAILING) {
221223
span.hasStatus(StatusData.error())
222224
.hasException(new IllegalStateException("failure"));
@@ -299,9 +301,9 @@ void shouldHandleCompletionStage(CompletionStageTestKind testKind) throws Except
299301
.hasKind(SpanKind.INTERNAL)
300302
.hasParent(trace.getSpan(0))
301303
.hasAttributesSatisfyingExactly(
302-
equalTo(
303-
CODE_FUNCTION_NAME,
304-
"io.opentelemetry.instrumentation.jaxrs.v2_0.test.JaxRsTestResource.jaxRs21Async"));
304+
codeFunctionAssertions(
305+
"io.opentelemetry.instrumentation.jaxrs.v2_0.test.JaxRsTestResource",
306+
"jaxRs21Async"));
305307
if (testKind == CompletionStageTestKind.FAILING) {
306308
span.hasStatus(StatusData.error())
307309
.hasException(new IllegalStateException("failure"));
@@ -316,7 +318,7 @@ protected SpanDataAssert assertHandlerSpan(
316318
return span.hasName("JaxRsTestResource." + methodName)
317319
.hasKind(SpanKind.INTERNAL)
318320
.hasAttributesSatisfyingExactly(
319-
satisfies(
320-
CODE_FUNCTION_NAME, name -> name.endsWith("JaxRsTestResource." + methodName)));
321+
codeFunctionAssertions(
322+
"io.opentelemetry.instrumentation.jaxrs.v2_0.test.JaxRsTestResource", methodName));
321323
}
322324
}

instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/ContextBridgeTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.javaagent.instrumentation.opentelemetryapi;
77

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionAssertions;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011
import static org.assertj.core.api.Assertions.assertThat;
1112

@@ -19,7 +20,9 @@
1920
import io.opentelemetry.instrumentation.annotations.WithSpan;
2021
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2122
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
23+
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
2224
import io.opentelemetry.semconv.CodeAttributes;
25+
import java.util.List;
2326
import java.util.concurrent.CountDownLatch;
2427
import java.util.concurrent.Executors;
2528
import java.util.concurrent.atomic.AtomicReference;
@@ -81,7 +84,7 @@ public void run() {
8184
span ->
8285
span.hasName("test")
8386
.hasNoParent()
84-
.hasAttributesSatisfyingExactly(
87+
.hasAttributesSatisfyingExactly( // equal
8588
equalTo(
8689
CodeAttributes.CODE_FUNCTION_NAME,
8790
runnable.getClass().getName() + ".run"),
@@ -138,18 +141,15 @@ public void run() {
138141
// When
139142
runnable.run();
140143

144+
List<AttributeAssertion> assertions = codeFunctionAssertions(runnable.getClass(), "run");
145+
assertions.add(equalTo(stringKey("cat"), "yes"));
146+
141147
// Then
142148
testing.waitAndAssertTraces(
143149
trace ->
144150
trace.hasSpansSatisfyingExactly(
145151
span ->
146-
span.hasName("test")
147-
.hasNoParent()
148-
.hasAttributesSatisfyingExactly(
149-
equalTo(
150-
CodeAttributes.CODE_FUNCTION_NAME,
151-
runnable.getClass().getName() + ".run"),
152-
equalTo(stringKey("cat"), "yes"))));
152+
span.hasName("test").hasNoParent().hasAttributesSatisfyingExactly(assertions)));
153153
}
154154

155155
@Test

instrumentation/spring/spring-data/spring-data-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/AbstractSpringJpaTest.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.javaagent.instrumentation.spring.data;
77

88
import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
9+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionAssertions;
910
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
1011
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1112
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
@@ -26,10 +27,8 @@
2627
import io.opentelemetry.api.trace.SpanKind;
2728
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2829
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
29-
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
3030
import io.opentelemetry.sdk.testing.assertj.TraceAssert;
3131
import io.opentelemetry.sdk.trace.data.StatusData;
32-
import io.opentelemetry.semconv.CodeAttributes;
3332
import java.util.List;
3433
import java.util.Optional;
3534
import org.hibernate.Version;
@@ -83,7 +82,7 @@ static void assertHibernate4Trace(TraceAssert trace, String repoClassName) {
8382
span ->
8483
span.hasName("JpaCustomerRepository.save")
8584
.hasKind(SpanKind.INTERNAL)
86-
.hasAttributesSatisfyingExactly(assertCodeFunction(repoClassName, "save")),
85+
.hasAttributesSatisfyingExactly(codeFunctionAssertions(repoClassName, "save")),
8786
span ->
8887
span.hasName("INSERT test.JpaCustomer")
8988
.hasKind(SpanKind.CLIENT)
@@ -99,17 +98,13 @@ DB_CONNECTION_STRING, emitStableDatabaseSemconv() ? null : "hsqldb:mem:"),
9998
equalTo(maybeStable(DB_SQL_TABLE), "JpaCustomer")));
10099
}
101100

102-
private static AttributeAssertion assertCodeFunction(String repoClassName, String methodName) {
103-
return equalTo(CodeAttributes.CODE_FUNCTION_NAME, repoClassName + "." + methodName);
104-
}
105-
106101
@SuppressWarnings("deprecation") // TODO DB_CONNECTION_STRING deprecation
107102
static void assertHibernateTrace(TraceAssert trace, String repoClassName) {
108103
trace.hasSpansSatisfyingExactly(
109104
span ->
110105
span.hasName("JpaCustomerRepository.save")
111106
.hasKind(SpanKind.INTERNAL)
112-
.hasAttributesSatisfyingExactly(assertCodeFunction(repoClassName, "save")),
107+
.hasAttributesSatisfyingExactly(codeFunctionAssertions(repoClassName, "save")),
113108
span ->
114109
span.hasName("CALL test")
115110
.hasKind(SpanKind.CLIENT)
@@ -156,7 +151,7 @@ void testCrud() {
156151
span.hasName("JpaCustomerRepository.findAll")
157152
.hasKind(SpanKind.INTERNAL)
158153
.hasAttributesSatisfyingExactly(
159-
assertCodeFunction(repoClassName, "findAll")),
154+
codeFunctionAssertions(repoClassName, "findAll")),
160155
span ->
161156
span.hasName("SELECT test.JpaCustomer")
162157
.hasKind(SpanKind.CLIENT)
@@ -192,7 +187,8 @@ void testCrud() {
192187
span ->
193188
span.hasName("JpaCustomerRepository.save")
194189
.hasKind(SpanKind.INTERNAL)
195-
.hasAttributesSatisfyingExactly(assertCodeFunction(repoClassName, "save")),
190+
.hasAttributesSatisfyingExactly(
191+
codeFunctionAssertions(repoClassName, "save")),
196192
span ->
197193
span.hasName("SELECT test.JpaCustomer")
198194
.hasKind(SpanKind.CLIENT)
@@ -231,7 +227,7 @@ void testCrud() {
231227
span.hasName("JpaCustomerRepository.findByLastName")
232228
.hasKind(SpanKind.INTERNAL)
233229
.hasAttributesSatisfyingExactly(
234-
assertCodeFunction(repoClassName, "findByLastName")),
230+
codeFunctionAssertions(repoClassName, "findByLastName")),
235231
span ->
236232
span.hasName("SELECT test.JpaCustomer")
237233
.hasKind(SpanKind.CLIENT)
@@ -256,7 +252,7 @@ void testCrud() {
256252
span.hasName("JpaCustomerRepository.delete")
257253
.hasKind(SpanKind.INTERNAL)
258254
.hasAttributesSatisfyingExactly(
259-
assertCodeFunction(repoClassName, "delete")),
255+
codeFunctionAssertions(repoClassName, "delete")),
260256
span ->
261257
span.hasName("SELECT test.JpaCustomer")
262258
.hasKind(SpanKind.CLIENT)
@@ -303,7 +299,7 @@ void testCustomRepositoryMethod() {
303299
span.hasName("JpaCustomerRepository.findSpecialCustomers")
304300
.hasKind(SpanKind.INTERNAL)
305301
.hasAttributesSatisfyingExactly(
306-
assertCodeFunction(repoClassName, "findSpecialCustomers")),
302+
codeFunctionAssertions(repoClassName, "findSpecialCustomers")),
307303
span ->
308304
span.hasName("SELECT test.JpaCustomer")
309305
.hasKind(SpanKind.CLIENT)
@@ -349,7 +345,7 @@ void testFailedRepositoryMethod() {
349345
.hasStatus(StatusData.error())
350346
.hasException(expectedException)
351347
.hasAttributesSatisfyingExactly(
352-
assertCodeFunction(repoClassName, "findOneByLastName")),
348+
codeFunctionAssertions(repoClassName, "findOneByLastName")),
353349
span ->
354350
span.hasName("SELECT test.JpaCustomer")
355351
.hasKind(SpanKind.CLIENT)

instrumentation/spring/spring-scheduling-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/v3_1/SpringSchedulingTest.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.javaagent.instrumentation.spring.scheduling.v3_1;
77

8+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionAssertions;
89
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
@@ -27,7 +28,9 @@
2728
import io.opentelemetry.javaagent.instrumentation.spring.scheduling.v3_1.spring.config.TaskWithErrorConfig;
2829
import io.opentelemetry.javaagent.instrumentation.spring.scheduling.v3_1.spring.config.TriggerTaskConfig;
2930
import io.opentelemetry.javaagent.instrumentation.spring.scheduling.v3_1.spring.service.LambdaTaskConfigurer;
31+
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
3032
import io.opentelemetry.sdk.trace.data.StatusData;
33+
import java.util.List;
3134
import java.util.concurrent.CountDownLatch;
3235
import java.util.concurrent.TimeUnit;
3336
import org.junit.jupiter.api.Test;
@@ -58,16 +61,17 @@ void scheduleCronExpressionTest() throws InterruptedException {
5861
TriggerTask task = context.getBean(TriggerTask.class);
5962
task.blockUntilExecute();
6063

64+
List<AttributeAssertion> assertions = codeFunctionAssertions(TriggerTask.class, "run");
65+
assertions.add(equalTo(AttributeKey.stringKey("job.system"), "spring_scheduling"));
66+
6167
assertThat(task).isNotNull();
6268
testing.waitAndAssertTraces(
6369
trace ->
6470
trace.hasSpansSatisfyingExactly(
6571
span ->
6672
span.hasName("TriggerTask.run")
6773
.hasNoParent()
68-
.hasAttributesSatisfyingExactly(
69-
equalTo(AttributeKey.stringKey("job.system"), "spring_scheduling"),
70-
equalTo(CODE_FUNCTION_NAME, TriggerTask.class.getName() + ".run"))));
74+
.hasAttributesSatisfyingExactly(assertions)));
7175
}
7276
}
7377

@@ -78,16 +82,17 @@ void scheduleIntervalTest() throws InterruptedException {
7882
IntervalTask task = context.getBean(IntervalTask.class);
7983
task.blockUntilExecute();
8084

85+
List<AttributeAssertion> assertions = codeFunctionAssertions(IntervalTask.class, "run");
86+
assertions.add(equalTo(AttributeKey.stringKey("job.system"), "spring_scheduling"));
87+
8188
assertThat(task).isNotNull();
8289
testing.waitAndAssertTraces(
8390
trace ->
8491
trace.hasSpansSatisfyingExactly(
8592
span ->
8693
span.hasName("IntervalTask.run")
8794
.hasNoParent()
88-
.hasAttributesSatisfyingExactly(
89-
equalTo(AttributeKey.stringKey("job.system"), "spring_scheduling"),
90-
equalTo(CODE_FUNCTION_NAME, IntervalTask.class.getName() + ".run"))));
95+
.hasAttributesSatisfyingExactly(assertions)));
9196
}
9297
}
9398

@@ -124,18 +129,18 @@ void scheduleEnhancedClassTest() throws InterruptedException {
124129
CountDownLatch latch = context.getBean(CountDownLatch.class);
125130
latch.await(5, TimeUnit.SECONDS);
126131

132+
List<AttributeAssertion> assertions =
133+
codeFunctionAssertions(EnhancedClassTaskConfig.class, "run");
134+
assertions.add(equalTo(AttributeKey.stringKey("job.system"), "spring_scheduling"));
135+
127136
assertThat(latch).isNotNull();
128137
testing.waitAndAssertTraces(
129138
trace ->
130139
trace.hasSpansSatisfyingExactly(
131140
span ->
132141
span.hasName("EnhancedClassTaskConfig.run")
133142
.hasNoParent()
134-
.hasAttributesSatisfyingExactly(
135-
equalTo(AttributeKey.stringKey("job.system"), "spring_scheduling"),
136-
equalTo(
137-
CODE_FUNCTION_NAME,
138-
EnhancedClassTaskConfig.class.getName() + ".run"))));
143+
.hasAttributesSatisfyingExactly(assertions)));
139144
}
140145
}
141146

@@ -146,6 +151,9 @@ void taskWithErrorTest() throws InterruptedException {
146151
TaskWithError task = context.getBean(TaskWithError.class);
147152
task.blockUntilExecute();
148153

154+
List<AttributeAssertion> assertions = codeFunctionAssertions(TaskWithError.class, "run");
155+
assertions.add(equalTo(AttributeKey.stringKey("job.system"), "spring_scheduling"));
156+
149157
assertThat(task).isNotNull();
150158
testing.waitAndAssertTraces(
151159
trace ->
@@ -154,9 +162,7 @@ void taskWithErrorTest() throws InterruptedException {
154162
span.hasName("TaskWithError.run")
155163
.hasNoParent()
156164
.hasStatus(StatusData.error())
157-
.hasAttributesSatisfyingExactly(
158-
equalTo(AttributeKey.stringKey("job.system"), "spring_scheduling"),
159-
equalTo(CODE_FUNCTION_NAME, TaskWithError.class.getName() + ".run"))
165+
.hasAttributesSatisfyingExactly(assertions)
160166
.hasEventsSatisfyingExactly(
161167
event ->
162168
event

instrumentation/spring/spring-webmvc/spring-webmvc-6.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v6_0/boot/SpringBootBasedTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

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

8+
import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionAssertions;
89
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
11-
import static io.opentelemetry.semconv.CodeAttributes.CODE_FUNCTION_NAME;
1212
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE;
1313
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE;
1414
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE;
@@ -77,9 +77,7 @@ protected SpanDataAssert assertHandlerSpan(
7777
.hasKind(SpanKind.INTERNAL)
7878
.hasStatus(StatusData.error())
7979
.hasAttributesSatisfyingExactly(
80-
equalTo(
81-
CODE_FUNCTION_NAME,
82-
ResourceHttpRequestHandler.class.getName() + ".handleRequest"))
80+
codeFunctionAssertions(ResourceHttpRequestHandler.class, "handleRequest"))
8381
.hasEventsSatisfyingExactly(
8482
event ->
8583
event

0 commit comments

Comments
 (0)