Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Oct 30, 2023
1 parent 862e4fd commit e874cd9
Show file tree
Hide file tree
Showing 19 changed files with 3 additions and 108 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public final class AsyncHttpClientSingletons {
.addAttributesExtractor(
HttpClientPeerServiceAttributesExtractor.create(
httpAttributesGetter, CommonConfig.get().getPeerServiceResolver()))
.addAttributesExtractor(new AsyncHttpClientAdditionalAttributesExtractor())
.addOperationMetrics(HttpClientMetrics.get());
if (CommonConfig.get().shouldEmitExperimentalHttpClientMetrics()) {
builder.addOperationMetrics(HttpClientExperimentalMetrics.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" String
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" String
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
Expand Down Expand Up @@ -572,7 +571,6 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" String
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" String
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" String
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" String
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" "http://localhost:$sqsPort"
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
Expand Down Expand Up @@ -213,7 +212,6 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" "http://localhost:$sqsPort"
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -322,7 +321,6 @@ public void afterExecution(
executionAttributes.putAttribute(SDK_HTTP_REQUEST_ATTRIBUTE, context.httpRequest());

Span span = Span.fromContext(otelContext);
onUserAgentHeaderAvailable(span, executionAttributes);
onSdkResponse(span, context.response(), executionAttributes);

SdkHttpResponse httpResponse = context.httpResponse();
Expand All @@ -336,15 +334,6 @@ public void afterExecution(
clearAttributes(executionAttributes);
}

// Certain headers in the request like User-Agent are only available after execution.
private static void onUserAgentHeaderAvailable(Span span, ExecutionAttributes request) {
List<String> userAgent =
AwsSdkInstrumenterFactory.httpAttributesGetter.getHttpRequestHeader(request, "User-Agent");
if (!userAgent.isEmpty()) {
span.setAttribute(SemanticAttributes.USER_AGENT_ORIGINAL, userAgent.get(0));
}
}

private void onSdkResponse(
Span span, SdkResponse response, ExecutionAttributes executionAttributes) {
if (captureExperimentalSpanAttributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") }
"$SemanticAttributes.HTTP_METHOD" "$method"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.USER_AGENT_ORIGINAL" { it.startsWith("aws-sdk-java/") }
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
Expand Down Expand Up @@ -174,7 +173,6 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") }
"$SemanticAttributes.HTTP_METHOD" "$method"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.USER_AGENT_ORIGINAL" { it.startsWith("aws-sdk-java/") }
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
Expand Down Expand Up @@ -209,7 +207,6 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") }
"$SemanticAttributes.HTTP_METHOD" "$method"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.USER_AGENT_ORIGINAL" { it.startsWith("aws-sdk-java/") }
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
"$SemanticAttributes.HTTP_METHOD" "$method"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.USER_AGENT_ORIGINAL" { it.startsWith("aws-sdk-java/") }
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
Expand Down Expand Up @@ -204,7 +203,6 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
"$SemanticAttributes.HTTP_METHOD" "$method"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.USER_AGENT_ORIGINAL" { it.startsWith("aws-sdk-java/") }
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
Expand Down Expand Up @@ -333,7 +331,6 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
"$SemanticAttributes.RPC_SERVICE" "S3"
"$SemanticAttributes.RPC_METHOD" "GetObject"
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"aws.agent" "java-aws-sdk"
"aws.bucket.name" "somebucket"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" { it.startsWith("http://localhost:$sqsPort") }
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
Expand All @@ -151,7 +150,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" { it.startsWith("http://localhost:$sqsPort") }
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
Expand All @@ -174,7 +172,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" { it.startsWith("http://localhost:$sqsPort") }
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
Expand Down Expand Up @@ -210,7 +207,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" { it.startsWith("http://localhost:$sqsPort") }
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
Expand Down Expand Up @@ -321,7 +317,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" { it.startsWith("http://localhost:$sqsPort") }
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
Expand All @@ -345,7 +340,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"http.method" "POST"
"http.status_code" 200
"http.url" { it.startsWith("http://localhost:$sqsPort") }
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
Expand Down Expand Up @@ -376,7 +370,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"http.status_code" 200
"http.url" { it.startsWith("http://localhost:$sqsPort") }
"net.peer.name" "localhost"
"$SemanticAttributes.USER_AGENT_ORIGINAL" String
"net.peer.port" sqsPort
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ static SpanDataAssert sqs(
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isNull(), v -> assertThat(v).isInstanceOf(Long.class))),
satisfies(
SemanticAttributes.USER_AGENT_ORIGINAL,
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isNull(),
v -> assertThat(v).isInstanceOf(String.class))),
satisfies(SemanticAttributes.HTTP_URL, val -> val.isInstanceOf(String.class)),
satisfies(
stringKey("net.peer.name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import co.elastic.clients.elasticsearch.core.InfoResponse;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.Version;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanKind;
Expand Down Expand Up @@ -76,10 +75,6 @@ static void cleanUp() {
elasticsearch.stop();
}

private static String userAgent() {
return "elastic-java/" + Version.VERSION + " (Java/" + System.getProperty("java.version") + ")";
}

@Test
public void elasticsearchStatus() throws IOException {
InfoResponse response = client.info();
Expand Down Expand Up @@ -111,7 +106,6 @@ public void elasticsearchStatus() throws IOException {
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, userAgent()),
satisfies(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
AbstractLongAssert::isPositive))));
Expand Down Expand Up @@ -162,7 +156,6 @@ public void elasticsearchIndex() throws IOException {
SemanticAttributes.HTTP_URL,
httpHost.toURI() + "/test-index/_doc/test-id?timeout=10s"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 201L),
equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, userAgent()),
satisfies(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
AbstractLongAssert::isPositive))));
Expand Down Expand Up @@ -218,7 +211,6 @@ public void elasticsearchStatusAsync() throws Exception {
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, userAgent()),
satisfies(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
AbstractLongAssert::isPositive)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
"$SemanticAttributes.HTTP_URL" "${uri}"
"$SemanticAttributes.HTTP_METHOD" method
"$SemanticAttributes.HTTP_STATUS_CODE" statusCode
"$SemanticAttributes.USER_AGENT_ORIGINAL" { it == null || it instanceof String }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

package io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.semconv.SemanticAttributes;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
Expand All @@ -20,8 +18,6 @@
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;

/**
* JettyHttpClient9TracingInterceptor does three jobs stimulated from the Jetty Request object from
Expand Down Expand Up @@ -137,15 +133,7 @@ private void startSpan(Request request) {
}

@Override
public void onBegin(Request request) {
if (this.context != null) {
Span span = Span.fromContext(this.context);
HttpField agentField = request.getHeaders().getField(HttpHeader.USER_AGENT);
if (agentField != null) {
span.setAttribute(SemanticAttributes.USER_AGENT_ORIGINAL, agentField.getValue());
}
}
}
public void onBegin(Request request) {}

@Override
public void onComplete(Result result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ void synchronousCall() throws ApiException {
mockWebServer.httpUri()
+ "/api/v1/namespaces/namespace/pods/name/proxy?path=path"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, TEST_USER_AGENT),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
equalTo(SemanticAttributes.NET_PEER_NAME, "127.0.0.1"),
equalTo(SemanticAttributes.NET_PEER_PORT, mockWebServer.httpPort()),
Expand Down Expand Up @@ -135,7 +134,6 @@ void handleErrorsInSyncCall() {
mockWebServer.httpUri()
+ "/api/v1/namespaces/namespace/pods/name/proxy?path=path"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, TEST_USER_AGENT),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 451),
equalTo(SemanticAttributes.NET_PEER_NAME, "127.0.0.1"),
equalTo(SemanticAttributes.NET_PEER_PORT, mockWebServer.httpPort()),
Expand Down Expand Up @@ -192,7 +190,6 @@ public void onSuccess(
mockWebServer.httpUri()
+ "/api/v1/namespaces/namespace/pods/name/proxy?path=path"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, TEST_USER_AGENT),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
equalTo(SemanticAttributes.NET_PEER_NAME, "127.0.0.1"),
equalTo(SemanticAttributes.NET_PEER_PORT, mockWebServer.httpPort()),
Expand Down Expand Up @@ -257,7 +254,6 @@ public void onFailure(
mockWebServer.httpUri()
+ "/api/v1/namespaces/namespace/pods/name/proxy?path=path"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, TEST_USER_AGENT),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 451),
equalTo(SemanticAttributes.NET_PEER_NAME, "127.0.0.1"),
equalTo(SemanticAttributes.NET_PEER_PORT, mockWebServer.httpPort()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
// the tests are capturing the user-agent, but since it's not possible to override it in
// the builder, and since it contains the okhttp library version, let's just skip
// verification on this attribute
attributes.remove(SemanticAttributes.USER_AGENT_ORIGINAL);

if (SemconvStability.emitOldHttpSemconv()) {
// protocol is extracted from the response, and those URLs cause exceptions (= null
Expand Down
Loading

0 comments on commit e874cd9

Please sign in to comment.