Skip to content

Commit

Permalink
Add HttpClientTestOptions (#3714)
Browse files Browse the repository at this point in the history
* Add HttpClientTestOptions

* Drift
  • Loading branch information
Anuraag Agrawal authored Aug 2, 2021
1 parent be645f0 commit 40aad45
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.linecorp.armeria.client.WebClientBuilder;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import org.junit.jupiter.api.extension.RegisterExtension;

class ArmeriaHttpClientTest extends AbstractArmeriaHttpClientTest {
Expand All @@ -21,21 +22,16 @@ protected WebClientBuilder configureClient(WebClientBuilder clientBuilder) {
ArmeriaTracing.create(testing.getOpenTelemetry()).newClientDecorator());
}

// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
@Override
protected boolean testWithClientParent() {
return false;
}
protected void configure(HttpClientTestOptions options) {
super.configure(options);

// Agent users have automatic propagation through executor instrumentation, but library users
// should do manually using Armeria patterns.
@Override
protected boolean testCallbackWithParent() {
return false;
}
// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet
options.disableTestWithClientParent();

@Override
protected boolean testErrorWithCallback() {
return false;
// Agent users have automatic propagation through executor instrumentation, but library users
// should do manually using Armeria patterns.
options.disableTestCallbackWithParent();
options.disableTestErrorWithCallback();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.linecorp.armeria.common.util.Exceptions;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.URI;
import java.util.HashSet;
Expand Down Expand Up @@ -70,27 +71,20 @@ protected final void sendRequestWithCallback(
requestResult.complete(() -> response.status().code(), throwable));
}

// Not supported yet: https://github.com/line/armeria/issues/2489
@Override
protected final boolean testRedirects() {
return false;
}

@Override
protected final boolean testReusedRequest() {
protected void configure(HttpClientTestOptions options) {
// Not supported yet: https://github.com/line/armeria/issues/2489
options.disableTestRedirects();
// armeria requests can't be reused
return false;
}
options.disableTestReusedRequest();

@Override
protected Set<AttributeKey<?>> httpAttributes(URI uri) {
Set<AttributeKey<?>> extra = new HashSet<>();
extra.add(SemanticAttributes.HTTP_HOST);
extra.add(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH);
extra.add(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH);
extra.add(SemanticAttributes.HTTP_SCHEME);
extra.add(SemanticAttributes.HTTP_TARGET);
extra.addAll(super.httpAttributes(uri));
return extra;
extra.addAll(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
options.setHttpAttributes(unused -> extra);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ abstract class HttpClientTest<REQUEST> extends InstrumentationSpecification {
def setupSpec() {
server = new HttpClientTestServer(openTelemetry)
server.start()
junitTest.setupOptions()
junitTest.setTesting(testRunner(), server)
}

Expand Down
Loading

0 comments on commit 40aad45

Please sign in to comment.