Update WithSpan tests to follow conventions (#13703)
This commit is contained in:
parent
1e7ddc8258
commit
7a974c97ee
|
@ -5,10 +5,11 @@
|
||||||
|
|
||||||
package io.opentelemetry.test.annotation;
|
package io.opentelemetry.test.annotation;
|
||||||
|
|
||||||
|
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.entry;
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||||
|
|
||||||
import io.opentelemetry.api.common.AttributeKey;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.trace.SpanId;
|
import io.opentelemetry.api.trace.SpanId;
|
||||||
import io.opentelemetry.api.trace.SpanKind;
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
|
@ -35,131 +36,88 @@ class WithSpanInstrumentationTest {
|
||||||
AgentInstrumentationExtension.create();
|
AgentInstrumentationExtension.create();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deriveAutomaticName() throws Exception {
|
void deriveAutomaticName() {
|
||||||
|
|
||||||
new TracedWithSpan().otel();
|
new TracedWithSpan().otel();
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.otel")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.otel")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "otel"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"otel")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void manualName() throws Exception {
|
void manualName() {
|
||||||
|
|
||||||
new TracedWithSpan().namedOtel();
|
new TracedWithSpan().namedOtel();
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("manualName")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("manualName")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "namedOtel"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"namedOtel")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void manualKind() throws Exception {
|
void manualKind() {
|
||||||
|
|
||||||
new TracedWithSpan().someKind();
|
new TracedWithSpan().someKind();
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.someKind")
|
||||||
span ->
|
.hasKind(SpanKind.PRODUCER)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.someKind")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.PRODUCER)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "someKind"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"someKind")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multipleSpans() throws Exception {
|
void multipleSpans() {
|
||||||
|
|
||||||
new TracedWithSpan().server();
|
new TracedWithSpan().server();
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.server")
|
||||||
span ->
|
.hasKind(SpanKind.SERVER)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.server")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.SERVER)
|
equalTo(
|
||||||
.hasNoParent()
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "server")),
|
||||||
assertThat(attributes)
|
span ->
|
||||||
.containsOnly(
|
span.hasName("TracedWithSpan.otel")
|
||||||
entry(
|
.hasKind(SpanKind.INTERNAL)
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
.hasParent(trace.getSpan(0))
|
||||||
TracedWithSpan.class.getName()),
|
.hasAttributesSatisfyingExactly(
|
||||||
entry(
|
equalTo(
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
"server"))),
|
TracedWithSpan.class.getName()),
|
||||||
span ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "otel"))));
|
||||||
assertThat(span)
|
|
||||||
.hasName("TracedWithSpan.otel")
|
|
||||||
.hasKind(SpanKind.INTERNAL)
|
|
||||||
.hasParent(trace.get(0))
|
|
||||||
.hasAttributesSatisfying(
|
|
||||||
attributes ->
|
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"otel")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void excludedMethod() throws Exception {
|
void excludedMethod() throws Exception {
|
||||||
|
|
||||||
new TracedWithSpan().ignored();
|
new TracedWithSpan().ignored();
|
||||||
|
|
||||||
Thread.sleep(500); // sleep a bit just to make sure no span is captured
|
Thread.sleep(500); // sleep a bit just to make sure no span is captured
|
||||||
|
@ -167,93 +125,67 @@ class WithSpanInstrumentationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void completedCompletionStage() throws Exception {
|
void completedCompletionStage() {
|
||||||
|
|
||||||
CompletableFuture<String> future = CompletableFuture.completedFuture("Done");
|
CompletableFuture<String> future = CompletableFuture.completedFuture("Done");
|
||||||
new TracedWithSpan().completionStage(future);
|
new TracedWithSpan().completionStage(future);
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completionStage")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completionStage")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completionStage"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completionStage")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void exceptionallyCompletedCompletionStage() throws Exception {
|
void exceptionallyCompletedCompletionStage() {
|
||||||
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
future.completeExceptionally(new IllegalArgumentException("Boom"));
|
Exception exception = new IllegalArgumentException("Boom");
|
||||||
|
future.completeExceptionally(exception);
|
||||||
new TracedWithSpan().completionStage(future);
|
new TracedWithSpan().completionStage(future);
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completionStage")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completionStage")
|
.hasStatus(StatusData.error())
|
||||||
.hasKind(SpanKind.INTERNAL)
|
.hasException(exception)
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasStatus(StatusData.error())
|
equalTo(
|
||||||
.hasAttributesSatisfying(
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
attributes ->
|
TracedWithSpan.class.getName()),
|
||||||
assertThat(attributes)
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completionStage"))));
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completionStage")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullCompletionStage() throws Exception {
|
void nullCompletionStage() {
|
||||||
|
|
||||||
new TracedWithSpan().completionStage(null);
|
new TracedWithSpan().completionStage(null);
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completionStage")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completionStage")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completionStage"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completionStage")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void completingCompletionStage() throws Exception {
|
void completingCompletionStage() throws Exception {
|
||||||
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
new TracedWithSpan().completionStage(future);
|
new TracedWithSpan().completionStage(future);
|
||||||
|
|
||||||
|
@ -262,150 +194,109 @@ class WithSpanInstrumentationTest {
|
||||||
|
|
||||||
future.complete("Done");
|
future.complete("Done");
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completionStage")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completionStage")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completionStage"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completionStage")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void exceptionallyCompletingCompletionStage() throws Exception {
|
void exceptionallyCompletingCompletionStage() throws Exception {
|
||||||
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
new TracedWithSpan().completionStage(future);
|
new TracedWithSpan().completionStage(future);
|
||||||
|
|
||||||
Thread.sleep(500); // sleep a bit just to make sure no span is captured
|
Thread.sleep(500); // sleep a bit just to make sure no span is captured
|
||||||
assertThat(testing.waitForTraces(0)).isEmpty();
|
assertThat(testing.waitForTraces(0)).isEmpty();
|
||||||
|
|
||||||
future.completeExceptionally(new IllegalArgumentException("Boom"));
|
Exception exception = new IllegalArgumentException("Boom");
|
||||||
|
future.completeExceptionally(exception);
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completionStage")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completionStage")
|
.hasStatus(StatusData.error())
|
||||||
.hasKind(SpanKind.INTERNAL)
|
.hasException(exception)
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasStatus(StatusData.error())
|
equalTo(
|
||||||
.hasAttributesSatisfying(
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
attributes ->
|
TracedWithSpan.class.getName()),
|
||||||
assertThat(attributes)
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completionStage"))));
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completionStage")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void completedCompletableFuture() throws Exception {
|
void completedCompletableFuture() {
|
||||||
|
|
||||||
CompletableFuture<String> future = CompletableFuture.completedFuture("Done");
|
CompletableFuture<String> future = CompletableFuture.completedFuture("Done");
|
||||||
new TracedWithSpan().completableFuture(future);
|
new TracedWithSpan().completableFuture(future);
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completableFuture")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completableFuture")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completableFuture"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completableFuture")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void exceptionallyCompletedCompletableFuture() throws Exception {
|
void exceptionallyCompletedCompletableFuture() {
|
||||||
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
future.completeExceptionally(new IllegalArgumentException("Boom"));
|
Exception exception = new IllegalArgumentException("Boom");
|
||||||
|
future.completeExceptionally(exception);
|
||||||
new TracedWithSpan().completableFuture(future);
|
new TracedWithSpan().completableFuture(future);
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completableFuture")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completableFuture")
|
.hasStatus(StatusData.error())
|
||||||
.hasKind(SpanKind.INTERNAL)
|
.hasException(exception)
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasStatus(StatusData.error())
|
equalTo(
|
||||||
.hasAttributesSatisfying(
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
attributes ->
|
TracedWithSpan.class.getName()),
|
||||||
assertThat(attributes)
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completableFuture"))));
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completableFuture")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullCompletableFuture() throws Exception {
|
void nullCompletableFuture() {
|
||||||
|
|
||||||
new TracedWithSpan().completableFuture(null);
|
new TracedWithSpan().completableFuture(null);
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completableFuture")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completableFuture")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completableFuture"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completableFuture")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void completingCompletableFuture() throws Exception {
|
void completingCompletableFuture() throws Exception {
|
||||||
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
new TracedWithSpan().completableFuture(future);
|
new TracedWithSpan().completableFuture(future);
|
||||||
|
|
||||||
|
@ -414,92 +305,65 @@ class WithSpanInstrumentationTest {
|
||||||
|
|
||||||
future.complete("Done");
|
future.complete("Done");
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completableFuture")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completableFuture")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completableFuture"))));
|
||||||
assertThat(attributes)
|
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completableFuture")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void exceptionallyCompletingCompletableFuture() throws Exception {
|
void exceptionallyCompletingCompletableFuture() throws Exception {
|
||||||
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
new TracedWithSpan().completableFuture(future);
|
new TracedWithSpan().completableFuture(future);
|
||||||
|
|
||||||
Thread.sleep(500); // sleep a bit just to make sure no span is captured
|
Thread.sleep(500); // sleep a bit just to make sure no span is captured
|
||||||
assertThat(testing.waitForTraces(0)).isEmpty();
|
assertThat(testing.waitForTraces(0)).isEmpty();
|
||||||
|
|
||||||
future.completeExceptionally(new IllegalArgumentException("Boom"));
|
Exception exception = new IllegalArgumentException("Boom");
|
||||||
|
future.completeExceptionally(exception);
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.completableFuture")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.completableFuture")
|
.hasStatus(StatusData.error())
|
||||||
.hasKind(SpanKind.INTERNAL)
|
.hasException(exception)
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasStatus(StatusData.error())
|
equalTo(
|
||||||
.hasAttributesSatisfying(
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
attributes ->
|
TracedWithSpan.class.getName()),
|
||||||
assertThat(attributes)
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "completableFuture"))));
|
||||||
.containsOnly(
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"completableFuture")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void captureAttributes() throws Exception {
|
void captureAttributes() {
|
||||||
|
|
||||||
new TracedWithSpan().withSpanAttributes("foo", "bar", null, "baz");
|
new TracedWithSpan().withSpanAttributes("foo", "bar", null, "baz");
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("TracedWithSpan.withSpanAttributes")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasNoParent()
|
||||||
.hasName("TracedWithSpan.withSpanAttributes")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE,
|
||||||
.hasAttributesSatisfying(
|
TracedWithSpan.class.getName()),
|
||||||
attributes ->
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "withSpanAttributes"),
|
||||||
assertThat(attributes)
|
equalTo(stringKey("implicitName"), "foo"),
|
||||||
.containsOnly(
|
equalTo(stringKey("explicitName"), "bar"))));
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
|
||||||
TracedWithSpan.class.getName()),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"withSpanAttributes"),
|
|
||||||
entry(
|
|
||||||
AttributeKey.stringKey("implicitName"), "foo"),
|
|
||||||
entry(
|
|
||||||
AttributeKey.stringKey("explicitName"),
|
|
||||||
"bar")))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Needs to be public for ByteBuddy
|
// Needs to be public for ByteBuddy
|
||||||
|
@ -541,32 +405,21 @@ class WithSpanInstrumentationTest {
|
||||||
Runnable runnable = (Runnable) generatedClass.getConstructor().newInstance();
|
Runnable runnable = (Runnable) generatedClass.getConstructor().newInstance();
|
||||||
runnable.run();
|
runnable.run();
|
||||||
|
|
||||||
assertThat(testing.waitForTraces(1))
|
testing.waitAndAssertTraces(
|
||||||
.satisfiesExactly(
|
trace ->
|
||||||
trace ->
|
trace.hasSpansSatisfyingExactly(
|
||||||
assertThat(trace)
|
span ->
|
||||||
.satisfiesExactly(
|
span.hasName("GeneratedJava6TestClass.run")
|
||||||
span ->
|
.hasKind(SpanKind.INTERNAL)
|
||||||
assertThat(span)
|
.hasParentSpanId(SpanId.getInvalid())
|
||||||
.hasName("GeneratedJava6TestClass.run")
|
.hasAttributesSatisfyingExactly(
|
||||||
.hasKind(SpanKind.INTERNAL)
|
equalTo(
|
||||||
.hasParentSpanId(SpanId.getInvalid())
|
CodeIncubatingAttributes.CODE_NAMESPACE, "GeneratedJava6TestClass"),
|
||||||
.hasAttributesSatisfying(
|
equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "run")),
|
||||||
attributes ->
|
span ->
|
||||||
assertThat(attributes)
|
span.hasName("intercept")
|
||||||
.containsOnly(
|
.hasKind(SpanKind.INTERNAL)
|
||||||
entry(
|
.hasParentSpanId(trace.getSpan(0).getSpanId())
|
||||||
CodeIncubatingAttributes.CODE_NAMESPACE,
|
.hasAttributes(Attributes.empty())));
|
||||||
"GeneratedJava6TestClass"),
|
|
||||||
entry(
|
|
||||||
CodeIncubatingAttributes.CODE_FUNCTION,
|
|
||||||
"run"))),
|
|
||||||
span ->
|
|
||||||
assertThat(span)
|
|
||||||
.hasName("intercept")
|
|
||||||
.hasKind(SpanKind.INTERNAL)
|
|
||||||
.hasParentSpanId(trace.get(0).getSpanId())
|
|
||||||
.hasAttributesSatisfying(
|
|
||||||
attributes -> assertThat(attributes).isEmpty())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue