Extract HTTP request & response content length from headers (#6415)

* Extract HTTP request & response content length from headers

* remove unused method

* fix camel tests

* fix google http client tests

* fix HttpUrlConnection tests

* fix k8s and jaxrs tests

* fix aws tests

* actually fix aws tests 🤞

* fix elasticsearch tests

* fix ratpack tests

* fix spring webflux tests

* fix vertx tests

* fix reactor netty tests
This commit is contained in:
Mateusz Rzeszutek 2022-08-05 19:55:47 +02:00 committed by GitHub
parent 6b1d415174
commit b2c90c79b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
81 changed files with 171 additions and 746 deletions

View File

@ -59,9 +59,7 @@ abstract class HttpCommonAttributesExtractor<
@Nullable Throwable error) {
internalSet(
attributes,
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
getter.requestContentLength(request, response));
attributes, SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, requestContentLength(request));
if (response != null) {
Integer statusCode = getter.statusCode(request, response);
@ -71,7 +69,7 @@ abstract class HttpCommonAttributesExtractor<
internalSet(
attributes,
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
getter.responseContentLength(request, response));
responseContentLength(request, response));
for (String name : capturedResponseHeaders) {
List<String> values = getter.responseHeader(request, response, name);
@ -87,8 +85,32 @@ abstract class HttpCommonAttributesExtractor<
return firstHeaderValue(getter.requestHeader(request, "user-agent"));
}
@Nullable
private Long requestContentLength(REQUEST request) {
return parseNumber(firstHeaderValue(getter.requestHeader(request, "content-length")));
}
@Nullable
private Long responseContentLength(REQUEST request, RESPONSE response) {
return parseNumber(
firstHeaderValue(getter.responseHeader(request, response, "content-length")));
}
@Nullable
static String firstHeaderValue(List<String> values) {
return values.isEmpty() ? null : values.get(0);
}
@Nullable
private static Long parseNumber(@Nullable String number) {
if (number == null) {
return null;
}
try {
return Long.parseLong(number);
} catch (NumberFormatException e) {
// not a number
return null;
}
}
}

View File

@ -34,9 +34,15 @@ public interface HttpCommonAttributesGetter<REQUEST, RESPONSE> {
*
* <p>This is called from {@link Instrumenter#end(Context, Object, Object, Throwable)}, whether
* {@code response} is {@code null} or not.
*
* @deprecated Request content length is now being calculated based on the request headers. This
* method is deprecated and will be removed in the next release.
*/
@Deprecated
@Nullable
Long requestContentLength(REQUEST request, @Nullable RESPONSE response);
default Long requestContentLength(REQUEST request, @Nullable RESPONSE response) {
throw new UnsupportedOperationException("This method is deprecated and will be removed");
}
/**
* Extracts the {@code http.request_content_length_uncompressed} span attribute.
@ -66,9 +72,15 @@ public interface HttpCommonAttributesGetter<REQUEST, RESPONSE> {
*
* <p>This is called from {@link Instrumenter#end(Context, Object, Object, Throwable)}, only when
* {@code response} is non-{@code null}.
*
* @deprecated Request content length is now being calculated based on the request headers. This
* method is deprecated and will be removed in the next release.
*/
@Deprecated
@Nullable
Long responseContentLength(REQUEST request, RESPONSE response);
default Long responseContentLength(REQUEST request, RESPONSE response) {
throw new UnsupportedOperationException("This method is deprecated and will be removed");
}
/**
* Extracts the {@code http.response_content_length_uncompressed} span attribute.

View File

@ -42,12 +42,6 @@ class HttpClientAttributesExtractorTest {
return value == null ? emptyList() : asList(value.split(","));
}
@Override
public Long requestContentLength(Map<String, String> request, Map<String, String> response) {
String value = request.get("requestContentLength");
return value == null ? null : Long.parseLong(value);
}
@Override
public Integer statusCode(Map<String, String> request, Map<String, String> response) {
return Integer.parseInt(response.get("statusCode"));
@ -58,12 +52,6 @@ class HttpClientAttributesExtractorTest {
return request.get("flavor");
}
@Override
public Long responseContentLength(Map<String, String> request, Map<String, String> response) {
String value = response.get("responseContentLength");
return value == null ? null : Long.parseLong(value);
}
@Override
public List<String> responseHeader(
Map<String, String> request, Map<String, String> response, String name) {
@ -77,14 +65,14 @@ class HttpClientAttributesExtractorTest {
Map<String, String> request = new HashMap<>();
request.put("method", "POST");
request.put("url", "http://github.com");
request.put("requestContentLength", "10");
request.put("header.content-length", "10");
request.put("flavor", "http/2");
request.put("header.user-agent", "okhttp 3.x");
request.put("header.custom-request-header", "123,456");
Map<String, String> response = new HashMap<>();
response.put("statusCode", "202");
response.put("responseContentLength", "20");
response.put("header.content-length", "20");
response.put("header.custom-response-header", "654,321");
HttpClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor =

View File

@ -58,12 +58,6 @@ class HttpServerAttributesExtractorTest {
return values == null ? emptyList() : asList(values.split(","));
}
@Override
public Long requestContentLength(Map<String, String> request, Map<String, String> response) {
String value = request.get("requestContentLength");
return value == null ? null : Long.parseLong(value);
}
@Override
public Integer statusCode(Map<String, String> request, Map<String, String> response) {
String value = response.get("statusCode");
@ -75,12 +69,6 @@ class HttpServerAttributesExtractorTest {
return request.get("flavor");
}
@Override
public Long responseContentLength(Map<String, String> request, Map<String, String> response) {
String value = response.get("responseContentLength");
return value == null ? null : Long.parseLong(value);
}
@Override
public List<String> responseHeader(
Map<String, String> request, Map<String, String> response, String name) {
@ -96,7 +84,7 @@ class HttpServerAttributesExtractorTest {
request.put("url", "http://github.com");
request.put("target", "/repositories/1");
request.put("scheme", "http");
request.put("requestContentLength", "10");
request.put("header.content-length", "10");
request.put("flavor", "http/2");
request.put("route", "/repositories/{id}");
request.put("serverName", "server");
@ -107,7 +95,7 @@ class HttpServerAttributesExtractorTest {
Map<String, String> response = new HashMap<>();
response.put("statusCode", "202");
response.put("responseContentLength", "20");
response.put("header.content-length", "20");
response.put("header.custom-response-header", "654,321");
Function<Context, String> routeFromContext = ctx -> "/repositories/{repoId}";
@ -147,11 +135,11 @@ class HttpServerAttributesExtractorTest {
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
entry(SemanticAttributes.HTTP_SERVER_NAME, "server"),
entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"),
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
entry(
AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
asList("123", "456")),
entry(SemanticAttributes.HTTP_SERVER_NAME, "server"),
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
entry(SemanticAttributes.HTTP_FLAVOR, "http/2"),
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L),

View File

@ -80,11 +80,6 @@ public class InstrumenterBenchmark {
return Collections.emptyList();
}
@Override
public Long requestContentLength(Void unused, @Nullable Void unused2) {
return 100L;
}
@Override
public String flavor(Void unused, @Nullable Void unused2) {
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
@ -95,11 +90,6 @@ public class InstrumenterBenchmark {
return 200;
}
@Override
public Long responseContentLength(Void unused, Void unused2) {
return 100L;
}
@Override
public List<String> responseHeader(Void unused, Void unused2, String name) {
return Collections.emptyList();

View File

@ -35,23 +35,11 @@ class AkkaHttpClientAttributesGetter
return AkkaHttpUtil.requestHeader(httpRequest, name);
}
@Override
@Nullable
public Long requestContentLength(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}
@Override
public Integer statusCode(HttpRequest httpRequest, HttpResponse httpResponse) {
return httpResponse.status().intValue();
}
@Override
@Nullable
public Long responseContentLength(HttpRequest httpRequest, HttpResponse httpResponse) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequest httpRequest, HttpResponse httpResponse, String name) {

View File

@ -26,23 +26,11 @@ class AkkaHttpServerAttributesGetter
return AkkaHttpUtil.requestHeader(request, name);
}
@Override
@Nullable
public Long requestContentLength(HttpRequest request, @Nullable HttpResponse httpResponse) {
return null;
}
@Override
public Integer statusCode(HttpRequest request, HttpResponse httpResponse) {
return httpResponse.status().intValue();
}
@Override
@Nullable
public Long responseContentLength(HttpRequest request, HttpResponse httpResponse) {
return null;
}
@Override
public List<String> responseHeader(HttpRequest request, HttpResponse httpResponse, String name) {
return AkkaHttpUtil.responseHeader(httpResponse, name);

View File

@ -34,7 +34,7 @@ class AwsSpan {
"http.url" String
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"net.peer.port" { it == null || it instanceof Number }
}
}
}
@ -60,9 +60,11 @@ class AwsSpan {
"http.method" "POST"
"http.status_code" 200
"http.url" String
"http.user_agent" { it == null || String }
"http.user_agent" { it == null || it instanceof String }
"http.request_content_length" { it == null || it instanceof Long }
"http.response_content_length" { it == null || it instanceof Long }
"net.peer.name" String
"net.peer.port" { it == null || Number }
"net.peer.port" { it == null || it instanceof Number }
"net.transport" IP_TCP
}
}
@ -88,7 +90,7 @@ class AwsSpan {
"http.status_code" 200
"http.url" String
"net.peer.name" String
"net.peer.port" { it == null || Number }
"net.peer.port" { it == null || it instanceof Number }
"net.transport" IP_TCP
}
}

View File

@ -31,13 +31,6 @@ final class ApacheHttpAsyncClientHttpAttributesGetter
return request.getHeader(name);
}
@Override
@Nullable
public Long requestContentLength(
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
@Override
@Nullable
public Integer statusCode(ApacheHttpClientRequest request, HttpResponse response) {
@ -51,12 +44,6 @@ final class ApacheHttpAsyncClientHttpAttributesGetter
return request.getFlavor();
}
@Override
@Nullable
public Long responseContentLength(ApacheHttpClientRequest request, HttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(
ApacheHttpClientRequest request, HttpResponse response, String name) {

View File

@ -37,12 +37,6 @@ final class ApacheHttpClientHttpAttributesGetter
return header == null ? emptyList() : singletonList(header.getValue());
}
@Override
@Nullable
public Long requestContentLength(HttpMethod request, @Nullable HttpMethod response) {
return null;
}
@Override
@Nullable
public Integer statusCode(HttpMethod request, HttpMethod response) {
@ -61,12 +55,6 @@ final class ApacheHttpClientHttpAttributesGetter
return null;
}
@Override
@Nullable
public Long responseContentLength(HttpMethod request, HttpMethod response) {
return null;
}
@Override
public List<String> responseHeader(HttpMethod request, HttpMethod response, String name) {
Header header = response.getResponseHeader(name);

View File

@ -30,13 +30,6 @@ final class ApacheHttpClientHttpAttributesGetter
return request.getHeader(name);
}
@Override
@Nullable
public Long requestContentLength(
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
@Override
public Integer statusCode(ApacheHttpClientRequest request, HttpResponse response) {
return response.getStatusLine().getStatusCode();
@ -48,12 +41,6 @@ final class ApacheHttpClientHttpAttributesGetter
return request.getFlavor();
}
@Override
@Nullable
public Long responseContentLength(ApacheHttpClientRequest request, HttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(
ApacheHttpClientRequest request, HttpResponse response, String name) {

View File

@ -32,13 +32,6 @@ enum ApacheHttpClientHttpAttributesGetter
return request.getHeader(name);
}
@Override
@Nullable
public Long requestContentLength(
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
@Override
public Integer statusCode(ApacheHttpClientRequest request, HttpResponse response) {
return response.getStatusLine().getStatusCode();
@ -50,12 +43,6 @@ enum ApacheHttpClientHttpAttributesGetter
return request.getFlavor();
}
@Override
@Nullable
public Long responseContentLength(ApacheHttpClientRequest request, HttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(
ApacheHttpClientRequest request, HttpResponse response, String name) {

View File

@ -68,12 +68,6 @@ final class ApacheHttpClientHttpAttributesGetter
return getHeader(request, name);
}
@Override
@Nullable
public Long requestContentLength(HttpRequest request, @Nullable HttpResponse response) {
return null;
}
@Override
public Integer statusCode(HttpRequest request, HttpResponse response) {
return response.getCode();
@ -105,12 +99,6 @@ final class ApacheHttpClientHttpAttributesGetter
return null;
}
@Override
@Nullable
public Long responseContentLength(HttpRequest request, HttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(HttpRequest request, HttpResponse response, String name) {
return getHeader(response, name);

View File

@ -34,15 +34,6 @@ enum ArmeriaHttpClientAttributesGetter
return request(ctx).headers().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(RequestContext ctx, @Nullable RequestLog requestLog) {
if (requestLog == null) {
return null;
}
return requestLog.requestLength();
}
@Override
@Nullable
public Integer statusCode(RequestContext ctx, RequestLog requestLog) {
@ -63,11 +54,6 @@ enum ArmeriaHttpClientAttributesGetter
}
}
@Override
public Long responseContentLength(RequestContext ctx, RequestLog requestLog) {
return requestLog.responseLength();
}
@Override
public List<String> responseHeader(RequestContext ctx, RequestLog requestLog, String name) {
return requestLog.responseHeaders().getAll(name);

View File

@ -41,15 +41,6 @@ enum ArmeriaHttpServerAttributesGetter
return request(ctx).headers().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(RequestContext ctx, @Nullable RequestLog requestLog) {
if (requestLog == null) {
return null;
}
return requestLog.requestLength();
}
@Override
@Nullable
public Integer statusCode(RequestContext ctx, RequestLog requestLog) {
@ -70,11 +61,6 @@ enum ArmeriaHttpServerAttributesGetter
}
}
@Override
public Long responseContentLength(RequestContext ctx, RequestLog requestLog) {
return requestLog.responseLength();
}
@Override
public List<String> responseHeader(RequestContext ctx, RequestLog requestLog, String name) {
return requestLog.responseHeaders().getAll(name);

View File

@ -14,14 +14,10 @@ import com.linecorp.armeria.common.HttpMethod;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.RequestHeaders;
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;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletionException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.BeforeEach;
@ -104,12 +100,6 @@ public abstract class AbstractArmeriaHttpClientTest extends AbstractHttpClientTe
// armeria requests can't be reused
options.disableTestReusedRequest();
options.enableTestReadTimeout();
Set<AttributeKey<?>> extra = new HashSet<>();
extra.add(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH);
extra.add(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH);
extra.addAll(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
options.setHttpAttributes(unused -> extra);
}
@Test

View File

@ -194,8 +194,6 @@ public abstract class AbstractArmeriaHttpServerTest extends AbstractHttpServerTe
options.setHttpAttributes(
endpoint -> {
Set<AttributeKey<?>> keys = new HashSet<>(HttpServerTestOptions.DEFAULT_HTTP_ATTRIBUTES);
keys.add(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH);
keys.add(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH);
keys.add(SemanticAttributes.HTTP_SERVER_NAME);
return keys;
});

View File

@ -31,12 +31,6 @@ final class AsyncHttpClientHttpAttributesGetter
return request.getHeaders().getOrDefault(name, Collections.emptyList());
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
return null;
}
@Override
public Integer statusCode(Request request, Response response) {
return response.getStatusCode();
@ -47,12 +41,6 @@ final class AsyncHttpClientHttpAttributesGetter
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
}
@Override
@Nullable
public Long responseContentLength(Request request, Response response) {
return null;
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
return response.getHeaders().getOrDefault(name, Collections.emptyList());

View File

@ -10,7 +10,6 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.List;
import javax.annotation.Nullable;
import org.asynchttpclient.Response;
import org.asynchttpclient.netty.request.NettyRequest;
final class AsyncHttpClientHttpAttributesGetter
implements HttpClientAttributesGetter<RequestContext, Response> {
@ -30,23 +29,6 @@ final class AsyncHttpClientHttpAttributesGetter
return requestContext.getRequest().getHeaders().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(RequestContext requestContext, @Nullable Response response) {
NettyRequest nettyRequest = requestContext.getNettyRequest();
if (nettyRequest != null) {
String contentLength = nettyRequest.getHttpRequest().headers().get("Content-Length");
if (contentLength != null) {
try {
return Long.valueOf(contentLength);
} catch (NumberFormatException ignored) {
// ignore
}
}
}
return null;
}
@Override
public Integer statusCode(RequestContext requestContext, Response response) {
return response.getStatusCode();
@ -57,20 +39,6 @@ final class AsyncHttpClientHttpAttributesGetter
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
}
@Override
@Nullable
public Long responseContentLength(RequestContext requestContext, Response response) {
String contentLength = response.getHeaders().get("Content-Length");
if (contentLength != null) {
try {
return Long.valueOf(contentLength);
} catch (NumberFormatException ignored) {
// ignore
}
}
return null;
}
@Override
public List<String> responseHeader(
RequestContext requestContext, Response response, String name) {

View File

@ -72,14 +72,6 @@ class AsyncHttpClientTest extends HttpClientTest<Request> implements AgentTestTr
SemanticAttributes.HTTP_SCHEME,
SemanticAttributes.HTTP_TARGET
]
switch (uri.toString()) {
case "http://localhost:61/": // unopened port
case "https://192.0.2.1/": // non routable address
break
default:
extra.add(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)
}
super.httpAttributes(uri) + extra
}
}

View File

@ -4,6 +4,7 @@
*/
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import spock.lang.Shared
import static io.opentelemetry.api.trace.SpanKind.CLIENT
@ -63,6 +64,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -86,6 +88,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -109,6 +112,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -132,6 +136,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -155,6 +160,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -177,6 +183,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -199,6 +206,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -220,6 +228,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -247,6 +256,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -269,6 +279,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -291,6 +302,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -313,6 +325,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -335,6 +348,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -387,6 +401,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -409,6 +424,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -431,6 +447,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -452,6 +469,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -473,6 +491,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -495,6 +514,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -516,6 +536,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -538,6 +559,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -561,6 +583,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -583,6 +606,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -609,6 +633,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -632,6 +657,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -654,6 +680,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -676,6 +703,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -698,6 +726,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -720,6 +749,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}

View File

@ -4,6 +4,7 @@
*/
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import spock.lang.Shared
import static io.opentelemetry.api.trace.SpanKind.CLIENT
@ -56,6 +57,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -79,6 +81,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -102,6 +105,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -124,6 +128,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -146,6 +151,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -167,6 +173,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(1) {
@ -188,6 +195,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -214,6 +222,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"net.peer.name" String
"net.transport" IP_TCP
"net.peer.port" { it == null || Number }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}

View File

@ -110,6 +110,7 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_METHOD" "$method"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
"$SemanticAttributes.RPC_SYSTEM" "aws-api"

View File

@ -39,23 +39,11 @@ class AwsSdkHttpAttributesGetter implements HttpClientAttributesGetter<Request<?
return value == null ? emptyList() : singletonList(value);
}
@Override
@Nullable
public Long requestContentLength(Request<?> request, @Nullable Response<?> response) {
return null;
}
@Override
public Integer statusCode(Request<?> request, Response<?> response) {
return response.getHttpResponse().getStatusCode();
}
@Override
@Nullable
public Long responseContentLength(Request<?> request, Response<?> response) {
return null;
}
@Override
public List<String> responseHeader(Request<?> request, Response<?> response, String name) {
String value = response.getHttpResponse().getHeaders().get(name);

View File

@ -108,6 +108,7 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_METHOD" "$method"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
"$SemanticAttributes.RPC_SYSTEM" "aws-api"

View File

@ -14,6 +14,7 @@ import com.amazonaws.services.sqs.model.ReceiveMessageRequest
import com.amazonaws.services.sqs.model.SendMessageRequest
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.elasticmq.rest.sqs.SQSRestServerBuilder
import spock.lang.Shared
@ -81,6 +82,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"net.transport" IP_TCP
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -103,6 +105,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"net.transport" IP_TCP
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(1) {
@ -124,6 +127,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"net.transport" IP_TCP
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -150,6 +154,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"net.transport" IP_TCP
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}

View File

@ -46,25 +46,11 @@ class AwsSdkHttpAttributesGetter
return value == null ? emptyList() : value;
}
@Override
@Nullable
public Long requestContentLength(
ExecutionAttributes request, @Nullable SdkHttpResponse response) {
return null;
}
@Override
public Integer statusCode(ExecutionAttributes request, SdkHttpResponse response) {
return response.statusCode();
}
@Override
@Nullable
public Long responseContentLength(
ExecutionAttributes request, @Nullable SdkHttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(
ExecutionAttributes request, SdkHttpResponse response, String name) {

View File

@ -169,6 +169,8 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_USER_AGENT" { it.startsWith("aws-sdk-java/") }
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$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"
"$SemanticAttributes.RPC_SERVICE" "DynamoDb"
"$SemanticAttributes.RPC_METHOD" "CreateTable"
@ -204,6 +206,8 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_METHOD" "$method"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_USER_AGENT" { 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.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
"$SemanticAttributes.RPC_SERVICE" "DynamoDb"
@ -240,6 +244,8 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_USER_AGENT" { it.startsWith("aws-sdk-java/") }
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$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"
"$SemanticAttributes.RPC_SERVICE" "$service"
"$SemanticAttributes.RPC_METHOD" "${operation}"
@ -353,6 +359,8 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_USER_AGENT" { 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"
"$SemanticAttributes.RPC_SERVICE" "$service"
"$SemanticAttributes.RPC_METHOD" "${operation}"
@ -443,6 +451,8 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_USER_AGENT" { 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"
"$SemanticAttributes.RPC_SERVICE" "$service"
"$SemanticAttributes.RPC_METHOD" "${operation}"

View File

@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.awssdk.v2_2
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.elasticmq.rest.sqs.SQSRestServerBuilder
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
@ -104,6 +105,8 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"net.transport" IP_TCP
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -127,6 +130,8 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"net.transport" IP_TCP
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -145,6 +150,8 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"net.transport" IP_TCP
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}
@ -172,6 +179,8 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
"net.peer.name" "localhost"
"net.peer.port" sqsPort
"net.transport" IP_TCP
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
}

View File

@ -96,6 +96,7 @@ class ElasticsearchRest5Test extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -170,6 +171,7 @@ class ElasticsearchRest5Test extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(3) {

View File

@ -90,6 +90,7 @@ class ElasticsearchRest6Test extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -163,6 +164,7 @@ class ElasticsearchRest6Test extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(3) {

View File

@ -89,6 +89,7 @@ class ElasticsearchRest7Test extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
}
@ -162,6 +163,7 @@ class ElasticsearchRest7Test extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(3) {

View File

@ -31,12 +31,6 @@ final class GoogleHttpClientHttpAttributesGetter
return httpRequest.getHeaders().getHeaderStringValues(name);
}
@Override
@Nullable
public Long requestContentLength(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return null;
}
@Override
public String flavor(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
@ -47,12 +41,6 @@ final class GoogleHttpClientHttpAttributesGetter
return httpResponse.getStatusCode();
}
@Override
@Nullable
public Long responseContentLength(HttpRequest httpRequest, HttpResponse httpResponse) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequest httpRequest, HttpResponse httpResponse, String name) {

View File

@ -98,7 +98,7 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
.hasAttributesSatisfying(
attrs ->
assertThat(attrs)
.hasSize(7)
.hasSize(8)
.containsEntry(
SemanticAttributes.NET_TRANSPORT,
SemanticAttributes.NetTransportValues.IP_TCP)
@ -109,6 +109,9 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
.containsEntry(SemanticAttributes.HTTP_URL, uri.toString())
.containsEntry(SemanticAttributes.HTTP_METHOD, "GET")
.containsEntry(SemanticAttributes.HTTP_STATUS_CODE, 500)
.hasEntrySatisfying(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
length -> assertThat(length).isPositive())
.containsEntry(
SemanticAttributes.HTTP_FLAVOR,
SemanticAttributes.HttpFlavorValues.HTTP_1_1)),

View File

@ -28,24 +28,11 @@ final class GrizzlyHttpAttributesGetter
return value == null ? emptyList() : singletonList(value);
}
@Nullable
@Override
public Long requestContentLength(
HttpRequestPacket request, @Nullable HttpResponsePacket response) {
return null;
}
@Override
public Integer statusCode(HttpRequestPacket request, HttpResponsePacket response) {
return response.getStatus();
}
@Nullable
@Override
public Long responseContentLength(HttpRequestPacket request, HttpResponsePacket response) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequestPacket request, HttpResponsePacket response, String name) {

View File

@ -33,12 +33,6 @@ class HttpUrlHttpAttributesGetter
return value == null ? emptyList() : singletonList(value);
}
@Override
@Nullable
public Long requestContentLength(HttpURLConnection connection, @Nullable Integer statusCode) {
return null;
}
@Override
public String flavor(HttpURLConnection connection, @Nullable Integer statusCode) {
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
@ -49,12 +43,6 @@ class HttpUrlHttpAttributesGetter
return statusCode;
}
@Override
@Nullable
public Long responseContentLength(HttpURLConnection connection, Integer statusCode) {
return null;
}
@Override
public List<String> responseHeader(
HttpURLConnection connection, Integer statusCode, String name) {

View File

@ -119,6 +119,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpURLConnection> implements
"$SemanticAttributes.HTTP_METHOD" "GET"
"$SemanticAttributes.HTTP_STATUS_CODE" STATUS
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(2) {
@ -140,6 +141,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpURLConnection> implements
"$SemanticAttributes.HTTP_METHOD" "GET"
"$SemanticAttributes.HTTP_STATUS_CODE" STATUS
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(4) {
@ -156,7 +158,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpURLConnection> implements
useCaches << [false, true]
}
def "test broken API usage"() {
def "test broken API usage (#iteration)"() {
setup:
def url = resolveAddress("/success").toURL()
HttpURLConnection connection = runWithSpan("someTrace") {
@ -188,6 +190,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpURLConnection> implements
"$SemanticAttributes.HTTP_METHOD" "GET"
"$SemanticAttributes.HTTP_STATUS_CODE" STATUS
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
serverSpan(it, 2, span(1))
@ -246,6 +249,8 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpURLConnection> implements
"$SemanticAttributes.HTTP_METHOD" "POST"
"$SemanticAttributes.HTTP_STATUS_CODE" STATUS
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" Long
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(2) {
@ -310,6 +315,8 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpURLConnection> implements
"$SemanticAttributes.HTTP_METHOD" "POST"
"$SemanticAttributes.HTTP_STATUS_CODE" STATUS
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" Long
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(2) {

View File

@ -30,13 +30,6 @@ class JdkHttpAttributesGetter implements HttpClientAttributesGetter<HttpRequest,
return httpRequest.headers().allValues(name);
}
@Override
@Nullable
public Long requestContentLength(
HttpRequest httpRequest, @Nullable HttpResponse<?> httpResponse) {
return null;
}
@Override
public Integer statusCode(HttpRequest httpRequest, HttpResponse<?> httpResponse) {
return httpResponse.statusCode();
@ -50,12 +43,6 @@ class JdkHttpAttributesGetter implements HttpClientAttributesGetter<HttpRequest,
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
}
@Override
@Nullable
public Long responseContentLength(HttpRequest httpRequest, HttpResponse<?> httpResponse) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequest httpRequest, HttpResponse<?> httpResponse, String name) {

View File

@ -42,13 +42,6 @@ final class JaxRsClientHttpAttributesGetter
return stringHeaders;
}
@Override
@Nullable
public Long requestContentLength(
ClientRequest httpRequest, @Nullable ClientResponse httpResponse) {
return null;
}
@Override
public String flavor(ClientRequest httpRequest, @Nullable ClientResponse httpResponse) {
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
@ -59,13 +52,6 @@ final class JaxRsClientHttpAttributesGetter
return httpResponse.getStatus();
}
@Override
@Nullable
public Long responseContentLength(ClientRequest httpRequest, ClientResponse httpResponse) {
int length = httpResponse.getLength();
return length != -1 ? (long) length : null;
}
@Override
public List<String> responseHeader(
ClientRequest httpRequest, ClientResponse httpResponse, String name) {

View File

@ -116,7 +116,8 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
"$SemanticAttributes.HTTP_METHOD" method
"$SemanticAttributes.HTTP_STATUS_CODE" statusCode
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" { it == null || String }
"$SemanticAttributes.HTTP_USER_AGENT" { it == null || it instanceof String }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
serverSpan(it, 1, span(0))

View File

@ -8,24 +8,17 @@ package io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HttpFlavorValues.HTTP_1_0;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HttpFlavorValues.HTTP_1_1;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HttpFlavorValues.HTTP_2_0;
import static java.util.logging.Level.FINE;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import java.util.List;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpVersion;
enum JettyClientHttpAttributesGetter implements HttpClientAttributesGetter<Request, Response> {
INSTANCE;
private static final Logger logger =
Logger.getLogger(JettyClientHttpAttributesGetter.class.getName());
@Override
@Nullable
public String method(Request request) {
@ -43,13 +36,6 @@ enum JettyClientHttpAttributesGetter implements HttpClientAttributesGetter<Reque
return request.getHeaders().getValuesList(name);
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
HttpField requestContentLengthField = request.getHeaders().getField(HttpHeader.CONTENT_LENGTH);
return getLongFromJettyHttpField(requestContentLengthField);
}
@Override
public String flavor(Request request, @Nullable Response response) {
@ -79,35 +65,8 @@ enum JettyClientHttpAttributesGetter implements HttpClientAttributesGetter<Reque
return response.getStatus();
}
@Override
@Nullable
public Long responseContentLength(Request request, Response response) {
Long respContentLength = null;
if (response != null) {
HttpField requestContentLengthField =
response.getHeaders().getField(HttpHeader.CONTENT_LENGTH);
respContentLength = getLongFromJettyHttpField(requestContentLengthField);
}
return respContentLength;
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
return response.getHeaders().getValuesList(name);
}
private static Long getLongFromJettyHttpField(HttpField httpField) {
Long longFromField = null;
try {
longFromField = httpField != null ? Long.getLong(httpField.getValue()) : null;
} catch (NumberFormatException t) {
if (logger.isLoggable(FINE)) {
logger.log(
FINE,
"Value {0} is not valid number format for header field: {1}",
new Object[] {httpField.getValue(), httpField.getName()});
}
}
return longFromField;
}
}

View File

@ -23,18 +23,10 @@ internal enum class KtorHttpServerAttributesGetter :
return request.headers.getAll(name) ?: emptyList()
}
override fun requestContentLength(request: ApplicationRequest, response: ApplicationResponse?): Long? {
return null
}
override fun statusCode(request: ApplicationRequest, response: ApplicationResponse): Int? {
return response.status()?.value
}
override fun responseContentLength(request: ApplicationRequest, response: ApplicationResponse): Long? {
return null
}
override fun responseHeader(request: ApplicationRequest, response: ApplicationResponse, name: String): List<String> {
return response.headers.allValues().getAll(name) ?: emptyList()
}

View File

@ -23,18 +23,10 @@ internal enum class KtorHttpServerAttributesGetter :
return request.headers.getAll(name) ?: emptyList()
}
override fun requestContentLength(request: ApplicationRequest, response: ApplicationResponse?): Long? {
return null
}
override fun statusCode(request: ApplicationRequest, response: ApplicationResponse): Int? {
return response.status()?.value
}
override fun responseContentLength(request: ApplicationRequest, response: ApplicationResponse): Long? {
return null
}
override fun responseHeader(request: ApplicationRequest, response: ApplicationResponse, name: String): List<String> {
return response.headers.allValues().getAll(name) ?: emptyList()
}

View File

@ -32,12 +32,6 @@ class KubernetesHttpAttributesGetter
return request.headers(name);
}
@Nullable
@Override
public Long requestContentLength(Request request, @Nullable ApiResponse<?> apiResponse) {
return null;
}
@Override
public String flavor(Request request, @Nullable ApiResponse<?> apiResponse) {
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
@ -48,12 +42,6 @@ class KubernetesHttpAttributesGetter
return apiResponse.getStatusCode();
}
@Nullable
@Override
public Long responseContentLength(Request request, ApiResponse<?> apiResponse) {
return null;
}
@Override
public List<String> responseHeader(Request request, ApiResponse<?> apiResponse, String name) {
return apiResponse.getHeaders().getOrDefault(name, emptyList());

View File

@ -202,6 +202,7 @@ class KubernetesClientTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
"kubernetes-client.namespace" "namespace"
"kubernetes-client.name" "name"
}

View File

@ -23,13 +23,6 @@ public class LibertyDispatcherHttpAttributesGetter
return libertyRequest.getHeaderValues(name);
}
@Override
@Nullable
public Long requestContentLength(
LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) {
return null;
}
@Override
@Nullable
public String flavor(LibertyRequest libertyRequest) {
@ -49,13 +42,6 @@ public class LibertyDispatcherHttpAttributesGetter
return libertyResponse.getStatus();
}
@Override
@Nullable
public Long responseContentLength(
LibertyRequest libertyRequest, LibertyResponse libertyResponse) {
return null;
}
@Override
public List<String> responseHeader(
LibertyRequest libertyRequest, LibertyResponse libertyResponse, String name) {

View File

@ -58,25 +58,11 @@ final class NettyHttpClientAttributesGetter
return requestAndChannel.request().headers().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
return null;
}
@Override
public Integer statusCode(HttpRequestAndChannel requestAndChannel, HttpResponse response) {
return response.getStatus().getCode();
}
@Override
@Nullable
public Long responseContentLength(
HttpRequestAndChannel requestAndChannel, HttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequestAndChannel requestAndChannel, HttpResponse response, String name) {

View File

@ -26,25 +26,11 @@ final class NettyHttpServerAttributesGetter
return requestAndChannel.request().headers().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
return null;
}
@Override
public Integer statusCode(HttpRequestAndChannel requestAndChannel, HttpResponse response) {
return response.getStatus().getCode();
}
@Override
@Nullable
public Long responseContentLength(
HttpRequestAndChannel requestAndChannel, HttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequestAndChannel requestAndChannel, HttpResponse response, String name) {

View File

@ -58,25 +58,11 @@ final class NettyHttpClientAttributesGetter
return requestAndChannel.request().headers().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
return null;
}
@Override
public Integer statusCode(HttpRequestAndChannel requestAndChannel, HttpResponse response) {
return response.getStatus().code();
}
@Override
@Nullable
public Long responseContentLength(
HttpRequestAndChannel requestAndChannel, HttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequestAndChannel requestAndChannel, HttpResponse response, String name) {

View File

@ -26,25 +26,11 @@ final class NettyHttpServerAttributesGetter
return requestAndChannel.request().headers().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
return null;
}
@Override
public Integer statusCode(HttpRequestAndChannel requestAndChannel, HttpResponse response) {
return response.getStatus().code();
}
@Override
@Nullable
public Long responseContentLength(
HttpRequestAndChannel requestAndChannel, HttpResponse response) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequestAndChannel requestAndChannel, HttpResponse response, String name) {

View File

@ -29,12 +29,6 @@ final class OkHttp2HttpAttributesGetter implements HttpClientAttributesGetter<Re
return request.headers(name);
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
return null;
}
@Override
public Integer statusCode(Request request, Response response) {
return response.code();
@ -59,11 +53,6 @@ final class OkHttp2HttpAttributesGetter implements HttpClientAttributesGetter<Re
return null;
}
@Override
public Long responseContentLength(Request request, Response response) {
return response.body().contentLength();
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
return response.headers(name);

View File

@ -30,12 +30,6 @@ enum OkHttpAttributesGetter implements HttpClientAttributesGetter<Request, Respo
return request.headers(name);
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
return null;
}
@Override
@SuppressWarnings("UnnecessaryDefaultInEnumSwitch")
@Nullable
@ -63,12 +57,6 @@ enum OkHttpAttributesGetter implements HttpClientAttributesGetter<Request, Respo
return response.code();
}
@Override
@Nullable
public Long responseContentLength(Request request, Response response) {
return null;
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
return response.headers(name);

View File

@ -27,24 +27,12 @@ enum MockHttpServerAttributesGetter implements HttpServerAttributesGetter<String
return emptyList();
}
@Nullable
@Override
public Long requestContentLength(String s, @Nullable Void unused) {
return null;
}
@Nullable
@Override
public Integer statusCode(String s, Void unused) {
return null;
}
@Nullable
@Override
public Long responseContentLength(String s, Void unused) {
return null;
}
@Override
public List<String> responseHeader(String s, Void unused, String name) {
return emptyList();

View File

@ -30,12 +30,6 @@ final class PlayWsClientHttpAttributesGetter
return request.getHeaders().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
return null;
}
@Override
public Integer statusCode(Request request, Response response) {
return response.getStatusCode();
@ -46,12 +40,6 @@ final class PlayWsClientHttpAttributesGetter
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
}
@Override
@Nullable
public Long responseContentLength(Request request, Response response) {
return null;
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
return response.getHeaders().getAll(name);

View File

@ -109,6 +109,7 @@ abstract class AbstractRatpackRoutesTest extends InstrumentationSpecification {
"$SemanticAttributes.HTTP_HOST" "localhost:${app.bindPort}"
"$SemanticAttributes.HTTP_TARGET" "/$path"
"$SemanticAttributes.HTTP_ROUTE" "/$route"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
if (hasHandlerSpan()) {

View File

@ -54,12 +54,6 @@ enum RatpackHttpAttributesGetter implements HttpServerAttributesGetter<Request,
return request.getHeaders().getAll(name);
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
return null;
}
@Override
@Nullable
public String flavor(Request request) {
@ -87,12 +81,6 @@ enum RatpackHttpAttributesGetter implements HttpServerAttributesGetter<Request,
return response.getStatus().getCode();
}
@Override
@Nullable
public Long responseContentLength(Request request, Response response) {
return null;
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
return response.getHeaders().getAll(name);

View File

@ -38,23 +38,11 @@ enum RatpackHttpClientAttributesGetter
return requestSpec.getHeaders().getAll(name);
}
@Nullable
@Override
public Long requestContentLength(RequestSpec requestSpec, @Nullable HttpResponse httpResponse) {
return null;
}
@Override
public Integer statusCode(RequestSpec requestSpec, HttpResponse httpResponse) {
return httpResponse.getStatusCode();
}
@Nullable
@Override
public Long responseContentLength(RequestSpec requestSpec, HttpResponse httpResponse) {
return null;
}
@Override
public List<String> responseHeader(
RequestSpec requestSpec, HttpResponse httpResponse, String name) {

View File

@ -74,24 +74,11 @@ final class ReactorNettyHttpClientAttributesGetter
return request.headers().getAll(name);
}
@Nullable
@Override
public Long requestContentLength(
HttpClientConfig request, @Nullable HttpClientResponse response) {
return null;
}
@Override
public Integer statusCode(HttpClientConfig request, HttpClientResponse response) {
return response.status().code();
}
@Nullable
@Override
public Long responseContentLength(HttpClientConfig request, HttpClientResponse response) {
return null;
}
@Override
public List<String> responseHeader(
HttpClientConfig request, HttpClientResponse response, String name) {

View File

@ -148,6 +148,7 @@ class ReactorNettyClientSslTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_URL" uri
"$SemanticAttributes.HTTP_FLAVOR" HTTP_1_1
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
"$SemanticAttributes.NET_PEER_NAME" "localhost"
"$SemanticAttributes.NET_PEER_PORT" server.httpsPort()
"$SemanticAttributes.NET_PEER_IP" "127.0.0.1"

View File

@ -71,6 +71,7 @@ class ReactorNettyConnectionSpanTest extends InstrumentationSpecification implem
"$SemanticAttributes.HTTP_URL" uri
"$SemanticAttributes.HTTP_FLAVOR" HTTP_1_1
"$SemanticAttributes.HTTP_STATUS_CODE" 200
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
"$SemanticAttributes.NET_PEER_NAME" "localhost"
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
"$SemanticAttributes.NET_PEER_IP" "127.0.0.1"

View File

@ -57,12 +57,6 @@ enum RestletHttpAttributesGetter implements HttpServerAttributesGetter<Request,
return parametersToList(headers.subList(name, /* ignoreCase = */ true));
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
return null;
}
@Override
@Nullable
public String flavor(Request request) {
@ -91,12 +85,6 @@ enum RestletHttpAttributesGetter implements HttpServerAttributesGetter<Request,
return response.getStatus().getCode();
}
@Override
@Nullable
public Long responseContentLength(Request request, Response response) {
return null;
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
Form headers = getHeaders(response);

View File

@ -59,12 +59,6 @@ public enum RestletHttpAttributesGetter implements HttpServerAttributesGetter<Re
return Arrays.asList(headers.getValuesArray(name, true));
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
return null;
}
@Override
@Nullable
public String flavor(Request request) {
@ -92,12 +86,6 @@ public enum RestletHttpAttributesGetter implements HttpServerAttributesGetter<Re
return response.getStatus().getCode();
}
@Override
@Nullable
public Long responseContentLength(Request request, Response response) {
return null;
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
Series<?> headers = getHeaders(response);

View File

@ -35,11 +35,6 @@ public class Servlet2Accessor extends JavaxServletAccessor<HttpServletResponse>
throw new UnsupportedOperationException();
}
@Override
public String getResponseHeader(HttpServletResponse httpServletResponse, String name) {
return null;
}
@Override
public List<String> getResponseHeaderValues(
HttpServletResponse httpServletResponse, String name) {

View File

@ -43,11 +43,6 @@ public class Servlet3Accessor extends JavaxServletAccessor<HttpServletResponse>
return response.getStatus();
}
@Override
public String getResponseHeader(HttpServletResponse response, String name) {
return response.getHeader(name);
}
@Override
public List<String> getResponseHeaderValues(HttpServletResponse response, String name) {
Collection<String> values = response.getHeaders(name);

View File

@ -35,16 +35,6 @@ public class Servlet5Accessor implements ServletAccessor<HttpServletRequest, Htt
return request.getScheme();
}
@Override
public String getRequestServerName(HttpServletRequest request) {
return request.getServerName();
}
@Override
public int getRequestServerPort(HttpServletRequest request) {
return request.getServerPort();
}
@Override
public String getRequestUri(HttpServletRequest request) {
return request.getRequestURI();
@ -123,11 +113,6 @@ public class Servlet5Accessor implements ServletAccessor<HttpServletRequest, Htt
return request.getRemotePort();
}
@Override
public int getRequestContentLength(HttpServletRequest request) {
return request.getContentLength();
}
@Override
public void addRequestAsyncListener(
HttpServletRequest request,
@ -145,11 +130,6 @@ public class Servlet5Accessor implements ServletAccessor<HttpServletRequest, Htt
return response.getStatus();
}
@Override
public String getResponseHeader(HttpServletResponse response, String name) {
return response.getHeader(name);
}
@Override
public List<String> getResponseHeaderValues(HttpServletResponse response, String name) {
Collection<String> values = response.getHeaders(name);

View File

@ -23,10 +23,6 @@ public interface ServletAccessor<REQUEST, RESPONSE> {
String getRequestScheme(REQUEST request);
String getRequestServerName(REQUEST request);
int getRequestServerPort(REQUEST request);
String getRequestUri(REQUEST request);
String getRequestQueryString(REQUEST request);
@ -57,15 +53,11 @@ public interface ServletAccessor<REQUEST, RESPONSE> {
Integer getRequestRemotePort(REQUEST request);
int getRequestContentLength(REQUEST request);
void addRequestAsyncListener(
REQUEST request, ServletAsyncListener<RESPONSE> listener, Object response);
int getResponseStatus(RESPONSE response);
String getResponseHeader(RESPONSE response, String name);
List<String> getResponseHeaderValues(RESPONSE response, String name);
boolean isResponseCommitted(RESPONSE response);

View File

@ -48,18 +48,6 @@ public class ServletHttpAttributesGetter<REQUEST, RESPONSE>
return accessor.getRequestHeaderValues(requestContext.request(), name);
}
@Override
@Nullable
public Long requestContentLength(
ServletRequestContext<REQUEST> requestContext,
@Nullable ServletResponseContext<RESPONSE> responseContext) {
int contentLength = accessor.getRequestContentLength(requestContext.request());
if (contentLength > -1) {
return (long) contentLength;
}
return null;
}
@Override
@Nullable
public String flavor(ServletRequestContext<REQUEST> requestContext) {
@ -91,22 +79,6 @@ public class ServletHttpAttributesGetter<REQUEST, RESPONSE>
return accessor.getResponseStatus(response);
}
@Override
@Nullable
public Long responseContentLength(
ServletRequestContext<REQUEST> requestContext,
ServletResponseContext<RESPONSE> responseContext) {
String contentLength = accessor.getResponseHeader(responseContext.response(), "Content-Length");
if (contentLength != null) {
try {
return Long.valueOf(contentLength);
} catch (NumberFormatException ignored) {
// ignore
}
}
return null;
}
@Override
public List<String> responseHeader(
ServletRequestContext<REQUEST> requestContext,

View File

@ -25,16 +25,6 @@ public abstract class JavaxServletAccessor<R> implements ServletAccessor<HttpSer
return request.getScheme();
}
@Override
public String getRequestServerName(HttpServletRequest request) {
return request.getServerName();
}
@Override
public int getRequestServerPort(HttpServletRequest request) {
return request.getServerPort();
}
@Override
public String getRequestUri(HttpServletRequest request) {
return request.getRequestURI();
@ -111,11 +101,6 @@ public abstract class JavaxServletAccessor<R> implements ServletAccessor<HttpSer
return request.getUserPrincipal();
}
@Override
public int getRequestContentLength(HttpServletRequest request) {
return request.getContentLength();
}
@Override
public boolean isServletException(Throwable throwable) {
return throwable instanceof ServletException;

View File

@ -35,13 +35,6 @@ enum SpringWebHttpAttributesGetter
return httpRequest.getHeaders().getOrDefault(name, emptyList());
}
@Override
@Nullable
public Long requestContentLength(
HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) {
return null;
}
@Override
@Nullable
public String flavor(HttpRequest httpRequest, @Nullable ClientHttpResponse clientHttpResponse) {
@ -57,13 +50,6 @@ enum SpringWebHttpAttributesGetter
}
}
@Override
@Nullable
public Long responseContentLength(
HttpRequest httpRequest, ClientHttpResponse clientHttpResponse) {
return null;
}
@Override
public List<String> responseHeader(
HttpRequest httpRequest, ClientHttpResponse clientHttpResponse, String name) {

View File

@ -92,6 +92,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" urlPathWithVariables
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -159,6 +161,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" urlPathWithVariables
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -246,6 +250,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" urlPathWithVariables
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -311,6 +317,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" "/**"
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -355,6 +363,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" "/echo"
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -404,6 +414,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" urlPathWithVariables
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -468,6 +480,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" "/double-greet-redirect"
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -500,6 +514,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" "/double-greet"
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {
@ -547,6 +563,8 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" urlPathWithVariables
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
}
}
span(1) {

View File

@ -55,12 +55,6 @@ enum SpringWebfluxHttpAttributesGetter
return request.headers().getOrDefault(name, emptyList());
}
@Nullable
@Override
public Long requestContentLength(ClientRequest request, @Nullable ClientResponse response) {
return null;
}
@Override
public Integer statusCode(ClientRequest request, ClientResponse response) {
if (RAW_STATUS_CODE != null) {
@ -76,12 +70,6 @@ enum SpringWebfluxHttpAttributesGetter
return response.statusCode().value();
}
@Nullable
@Override
public Long responseContentLength(ClientRequest request, ClientResponse response) {
return null;
}
@Override
public List<String> responseHeader(ClientRequest request, ClientResponse response, String name) {
return response.headers().header(name);

View File

@ -31,13 +31,6 @@ enum SpringWebMvcHttpAttributesGetter
return headers == null ? Collections.emptyList() : Collections.list(headers);
}
@Override
@Nullable
public Long requestContentLength(
HttpServletRequest request, @Nullable HttpServletResponse response) {
return null;
}
@Override
@Nullable
public String flavor(HttpServletRequest request) {
@ -51,12 +44,6 @@ enum SpringWebMvcHttpAttributesGetter
return null;
}
@Override
@Nullable
public Long responseContentLength(HttpServletRequest request, HttpServletResponse response) {
return null;
}
@Override
public List<String> responseHeader(
HttpServletRequest request, HttpServletResponse response, String name) {

View File

@ -43,13 +43,6 @@ public class TomcatHttpAttributesGetter implements HttpServerAttributesGetter<Re
return Collections.list(request.getMimeHeaders().values(name));
}
@Override
@Nullable
public Long requestContentLength(Request request, @Nullable Response response) {
long contentLength = request.getContentLengthLong();
return contentLength != -1 ? contentLength : null;
}
@Override
@Nullable
public String flavor(Request request) {
@ -69,13 +62,6 @@ public class TomcatHttpAttributesGetter implements HttpServerAttributesGetter<Re
return response.getStatus();
}
@Override
@Nullable
public Long responseContentLength(Request request, Response response) {
long contentLength = response.getContentLengthLong();
return contentLength != -1 ? contentLength : null;
}
@Override
public List<String> responseHeader(Request request, Response response, String name) {
return Collections.list(response.getMimeHeaders().values(name));

View File

@ -26,14 +26,6 @@ public class UndertowHttpAttributesGetter
return values == null ? Collections.emptyList() : values;
}
@Override
@Nullable
public Long requestContentLength(
HttpServerExchange exchange, @Nullable HttpServerExchange unused) {
long requestContentLength = exchange.getRequestContentLength();
return requestContentLength != -1 ? requestContentLength : null;
}
@Override
public String flavor(HttpServerExchange exchange) {
String flavor = exchange.getProtocol().toString();
@ -49,13 +41,6 @@ public class UndertowHttpAttributesGetter
return exchange.getStatusCode();
}
@Override
@Nullable
public Long responseContentLength(HttpServerExchange exchange, HttpServerExchange unused) {
long responseContentLength = exchange.getResponseContentLength();
return responseContentLength != -1 ? responseContentLength : null;
}
@Override
public List<String> responseHeader(
HttpServerExchange exchange, HttpServerExchange unused, String name) {

View File

@ -101,7 +101,6 @@ class UndertowServerDispatchTest extends HttpServerTest<Undertow> implements Age
Set<AttributeKey<?>> httpAttributes(ServerEndpoint endpoint) {
def attributes = super.httpAttributes(endpoint)
attributes.remove(SemanticAttributes.HTTP_ROUTE)
attributes.add(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)
attributes
}
}

View File

@ -110,7 +110,6 @@ class UndertowServerTest extends HttpServerTest<Undertow> implements AgentTestTr
Set<AttributeKey<?>> httpAttributes(ServerEndpoint endpoint) {
def attributes = super.httpAttributes(endpoint)
attributes.remove(SemanticAttributes.HTTP_ROUTE)
attributes.add(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)
attributes
}

View File

@ -25,24 +25,11 @@ public abstract class AbstractVertxHttpAttributesGetter
return request.headers().getAll(name);
}
@Nullable
@Override
public Long requestContentLength(
HttpClientRequest request, @Nullable HttpClientResponse response) {
return null;
}
@Override
public Integer statusCode(HttpClientRequest request, HttpClientResponse response) {
return response.statusCode();
}
@Nullable
@Override
public Long responseContentLength(HttpClientRequest request, HttpClientResponse response) {
return null;
}
@Override
public List<String> responseHeader(
HttpClientRequest request, HttpClientResponse response, String name) {

View File

@ -75,6 +75,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" "/listProducts"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(1) {
@ -166,6 +167,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" "/listProducts"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
"${TEST_REQUEST_ID_ATTRIBUTE}" requestId
}
}

View File

@ -75,6 +75,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" "/listProducts"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
}
}
span(1) {
@ -166,6 +167,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
"$SemanticAttributes.HTTP_USER_AGENT" String
"$SemanticAttributes.HTTP_ROUTE" "/listProducts"
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
"${TEST_REQUEST_ID_ATTRIBUTE}" requestId
}
}

View File

@ -978,13 +978,13 @@ public abstract class AbstractHttpClientTest<REQUEST> {
actual -> assertThat(actual).startsWith(userAgent));
}
}
if (httpClientAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) {
if (attrs.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) != null) {
assertThat(attrs)
.hasEntrySatisfying(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
length -> assertThat(length).isNotNegative());
}
if (httpClientAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) {
if (attrs.get(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH) != null) {
assertThat(attrs)
.hasEntrySatisfying(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,

View File

@ -560,8 +560,7 @@ public abstract class AbstractHttpServerTest<SERVER> {
.isInstanceOf(Long.class)
.isNotEqualTo(Long.valueOf(port)));
}
if (httpAttributes.contains(SemanticAttributes.NET_PEER_IP)
|| attrs.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) != null) {
if (httpAttributes.contains(SemanticAttributes.NET_PEER_IP)) {
assertThat(attrs)
.containsEntry(SemanticAttributes.NET_PEER_IP, options.peerIp.apply(endpoint));
}
@ -595,19 +594,17 @@ public abstract class AbstractHttpServerTest<SERVER> {
+ (endpoint == QUERY_PARAM ? "?" + endpoint.body : ""));
}
if (httpAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)
|| attrs.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) != null) {
if (attrs.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) != null) {
assertThat(attrs)
.hasEntrySatisfying(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
entry -> assertThat(entry).isInstanceOf(Long.class));
entry -> assertThat(entry).isNotNegative());
}
if (httpAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)
|| attrs.get(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH) != null) {
if (attrs.get(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH) != null) {
assertThat(attrs)
.hasEntrySatisfying(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
entry -> assertThat(entry).isInstanceOf(Long.class));
entry -> assertThat(entry).isNotNegative());
}
if (httpAttributes.contains(SemanticAttributes.HTTP_SERVER_NAME)) {
assertThat(attrs)
@ -615,10 +612,8 @@ public abstract class AbstractHttpServerTest<SERVER> {
SemanticAttributes.HTTP_SERVER_NAME,
entry -> assertThat(entry).isInstanceOf(String.class));
}
if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE)) {
if (expectedRoute != null) {
assertThat(attrs).containsEntry(SemanticAttributes.HTTP_ROUTE, expectedRoute);
}
if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE) && expectedRoute != null) {
assertThat(attrs).containsEntry(SemanticAttributes.HTTP_ROUTE, expectedRoute);
}
if (endpoint == CAPTURE_HEADERS) {