Skip to content

Commit

Permalink
Test nested CLIENT span suppression in library instrumentations (#3970)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Aug 27, 2021
1 parent 79f4351 commit ab9c688
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ class ApacheClientHostAbsoluteUriRequestContextTest extends AbstractApacheClient
.build()
return builder.build()
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
boolean testWithClientParent() {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ class ApacheClientHostAbsoluteUriRequestTest extends AbstractApacheClientHostAbs
.build()
return builder.build()
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
boolean testWithClientParent() {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ class ApacheClientHostRequestContextTest extends AbstractApacheClientHostRequest
.build()
return builder.build()
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
boolean testWithClientParent() {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ class ApacheClientHostRequestTest extends AbstractApacheClientHostRequestTest im
.build()
return builder.build()
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
boolean testWithClientParent() {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ class ApacheClientUriRequestContextTest extends AbstractApacheClientUriRequestCo
.build()
return builder.build()
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
boolean testWithClientParent() {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ class ApacheClientUriRequestTest extends AbstractApacheClientUriRequestTest impl
.build()
return builder.build()
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
boolean testWithClientParent() {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ import org.eclipse.jetty.util.ssl.SslContextFactory

class JettyHttpClient9LibraryTest extends AbstractJettyClient9Test implements LibraryTestTrait {


@Override
boolean testWithClientParent() {
//The client parent test does not work well in the context of library only tests.
false
}

@Override
HttpClient createStandardClient() {
JettyClientTracingBuilder jettyClientTracingBuilder = new JettyClientTracingBuilder(getOpenTelemetry())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,4 @@ class OkHttp3Test extends AbstractOkHttp3Test implements LibraryTestTrait {
Call.Factory createCallFactory(OkHttpClient.Builder clientBuilder) {
return OkHttpTracing.create(getOpenTelemetry()).newCallFactory(clientBuilder.build())
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
boolean testWithClientParent() {
false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ class SpringWebInstrumentationTest extends HttpClientTest<HttpEntity<String>> im
false
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
boolean testWithClientParent() {
false
}

@Override
Set<AttributeKey<?>> httpAttributes(URI uri) {
def attributes = super.httpAttributes(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.extension.annotations.WithSpan;
import io.opentelemetry.instrumentation.test.utils.PortUtils;
import io.opentelemetry.instrumentation.testing.InstrumentationTestRunner;
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
Expand All @@ -29,7 +28,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -257,11 +255,13 @@ void successfulRequestWithNotSampledParent() throws Exception {

@ParameterizedTest
@ValueSource(strings = {"PUT", "POST"})
void shouldSuppressNestedClientSpanIfAlreadyUnderParentClientSpan(String method) {
void shouldSuppressNestedClientSpanIfAlreadyUnderParentClientSpan(String method)
throws Exception {
assumeTrue(options.testWithClientParent);

URI uri = resolveAddress("/success");
int responseCode = runUnderParentClientSpan(() -> doRequest(method, uri));
int responseCode =
testing.runWithClientSpan("parent-client-span", () -> doRequest(method, uri));

assertThat(responseCode).isEqualTo(200);

Expand Down Expand Up @@ -1137,15 +1137,4 @@ final void setTesting(InstrumentationTestRunner testing, HttpClientTestServer se
this.testing = testing;
this.server = server;
}

// Must create span within agent using annotation until
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1726
@WithSpan(value = "parent-client-span", kind = SpanKind.CLIENT)
private static <T> T runUnderParentClientSpan(Callable<T> r) {
try {
return r.call();
} catch (Throwable t) {
throw new AssertionError(t);
}
}
}

0 comments on commit ab9c688

Please sign in to comment.