Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test nested CLIENT span suppression in library instrumentations #3970

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}