Tweak Guava WithSpan test pattern.
MODIFY
instrumentation/guava-10.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/guava/GuavaWithSpanInstrumentationTest.java
instrumentation/guava-10.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/guava/GuavaWithSpanInstrumentationTest.java
package io.opentelemetry.javaagent.instrumentation.guava;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
+import com.google.common.util.concurrent.UncheckedExecutionException;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
@@ -24,15 +27,14 @@ class GuavaWithSpanInstrumentationTest {
@Test
void success() {
- SettableFuture<String> future = SettableFuture.create();
- new TracedWithSpan().listenableFuture(future);
+ SettableFuture<String> future = new TracedWithSpan().completable();
future.set("Value");
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
- span.hasName("TracedWithSpan.listenableFuture")
+ span.hasName("TracedWithSpan.completable")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttributes(Attributes.empty())));
@@ -41,15 +43,14 @@ class GuavaWithSpanInstrumentationTest {
@Test
void failure() {
IllegalArgumentException error = new IllegalArgumentException("Boom");
- SettableFuture<String> future = SettableFuture.create();
- new TracedWithSpan().listenableFuture(future);
+ SettableFuture<String> future = new TracedWithSpan().completable();
future.setException(error);
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
- span.hasName("TracedWithSpan.listenableFuture")
+ span.hasName("TracedWithSpan.completable")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasStatus(StatusData.error())
@@ -59,15 +60,14 @@ class GuavaWithSpanInstrumentationTest {
@Test
void canceled() {
- SettableFuture<String> future = SettableFuture.create();
- new TracedWithSpan().listenableFuture(future);
+ SettableFuture<String> future = new TracedWithSpan().completable();
future.cancel(true);
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
- span.hasName("TracedWithSpan.listenableFuture")
+ span.hasName("TracedWithSpan.completable")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttributes(attributeEntry("guava.canceled", true))));
@@ -75,13 +75,13 @@ class GuavaWithSpanInstrumentationTest {
@Test
void immediateSuccess() {
- new TracedWithSpan().listenableFuture(Futures.immediateFuture("Value"));
+ assertThat(Futures.getUnchecked(new TracedWithSpan().alreadySucceeded())).isEqualTo("Value");
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
- span.hasName("TracedWithSpan.listenableFuture")
+ span.hasName("TracedWithSpan.alreadySucceeded")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttributes(Attributes.empty())));
@@ -89,18 +89,19 @@ class GuavaWithSpanInstrumentationTest {
@Test
void immediateFailure() {
- IllegalArgumentException error = new IllegalArgumentException("Boom");
- new TracedWithSpan().listenableFuture(Futures.immediateFailedFuture(error));
+ assertThatThrownBy(() -> Futures.getUnchecked(new TracedWithSpan().alreadyFailed()))
+ .isInstanceOf(UncheckedExecutionException.class)
+ .hasCause(TracedWithSpan.FAILURE);
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
- span.hasName("TracedWithSpan.listenableFuture")
+ span.hasName("TracedWithSpan.alreadyFailed")
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasStatus(StatusData.error())
- .hasException(error)
+ .hasException(TracedWithSpan.FAILURE)
.hasAttributes(Attributes.empty())));
}
}

MODIFY
instrumentation/guava-10.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/guava/TracedWithSpan.java
instrumentation/guava-10.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/guava/TracedWithSpan.java
package io.opentelemetry.javaagent.instrumentation.guava;
+import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
import io.opentelemetry.extension.annotations.WithSpan;
final class TracedWithSpan {
+ static final IllegalArgumentException FAILURE = new IllegalArgumentException("Boom");
+
+ @WithSpan
+ SettableFuture<String> completable() {
+ return SettableFuture.create();
+ }
+
+ @WithSpan
+ ListenableFuture<String> alreadySucceeded() {
+ return Futures.immediateFuture("Value");
+ }
+
@WithSpan
- ListenableFuture<String> listenableFuture(ListenableFuture<String> future) {
- return future;
+ ListenableFuture<String> alreadyFailed() {
+ return Futures.immediateFailedFuture(FAILURE);
}
}

Tweak Guava WithSpan test pattern. (#5744)