Switch from http.flavor to net.protocol.* in HTTP client instrumentat… (#8131)
This commit is contained in:
parent
e79c46e190
commit
f501569106
|
@ -156,8 +156,6 @@ public final class HttpClientAttributesExtractor<REQUEST, RESPONSE>
|
|||
@Nullable Throwable error) {
|
||||
super.onEnd(attributes, context, request, response, error);
|
||||
|
||||
internalSet(attributes, SemanticAttributes.HTTP_FLAVOR, getter.getFlavor(request, response));
|
||||
|
||||
internalNetExtractor.onEnd(attributes, request, response);
|
||||
|
||||
int resendCount = resendCountIncrementer.applyAsInt(context);
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
|
|||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +32,13 @@ public interface HttpClientAttributesGetter<REQUEST, RESPONSE>
|
|||
*
|
||||
* <p>This is called from {@link Instrumenter#end(Context, Object, Object, Throwable)}, whether
|
||||
* {@code response} is {@code null} or not.
|
||||
*
|
||||
* @deprecated Use {@link NetClientAttributesGetter#getProtocolName(Object, Object)} and {@link
|
||||
* NetClientAttributesGetter#getProtocolVersion(Object, Object)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
String getFlavor(REQUEST request, @Nullable RESPONSE response);
|
||||
default String getFlavor(REQUEST request, @Nullable RESPONSE response) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
|
|||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -30,6 +31,8 @@ final class TemporaryMetricsView {
|
|||
view.add(SemanticAttributes.HTTP_METHOD);
|
||||
view.add(SemanticAttributes.HTTP_STATUS_CODE); // Optional
|
||||
view.add(SemanticAttributes.HTTP_FLAVOR); // Optional
|
||||
view.add(NetAttributes.NET_PROTOCOL_NAME); // Optional
|
||||
view.add(NetAttributes.NET_PROTOCOL_VERSION); // Optional
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.messaging;
|
|||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -31,39 +30,6 @@ public interface MessagingAttributesGetter<REQUEST, RESPONSE> {
|
|||
|
||||
boolean isTemporaryDestination(REQUEST request);
|
||||
|
||||
/**
|
||||
* Returns the application protocol used.
|
||||
*
|
||||
* @deprecated Use {@link NetClientAttributesGetter#getProtocolName(Object, Object)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
default String getProtocol(REQUEST request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of the application protocol used.
|
||||
*
|
||||
* @deprecated Use {@link NetClientAttributesGetter#getProtocolVersion(Object, Object)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
default String getProtocolVersion(REQUEST request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the application protocol used.
|
||||
*
|
||||
* @deprecated The {@code messaging.url} attribute was removed without replacement.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
default String getUrl(REQUEST request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String getConversationId(REQUEST request);
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ public interface NetClientAttributesGetter<REQUEST, RESPONSE> {
|
|||
@Nullable
|
||||
String getTransport(REQUEST request, @Nullable RESPONSE response);
|
||||
|
||||
// TODO: make required after the 1.24 release
|
||||
/**
|
||||
* Returns the application protocol used.
|
||||
*
|
||||
|
@ -31,7 +30,6 @@ public interface NetClientAttributesGetter<REQUEST, RESPONSE> {
|
|||
return null;
|
||||
}
|
||||
|
||||
// TODO: make required after the 1.24 release
|
||||
/**
|
||||
* Returns the version of the application protocol used.
|
||||
*
|
||||
|
|
|
@ -10,6 +10,7 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorU
|
|||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.Locale;
|
||||
import java.util.function.BiPredicate;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -49,13 +50,14 @@ public final class InternalNetClientAttributesExtractor<REQUEST, RESPONSE> {
|
|||
|
||||
internalSet(
|
||||
attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request, response));
|
||||
String protocolName = getter.getProtocolName(request, response);
|
||||
if (protocolName != null) {
|
||||
internalSet(
|
||||
attributes, NetAttributes.NET_PROTOCOL_NAME, protocolName.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
internalSet(
|
||||
attributes,
|
||||
SemanticAttributes.NET_APP_PROTOCOL_NAME,
|
||||
getter.getProtocolName(request, response));
|
||||
internalSet(
|
||||
attributes,
|
||||
SemanticAttributes.NET_APP_PROTOCOL_VERSION,
|
||||
NetAttributes.NET_PROTOCOL_VERSION,
|
||||
getter.getProtocolVersion(request, response));
|
||||
|
||||
String peerName = extractPeerName(request);
|
||||
|
|
|
@ -34,12 +34,8 @@ public final class InternalNetServerAttributesExtractor<REQUEST> {
|
|||
public void onStart(AttributesBuilder attributes, REQUEST request) {
|
||||
|
||||
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request));
|
||||
internalSet(
|
||||
attributes, SemanticAttributes.NET_APP_PROTOCOL_NAME, getter.getProtocolName(request));
|
||||
internalSet(
|
||||
attributes,
|
||||
SemanticAttributes.NET_APP_PROTOCOL_VERSION,
|
||||
getter.getProtocolVersion(request));
|
||||
internalSet(attributes, NetAttributes.NET_PROTOCOL_NAME, getter.getProtocolName(request));
|
||||
internalSet(attributes, NetAttributes.NET_PROTOCOL_VERSION, getter.getProtocolVersion(request));
|
||||
|
||||
boolean setSockFamily = false;
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.net.internal;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
|
||||
/**
|
||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||
* any time.
|
||||
*/
|
||||
public final class NetAttributes {
|
||||
|
||||
// FIXME: remove this class and replace its usages with SemanticAttributes once schema 1.20 is
|
||||
// released
|
||||
|
||||
public static final AttributeKey<String> NET_PROTOCOL_NAME = stringKey("net.protocol.name");
|
||||
|
||||
public static final AttributeKey<String> NET_PROTOCOL_VERSION = stringKey("net.protocol.version");
|
||||
|
||||
private NetAttributes() {}
|
||||
}
|
|
@ -19,6 +19,7 @@ import io.opentelemetry.api.common.AttributesBuilder;
|
|||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -60,11 +61,6 @@ class HttpClientAttributesExtractorTest {
|
|||
return Integer.parseInt(response.get("statusCode"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(Map<String, String> request, Map<String, String> response) {
|
||||
return request.get("flavor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(
|
||||
Map<String, String> request, Map<String, String> response, String name) {
|
||||
|
@ -83,6 +79,20 @@ class HttpClientAttributesExtractorTest {
|
|||
return response == null ? null : response.get("transport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPeerName(Map<String, String> request) {
|
||||
|
@ -103,9 +113,10 @@ class HttpClientAttributesExtractorTest {
|
|||
request.put("method", "POST");
|
||||
request.put("url", "http://github.com");
|
||||
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");
|
||||
request.put("protocolName", "http");
|
||||
request.put("protocolVersion", "1.1");
|
||||
request.put("peerName", "github.com");
|
||||
request.put("peerPort", "123");
|
||||
|
||||
|
@ -143,14 +154,15 @@ class HttpClientAttributesExtractorTest {
|
|||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
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),
|
||||
entry(SemanticAttributes.HTTP_RESEND_COUNT, 2L),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
||||
asList("654", "321")),
|
||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP));
|
||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
|
|
@ -14,6 +14,7 @@ import io.opentelemetry.api.common.Attributes;
|
|||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -113,8 +114,8 @@ class NetClientAttributesExtractorTest {
|
|||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
entry(SemanticAttributes.NET_APP_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_APP_PROTOCOL_VERSION, "1.1"),
|
||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"),
|
||||
|
|
|
@ -14,6 +14,7 @@ import io.opentelemetry.api.common.Attributes;
|
|||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -118,8 +119,8 @@ class NetServerAttributesExtractorTest {
|
|||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
entry(SemanticAttributes.NET_APP_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_APP_PROTOCOL_VERSION, "1.1"),
|
||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.NET_HOST_PORT, 80L),
|
||||
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
|
||||
|
|
|
@ -78,11 +78,6 @@ public class InstrumenterBenchmark {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(Void unused, @Nullable Void unused2) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatusCode(Void unused, Void unused2, @Nullable Throwable error) {
|
||||
return 200;
|
||||
|
@ -106,6 +101,18 @@ public class InstrumenterBenchmark {
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(Void unused, @Nullable Void unused2) {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(Void unused, @Nullable Void unused2) {
|
||||
return "2.0";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPeerName(Void request) {
|
||||
|
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.javaagent.instrumentation.akkahttp;
|
|||
|
||||
import akka.http.scaladsl.model.HttpRequest;
|
||||
import akka.http.scaladsl.model.HttpResponse;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -33,16 +32,12 @@ public class AkkaHttpUtil {
|
|||
.orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
public static String flavor(HttpRequest httpRequest) {
|
||||
switch (httpRequest.protocol().value()) {
|
||||
case "HTTP/1.0":
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
|
||||
case "HTTP/2.0":
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
case "HTTP/1.1":
|
||||
default:
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
public static String httpVersion(HttpRequest httpRequest) {
|
||||
String protocol = httpRequest.protocol().value();
|
||||
if (protocol.startsWith("HTTP/")) {
|
||||
protocol = protocol.substring("HTTP/".length());
|
||||
}
|
||||
return protocol;
|
||||
}
|
||||
|
||||
private AkkaHttpUtil() {}
|
||||
|
|
|
@ -20,11 +20,6 @@ class AkkaHttpClientAttributesGetter
|
|||
return httpRequest.uri().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
|
||||
return AkkaHttpUtil.flavor(httpRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod(HttpRequest httpRequest) {
|
||||
return httpRequest.method().value();
|
||||
|
|
|
@ -8,6 +8,7 @@ package io.opentelemetry.javaagent.instrumentation.akkahttp.client;
|
|||
import akka.http.scaladsl.model.HttpRequest;
|
||||
import akka.http.scaladsl.model.HttpResponse;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||
import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -18,6 +19,18 @@ class AkkaHttpNetAttributesGetter implements NetClientAttributesGetter<HttpReque
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
|
||||
return AkkaHttpUtil.httpVersion(httpRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPeerName(HttpRequest httpRequest) {
|
||||
return httpRequest.uri().authority().host().address();
|
||||
|
|
|
@ -40,7 +40,7 @@ class AkkaHttpServerAttributesGetter
|
|||
|
||||
@Override
|
||||
public String getFlavor(HttpRequest request) {
|
||||
return AkkaHttpUtil.flavor(request);
|
||||
return AkkaHttpUtil.httpVersion(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,12 +39,6 @@ final class ApacheHttpAsyncClientHttpAttributesGetter
|
|||
return statusLine != null ? statusLine.getStatusCode() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getFlavor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(
|
||||
ApacheHttpClientRequest request, HttpResponse response, String name) {
|
||||
|
|
|
@ -19,6 +19,17 @@ final class ApacheHttpAsyncClientNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getProtocolName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolVersion(
|
||||
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(ApacheHttpClientRequest request) {
|
||||
|
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient;
|
|||
|
||||
import static java.util.logging.Level.FINE;
|
||||
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
|
@ -70,25 +69,13 @@ public final class ApacheHttpClientRequest {
|
|||
return uri != null ? uri.toString() : null;
|
||||
}
|
||||
|
||||
public String getFlavor() {
|
||||
String getProtocolName() {
|
||||
return delegate.getProtocolVersion().getProtocol();
|
||||
}
|
||||
|
||||
String getProtocolVersion() {
|
||||
ProtocolVersion protocolVersion = delegate.getProtocolVersion();
|
||||
String protocol = protocolVersion.getProtocol();
|
||||
if (!protocol.equals("HTTP")) {
|
||||
return null;
|
||||
}
|
||||
int major = protocolVersion.getMajor();
|
||||
int minor = protocolVersion.getMinor();
|
||||
if (major == 1 && minor == 0) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
|
||||
}
|
||||
if (major == 1 && minor == 1) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
if (major == 2 && minor == 0) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
}
|
||||
logger.log(FINE, "unexpected http protocol version: {0}", protocolVersion);
|
||||
return null;
|
||||
return protocolVersion.getMajor() + "." + protocolVersion.getMinor();
|
||||
}
|
||||
|
||||
public String getPeerName() {
|
||||
|
|
|
@ -9,13 +9,11 @@ import static java.util.Collections.emptyList;
|
|||
import static java.util.Collections.singletonList;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.HostConfiguration;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.HttpMethodBase;
|
||||
import org.apache.commons.httpclient.StatusLine;
|
||||
|
||||
final class ApacheHttpClientHttpAttributesGetter
|
||||
|
@ -70,17 +68,6 @@ final class ApacheHttpClientHttpAttributesGetter
|
|||
return statusLine == null ? null : statusLine.getStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(HttpMethod request, @Nullable HttpMethod response) {
|
||||
if (request instanceof HttpMethodBase) {
|
||||
return ((HttpMethodBase) request).isHttp11()
|
||||
? SemanticAttributes.HttpFlavorValues.HTTP_1_1
|
||||
: SemanticAttributes.HttpFlavorValues.HTTP_1_0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(HttpMethod request, HttpMethod response, String name) {
|
||||
Header header = response.getResponseHeader(name);
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
|||
import javax.annotation.Nullable;
|
||||
import org.apache.commons.httpclient.HostConfiguration;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.HttpMethodBase;
|
||||
|
||||
final class ApacheHttpClientNetAttributesGetter
|
||||
implements NetClientAttributesGetter<HttpMethod, HttpMethod> {
|
||||
|
@ -19,6 +20,20 @@ final class ApacheHttpClientNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(HttpMethod request, @Nullable HttpMethod response) {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(HttpMethod request, @Nullable HttpMethod response) {
|
||||
if (request instanceof HttpMethodBase) {
|
||||
return ((HttpMethodBase) request).isHttp11() ? "1.1" : "1.0";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(HttpMethod request) {
|
||||
|
|
|
@ -36,12 +36,6 @@ final class ApacheHttpClientHttpAttributesGetter
|
|||
return response.getStatusLine().getStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getFlavor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(
|
||||
ApacheHttpClientRequest request, HttpResponse response, String name) {
|
||||
|
|
|
@ -18,6 +18,17 @@ final class ApacheHttpClientNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getProtocolName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolVersion(
|
||||
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(ApacheHttpClientRequest request) {
|
||||
|
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0;
|
|||
|
||||
import static java.util.logging.Level.FINE;
|
||||
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -72,25 +71,13 @@ public final class ApacheHttpClientRequest {
|
|||
return uri != null ? uri.toString() : null;
|
||||
}
|
||||
|
||||
public String getFlavor() {
|
||||
String getProtocolName() {
|
||||
return delegate.getProtocolVersion().getProtocol();
|
||||
}
|
||||
|
||||
String getProtocolVersion() {
|
||||
ProtocolVersion protocolVersion = delegate.getProtocolVersion();
|
||||
String protocol = protocolVersion.getProtocol();
|
||||
if (!protocol.equals("HTTP")) {
|
||||
return null;
|
||||
}
|
||||
int major = protocolVersion.getMajor();
|
||||
int minor = protocolVersion.getMinor();
|
||||
if (major == 1 && minor == 0) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
|
||||
}
|
||||
if (major == 1 && minor == 1) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
if (major == 2 && minor == 0) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
}
|
||||
logger.log(FINE, "unexpected http protocol version: {0}", protocolVersion);
|
||||
return null;
|
||||
return protocolVersion.getMajor() + "." + protocolVersion.getMinor();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -38,12 +38,6 @@ enum ApacheHttpClientHttpAttributesGetter
|
|||
return response.getStatusLine().getStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getFlavor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(
|
||||
ApacheHttpClientRequest request, HttpResponse response, String name) {
|
||||
|
|
|
@ -19,6 +19,17 @@ final class ApacheHttpClientNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getProtocolName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolVersion(
|
||||
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||
return request.getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(ApacheHttpClientRequest request) {
|
||||
|
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.instrumentation.apachehttpclient.v4_3;
|
|||
|
||||
import static java.util.logging.Level.FINE;
|
||||
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
|
@ -76,26 +75,13 @@ public final class ApacheHttpClientRequest {
|
|||
return uri != null ? uri.toString() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String getFlavor() {
|
||||
String getProtocolName() {
|
||||
return delegate.getProtocolVersion().getProtocol();
|
||||
}
|
||||
|
||||
String getProtocolVersion() {
|
||||
ProtocolVersion protocolVersion = delegate.getProtocolVersion();
|
||||
String protocol = protocolVersion.getProtocol();
|
||||
if (!protocol.equals("HTTP")) {
|
||||
return null;
|
||||
}
|
||||
int major = protocolVersion.getMajor();
|
||||
int minor = protocolVersion.getMinor();
|
||||
if (major == 1 && minor == 0) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
|
||||
}
|
||||
if (major == 1 && minor == 1) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
if (major == 2 && minor == 0) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
}
|
||||
logger.log(FINE, "unexpected http protocol version: {0}", protocolVersion);
|
||||
return null;
|
||||
return protocolVersion.getMajor() + "." + protocolVersion.getMinor();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -6,24 +6,18 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.MessageHeaders;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.net.URIAuthority;
|
||||
|
||||
final class ApacheHttpClientHttpAttributesGetter
|
||||
implements HttpClientAttributesGetter<HttpRequest, HttpResponse> {
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(ApacheHttpClientHttpAttributesGetter.class.getName());
|
||||
|
||||
@Override
|
||||
public String getMethod(HttpRequest request) {
|
||||
|
@ -74,45 +68,11 @@ final class ApacheHttpClientHttpAttributesGetter
|
|||
return response.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(HttpRequest request, @Nullable HttpResponse response) {
|
||||
ProtocolVersion protocolVersion = getVersion(request, response);
|
||||
if (protocolVersion == null) {
|
||||
return null;
|
||||
}
|
||||
String protocol = protocolVersion.getProtocol();
|
||||
if (!protocol.equals("HTTP")) {
|
||||
return null;
|
||||
}
|
||||
int major = protocolVersion.getMajor();
|
||||
int minor = protocolVersion.getMinor();
|
||||
if (major == 1 && minor == 0) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
|
||||
}
|
||||
if (major == 1 && minor == 1) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
if (major == 2 && minor == 0) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
}
|
||||
logger.log(Level.FINE, "unexpected http protocol version: {0}", protocolVersion);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(HttpRequest request, HttpResponse response, String name) {
|
||||
return getHeader(response, name);
|
||||
}
|
||||
|
||||
private static ProtocolVersion getVersion(HttpRequest request, @Nullable HttpResponse response) {
|
||||
ProtocolVersion protocolVersion = request.getVersion();
|
||||
if (protocolVersion == null && response != null) {
|
||||
protocolVersion = response.getVersion();
|
||||
}
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
private static List<String> getHeader(MessageHeaders messageHeaders, String name) {
|
||||
return headersToList(messageHeaders.getHeaders(name));
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
|||
import javax.annotation.Nullable;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
|
||||
final class ApacheHttpClientNetAttributesGetter
|
||||
implements NetClientAttributesGetter<HttpRequest, HttpResponse> {
|
||||
|
@ -19,6 +20,26 @@ final class ApacheHttpClientNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(HttpRequest request, @Nullable HttpResponse response) {
|
||||
ProtocolVersion protocolVersion = getVersion(request, response);
|
||||
if (protocolVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return protocolVersion.getProtocol();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse response) {
|
||||
ProtocolVersion protocolVersion = getVersion(request, response);
|
||||
if (protocolVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return protocolVersion.getMajor() + "." + protocolVersion.getMinor();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(HttpRequest request) {
|
||||
|
@ -29,4 +50,12 @@ final class ApacheHttpClientNetAttributesGetter
|
|||
public Integer getPeerPort(HttpRequest request) {
|
||||
return request.getAuthority().getPort();
|
||||
}
|
||||
|
||||
private static ProtocolVersion getVersion(HttpRequest request, @Nullable HttpResponse response) {
|
||||
ProtocolVersion protocolVersion = request.getVersion();
|
||||
if (protocolVersion == null && response != null) {
|
||||
protocolVersion = response.getVersion();
|
||||
}
|
||||
return protocolVersion;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.HashSet;
|
||||
|
@ -35,16 +36,17 @@ abstract class AbstractApacheHttpClientTest<T extends HttpRequest>
|
|||
optionsBuilder.setHttpAttributes(this::getHttpAttributes);
|
||||
}
|
||||
|
||||
protected Set<AttributeKey<?>> getHttpAttributes(URI endpoint) {
|
||||
Set<AttributeKey<?>> attributes = new HashSet<>();
|
||||
attributes.add(SemanticAttributes.NET_PEER_NAME);
|
||||
attributes.add(SemanticAttributes.NET_PEER_PORT);
|
||||
attributes.add(SemanticAttributes.HTTP_URL);
|
||||
attributes.add(SemanticAttributes.HTTP_METHOD);
|
||||
if (endpoint.toString().contains("/success")) {
|
||||
attributes.add(SemanticAttributes.HTTP_FLAVOR);
|
||||
protected Set<AttributeKey<?>> getHttpAttributes(URI uri) {
|
||||
Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
// unopened port or non routable address; or timeout
|
||||
// circular redirects don't report protocol information as well
|
||||
if ("http://localhost:61/".equals(uri.toString())
|
||||
|| "https://192.0.2.1/".equals(uri.toString())
|
||||
|| uri.toString().contains("/read-timeout")
|
||||
|| uri.toString().contains("/circular-redirect")) {
|
||||
attributes.remove(stringKey("net.protocol.name"));
|
||||
attributes.remove(stringKey("net.protocol.version"));
|
||||
}
|
||||
attributes.add(SemanticAttributes.HTTP_USER_AGENT);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,8 @@ package io.opentelemetry.instrumentation.armeria.v1_3;
|
|||
import com.linecorp.armeria.common.HttpRequest;
|
||||
import com.linecorp.armeria.common.HttpStatus;
|
||||
import com.linecorp.armeria.common.RequestContext;
|
||||
import com.linecorp.armeria.common.SessionProtocol;
|
||||
import com.linecorp.armeria.common.logging.RequestLog;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -45,16 +43,6 @@ enum ArmeriaHttpClientAttributesGetter
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(RequestContext ctx, @Nullable RequestLog requestLog) {
|
||||
SessionProtocol protocol = ctx.sessionProtocol();
|
||||
if (protocol.isMultiplex()) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
} else {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(RequestContext ctx, RequestLog requestLog, String name) {
|
||||
return requestLog.responseHeaders().getAll(name);
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.armeria.v1_3.internal;
|
|||
|
||||
import com.linecorp.armeria.common.HttpRequest;
|
||||
import com.linecorp.armeria.common.RequestContext;
|
||||
import com.linecorp.armeria.common.SessionProtocol;
|
||||
import com.linecorp.armeria.common.logging.RequestLog;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
|
@ -26,6 +27,17 @@ public final class ArmeriaNetClientAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) {
|
||||
SessionProtocol protocol = ctx.sessionProtocol();
|
||||
return protocol.isMultiplex() ? "2.0" : "1.1";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPeerName(RequestContext ctx) {
|
||||
|
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9;
|
|||
import com.ning.http.client.Request;
|
||||
import com.ning.http.client.Response;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -36,11 +35,6 @@ final class AsyncHttpClientHttpAttributesGetter
|
|||
return response.getStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(Request request, @Nullable Response response) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(Request request, Response response, String name) {
|
||||
return response.getHeaders().getOrDefault(name, Collections.emptyList());
|
||||
|
|
|
@ -19,6 +19,18 @@ final class AsyncHttpClientNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(Request request, @Nullable Response response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(Request request, @Nullable Response response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPeerName(Request request) {
|
||||
return request.getUri().getHost();
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.ning.http.client.Request
|
|||
import com.ning.http.client.RequestBuilder
|
||||
import com.ning.http.client.Response
|
||||
import com.ning.http.client.uri.Uri
|
||||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpClientTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult
|
||||
|
@ -17,6 +18,8 @@ import io.opentelemetry.instrumentation.testing.junit.http.SingleConnection
|
|||
import spock.lang.AutoCleanup
|
||||
import spock.lang.Shared
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey
|
||||
|
||||
class AsyncHttpClientTest extends HttpClientTest<Request> implements AgentTestTrait {
|
||||
|
||||
@AutoCleanup
|
||||
|
@ -69,4 +72,11 @@ class AsyncHttpClientTest extends HttpClientTest<Request> implements AgentTestTr
|
|||
// for a high concurrency test.
|
||||
return null
|
||||
}
|
||||
|
||||
Set<AttributeKey<?>> httpAttributes(URI uri) {
|
||||
def attributes = super.httpAttributes(uri)
|
||||
attributes.remove(stringKey("net.protocol.name"))
|
||||
attributes.remove(stringKey("net.protocol.version"))
|
||||
return attributes
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v2_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import org.asynchttpclient.Response;
|
||||
|
@ -35,11 +34,6 @@ final class AsyncHttpClientHttpAttributesGetter
|
|||
return response.getStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(RequestContext requestContext, @Nullable Response response) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(
|
||||
RequestContext requestContext, Response response, String name) {
|
||||
|
|
|
@ -5,11 +5,14 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v2_0;
|
||||
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.InetSocketAddress;
|
||||
import javax.annotation.Nullable;
|
||||
import org.asynchttpclient.Response;
|
||||
import org.asynchttpclient.netty.request.NettyRequest;
|
||||
|
||||
final class AsyncHttpClientNetAttributesGetter
|
||||
extends InetSocketAddressNetClientAttributesGetter<RequestContext, Response> {
|
||||
|
@ -21,13 +24,46 @@ final class AsyncHttpClientNetAttributesGetter
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPeerName(RequestContext requestContext) {
|
||||
return requestContext.getRequest().getUri().getHost();
|
||||
public String getProtocolName(RequestContext request, @Nullable Response response) {
|
||||
HttpVersion httpVersion = getHttpVersion(request);
|
||||
if (httpVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return httpVersion.protocolName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(RequestContext request, @Nullable Response response) {
|
||||
HttpVersion httpVersion = getHttpVersion(request);
|
||||
if (httpVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return httpVersion.majorVersion() + "." + httpVersion.minorVersion();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HttpVersion getHttpVersion(RequestContext request) {
|
||||
NettyRequest nettyRequest = request.getNettyRequest();
|
||||
if (nettyRequest == null) {
|
||||
return null;
|
||||
}
|
||||
HttpRequest httpRequest = nettyRequest.getHttpRequest();
|
||||
if (httpRequest == null) {
|
||||
return null;
|
||||
}
|
||||
return httpRequest.getProtocolVersion();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPeerName(RequestContext request) {
|
||||
return request.getRequest().getUri().getHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPeerPort(RequestContext requestContext) {
|
||||
return requestContext.getRequest().getUri().getPort();
|
||||
public Integer getPeerPort(RequestContext request) {
|
||||
return request.getRequest().getUri().getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,11 +3,9 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpClientTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.asynchttpclient.AsyncCompletionHandler
|
||||
import org.asynchttpclient.Dsl
|
||||
import org.asynchttpclient.Request
|
||||
|
@ -65,13 +63,4 @@ class AsyncHttpClientTest extends HttpClientTest<Request> implements AgentTestTr
|
|||
boolean testRedirects() {
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
Set<AttributeKey<?>> httpAttributes(URI uri) {
|
||||
Set<AttributeKey<?>> extra = [
|
||||
SemanticAttributes.HTTP_SCHEME,
|
||||
SemanticAttributes.HTTP_TARGET
|
||||
]
|
||||
super.httpAttributes(uri) + extra
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,12 +57,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.name" queueName
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -82,12 +83,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -107,12 +109,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -132,12 +135,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -157,12 +161,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -181,12 +186,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -205,12 +211,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -227,13 +234,14 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"http.user_agent" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -257,12 +265,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -281,12 +290,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "GET"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -305,12 +315,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "DELETE"
|
||||
"http.status_code" 204
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -329,12 +340,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "DELETE"
|
||||
"http.status_code" 204
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -353,12 +365,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -407,12 +420,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.name" queueName
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -431,12 +445,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -455,12 +470,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -478,12 +494,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "CreateTopic"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -501,12 +518,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "Subscribe"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -525,12 +543,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -548,12 +567,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "SetTopicAttributes"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -572,12 +592,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -597,12 +618,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -621,12 +643,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -649,12 +672,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -673,13 +697,14 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"http.user_agent" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -698,12 +723,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "GET"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -722,12 +748,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "DELETE"
|
||||
"http.status_code" 204
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -746,12 +773,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "DELETE"
|
||||
"http.status_code" 204
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
@ -770,12 +798,13 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
|
|
|
@ -50,12 +50,13 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.name" queueName
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
|
@ -74,12 +75,13 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
|
@ -98,12 +100,13 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
|
@ -121,12 +124,13 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "CreateTopic"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
|
@ -144,12 +148,13 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "Subscribe"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
|
@ -166,12 +171,13 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "Publish"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
|
@ -187,13 +193,14 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"rpc.method" "ReceiveMessage"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"http.user_agent" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
|
@ -215,12 +222,13 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"rpc.method" "ReceiveMessage"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
|
|
|
@ -100,7 +100,6 @@ class Aws1ClientTest extends AbstractAws1ClientTest implements AgentTestTrait {
|
|||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||
"$SemanticAttributes.HTTP_URL" "https://s3.amazonaws.com"
|
||||
"$SemanticAttributes.HTTP_METHOD" "HEAD"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "s3.amazonaws.com"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "Amazon S3"
|
||||
|
|
|
@ -109,8 +109,9 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.HTTP_URL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
|
@ -172,7 +173,6 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||
"$SemanticAttributes.HTTP_URL" "http://localhost:${UNUSABLE_PORT}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" 61
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
|
@ -221,7 +221,6 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||
"$SemanticAttributes.HTTP_URL" "https://s3.amazonaws.com"
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "s3.amazonaws.com"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "Amazon S3"
|
||||
|
@ -265,7 +264,6 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||
"$SemanticAttributes.HTTP_URL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
|
|
|
@ -11,7 +11,6 @@ import static java.util.Collections.singletonList;
|
|||
import com.amazonaws.Request;
|
||||
import com.amazonaws.Response;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -22,12 +21,6 @@ class AwsSdkHttpAttributesGetter implements HttpClientAttributesGetter<Request<?
|
|||
return request.getEndpoint().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(Request<?> request, @Nullable Response<?> response) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod(Request<?> request) {
|
||||
return request.getHttpMethod().name();
|
||||
|
|
|
@ -7,9 +7,12 @@ package io.opentelemetry.instrumentation.awssdk.v1_11;
|
|||
|
||||
import com.amazonaws.Request;
|
||||
import com.amazonaws.Response;
|
||||
import com.amazonaws.http.HttpResponse;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import javax.annotation.Nullable;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
|
||||
class AwsSdkNetAttributesGetter implements NetClientAttributesGetter<Request<?>, Response<?>> {
|
||||
|
||||
|
@ -18,6 +21,42 @@ class AwsSdkNetAttributesGetter implements NetClientAttributesGetter<Request<?>,
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(Request<?> request, @Nullable Response<?> response) {
|
||||
ProtocolVersion protocolVersion = getProtocolVersion(response);
|
||||
if (protocolVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return protocolVersion.getProtocol();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(Request<?> request, @Nullable Response<?> response) {
|
||||
ProtocolVersion protocolVersion = getProtocolVersion(response);
|
||||
if (protocolVersion == null) {
|
||||
return null;
|
||||
}
|
||||
return protocolVersion.getMajor() + "." + protocolVersion.getMinor();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ProtocolVersion getProtocolVersion(@Nullable Response<?> response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
HttpResponse httpResponse = response.getHttpResponse();
|
||||
if (httpResponse == null) {
|
||||
return null;
|
||||
}
|
||||
HttpRequestBase httpRequest = httpResponse.getHttpRequest();
|
||||
if (httpRequest == null) {
|
||||
return null;
|
||||
}
|
||||
return httpRequest.getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(Request<?> request) {
|
||||
|
|
|
@ -107,9 +107,10 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.HTTP_URL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
|
@ -186,7 +187,6 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||
"$SemanticAttributes.HTTP_URL" "http://127.0.0.1:${UNUSABLE_PORT}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" 61
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
|
@ -245,7 +245,6 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "Amazon S3"
|
||||
"$SemanticAttributes.RPC_METHOD" "GetObject"
|
||||
|
|
|
@ -75,13 +75,14 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"rpc.method" "CreateQueue"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
}
|
||||
|
@ -98,13 +99,14 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessage"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +121,6 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
|
@ -127,6 +128,8 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
}
|
||||
|
@ -147,13 +150,14 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"net.transport" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.instrumentation.awssdk.v2_2;
|
|||
import static java.util.Collections.emptyList;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
|
||||
|
@ -25,12 +24,6 @@ class AwsSdkHttpAttributesGetter
|
|||
return httpRequest.getUri().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(ExecutionAttributes request, @Nullable SdkHttpResponse response) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod(ExecutionAttributes request) {
|
||||
SdkHttpRequest httpRequest =
|
||||
|
|
|
@ -168,7 +168,6 @@ 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_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"
|
||||
|
@ -208,7 +207,6 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
|
|||
"$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"
|
||||
"$SemanticAttributes.RPC_METHOD" "Query"
|
||||
|
@ -243,7 +241,6 @@ 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_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"
|
||||
|
@ -356,7 +353,6 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") }
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$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 }
|
||||
|
@ -448,7 +444,6 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") }
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$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 }
|
||||
|
@ -550,7 +545,6 @@ abstract class AbstractAws2ClientTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_URL" "${server.httpUri()}${path}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "S3"
|
||||
"$SemanticAttributes.RPC_METHOD" "GetObject"
|
||||
|
|
|
@ -97,7 +97,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"rpc.method" "CreateQueue"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
|
@ -122,7 +121,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessage"
|
||||
"rpc.service" "Sqs"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
|
@ -143,7 +141,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.method" "ReceiveMessage"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
|
@ -171,7 +168,6 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
|
|
|
@ -28,10 +28,11 @@ class AwsSpan {
|
|||
"rpc.method" spanName.substring(3)
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.flavor" "1.1"
|
||||
"http.method" method
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.name" String
|
||||
"net.transport" IP_TCP
|
||||
"net.peer.port" { it == null || it instanceof Number }
|
||||
|
@ -56,13 +57,14 @@ class AwsSpan {
|
|||
"rpc.service" "AmazonSQS"
|
||||
"aws.queue.name" { it == null || it == queueName }
|
||||
"aws.queue.url" { it == null || it == queueUrl }
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" 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.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.name" String
|
||||
"net.peer.port" { it == null || it instanceof Number }
|
||||
"net.transport" IP_TCP
|
||||
|
@ -85,10 +87,11 @@ class AwsSpan {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" spanName.substring(4)
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.flavor" "1.1"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"net.peer.name" String
|
||||
"net.peer.port" { it == null || it instanceof Number }
|
||||
"net.transport" IP_TCP
|
||||
|
|
|
@ -91,7 +91,8 @@ class ElasticsearchRest5Test extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_NAME" httpHost.hostName
|
||||
"$SemanticAttributes.NET_PEER_PORT" httpHost.port
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
|
@ -164,7 +165,8 @@ class ElasticsearchRest5Test extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_NAME" httpHost.hostName
|
||||
"$SemanticAttributes.NET_PEER_PORT" httpHost.port
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
|
|
|
@ -85,7 +85,8 @@ class ElasticsearchRest6Test extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_NAME" httpHost.hostName
|
||||
"$SemanticAttributes.NET_PEER_PORT" httpHost.port
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
|
@ -157,7 +158,8 @@ class ElasticsearchRest6Test extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_NAME" httpHost.hostName
|
||||
"$SemanticAttributes.NET_PEER_PORT" httpHost.port
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
|
|
|
@ -84,7 +84,8 @@ class ElasticsearchRest7Test extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_NAME" httpHost.hostName
|
||||
"$SemanticAttributes.NET_PEER_PORT" httpHost.port
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
|
@ -156,7 +157,8 @@ class ElasticsearchRest7Test extends AgentInstrumentationSpecification {
|
|||
"$SemanticAttributes.NET_PEER_NAME" httpHost.hostName
|
||||
"$SemanticAttributes.NET_PEER_PORT" httpHost.port
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_FLAVOR" SemanticAttributes.HttpFlavorValues.HTTP_1_1
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.HTTP_URL" "${httpHost.toURI()}/_cluster/health"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
|
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.javaagent.instrumentation.googlehttpclient;
|
|||
import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpResponse;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -31,11 +30,6 @@ final class GoogleHttpClientHttpAttributesGetter
|
|||
return httpRequest.getHeaders().getHeaderStringValues(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatusCode(
|
||||
HttpRequest httpRequest, HttpResponse httpResponse, @Nullable Throwable error) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.googlehttpclient;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
|
||||
import com.google.api.client.http.GenericUrl;
|
||||
|
@ -13,6 +14,7 @@ import com.google.api.client.http.HttpRequestFactory;
|
|||
import com.google.api.client.http.HttpResponse;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.util.ClassInfo;
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
|
||||
|
@ -22,8 +24,10 @@ import io.opentelemetry.sdk.trace.data.StatusData;
|
|||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
@ -92,7 +96,7 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
|
|||
.hasAttributesSatisfying(
|
||||
attrs ->
|
||||
assertThat(attrs)
|
||||
.hasSize(8)
|
||||
.hasSize(7)
|
||||
.containsEntry(
|
||||
SemanticAttributes.NET_TRANSPORT,
|
||||
SemanticAttributes.NetTransportValues.IP_TCP)
|
||||
|
@ -105,10 +109,7 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
|
|||
.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)),
|
||||
length -> assertThat(length).isPositive())),
|
||||
span -> span.hasKind(SpanKind.SERVER).hasParent(trace.getSpan(0))));
|
||||
}
|
||||
|
||||
|
@ -124,5 +125,14 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
|
|||
|
||||
// Circular redirects don't throw an exception with Google Http Client
|
||||
optionsBuilder.disableTestCircularRedirects();
|
||||
|
||||
optionsBuilder.setHttpAttributes(
|
||||
uri -> {
|
||||
Set<AttributeKey<?>> attributes =
|
||||
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
attributes.remove(stringKey("net.protocol.name"));
|
||||
attributes.remove(stringKey("net.protocol.version"));
|
||||
return attributes;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import static java.util.Collections.emptyList;
|
|||
import static java.util.Collections.singletonList;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -33,11 +32,6 @@ class HttpUrlHttpAttributesGetter
|
|||
return value == null ? emptyList() : singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(HttpURLConnection connection, @Nullable Integer statusCode) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatusCode(
|
||||
HttpURLConnection connection, Integer statusCode, @Nullable Throwable error) {
|
||||
|
|
|
@ -18,6 +18,20 @@ class HttpUrlNetAttributesGetter implements NetClientAttributesGetter<HttpURLCon
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(HttpURLConnection connection, @Nullable Integer integer) {
|
||||
// HttpURLConnection hardcodes the protocol name&version
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(HttpURLConnection connection, @Nullable Integer integer) {
|
||||
// HttpURLConnection hardcodes the protocol name&version
|
||||
return "1.1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPeerName(HttpURLConnection connection) {
|
||||
return connection.getURL().getHost();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.httpurlconnection;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
|
||||
import static io.opentelemetry.api.trace.SpanKind.SERVER;
|
||||
import static io.opentelemetry.javaagent.instrumentation.httpurlconnection.StreamUtils.readLines;
|
||||
|
@ -136,12 +137,13 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_URL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, STATUS),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "1.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isNotNegative)),
|
||||
|
@ -153,12 +155,13 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_URL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, STATUS),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "1.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isNotNegative)),
|
||||
|
@ -191,12 +194,13 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_URL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, STATUS),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "1.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isNotNegative)),
|
||||
|
@ -242,12 +246,13 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_URL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, STATUS),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "1.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isNotNegative),
|
||||
|
@ -298,12 +303,13 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_URL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, STATUS),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "1.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isNotNegative),
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.httpurlconnection;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
|
@ -65,10 +66,11 @@ class UrlConnectionTest {
|
|||
.hasException(thrown)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, PortUtils.UNUSABLE_PORT),
|
||||
equalTo(SemanticAttributes.HTTP_URL, uri),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "1.1"))));
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
package io.opentelemetry.instrumentation.httpclient.internal;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.http.HttpClient.Version;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
|
@ -42,14 +40,6 @@ enum JavaHttpClientAttributesGetter
|
|||
return httpResponse.statusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(HttpRequest httpRequest, @Nullable HttpResponse<?> httpResponse) {
|
||||
if (httpResponse != null && httpResponse.version() == Version.HTTP_2) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
}
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(
|
||||
HttpRequest httpRequest, HttpResponse<?> httpResponse, String name) {
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.httpclient.internal;
|
|||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -19,19 +20,46 @@ public class JavaHttpClientNetAttributesGetter
|
|||
implements NetClientAttributesGetter<HttpRequest, HttpResponse<?>> {
|
||||
|
||||
@Override
|
||||
public String getTransport(HttpRequest httpRequest, @Nullable HttpResponse<?> response) {
|
||||
public String getTransport(HttpRequest request, @Nullable HttpResponse<?> response) {
|
||||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(HttpRequest httpRequest) {
|
||||
return httpRequest.uri().getHost();
|
||||
@Override
|
||||
public String getProtocolName(HttpRequest request, @Nullable HttpResponse<?> response) {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse<?> response) {
|
||||
HttpClient.Version version;
|
||||
if (response != null) {
|
||||
version = response.version();
|
||||
} else {
|
||||
version = request.version().orElse(null);
|
||||
}
|
||||
if (version == null) {
|
||||
return null;
|
||||
}
|
||||
switch (version) {
|
||||
case HTTP_1_1:
|
||||
return "1.1";
|
||||
case HTTP_2:
|
||||
return "2.0";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Integer getPeerPort(HttpRequest httpRequest) {
|
||||
return httpRequest.uri().getPort();
|
||||
public String getPeerName(HttpRequest request) {
|
||||
return request.uri().getHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Integer getPeerPort(HttpRequest request) {
|
||||
return request.uri().getPort();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.httpclient;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
|
||||
|
@ -13,7 +16,9 @@ import java.net.URI;
|
|||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
public abstract class AbstractJavaHttpClientTest extends AbstractHttpClientTest<HttpRequest> {
|
||||
|
@ -79,5 +84,19 @@ public abstract class AbstractJavaHttpClientTest extends AbstractHttpClientTest<
|
|||
// TODO nested client span is not created, but context is still injected
|
||||
// which is not what the test expects
|
||||
optionsBuilder.disableTestWithClientParent();
|
||||
|
||||
optionsBuilder.setHttpAttributes(
|
||||
uri -> {
|
||||
Set<AttributeKey<?>> attributes =
|
||||
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
// unopened port or non routable address; or timeout
|
||||
if ("http://localhost:61/".equals(uri.toString())
|
||||
|| "https://192.0.2.1/".equals(uri.toString())
|
||||
|| uri.toString().contains("/read-timeout")) {
|
||||
attributes.remove(stringKey("net.protocol.name"));
|
||||
attributes.remove(stringKey("net.protocol.version"));
|
||||
}
|
||||
return attributes;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import static java.util.Collections.emptyList;
|
|||
import com.sun.jersey.api.client.ClientRequest;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -42,11 +41,6 @@ final class JaxRsClientHttpAttributesGetter
|
|||
return stringHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(ClientRequest httpRequest, @Nullable ClientResponse httpResponse) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatusCode(
|
||||
ClientRequest httpRequest, ClientResponse httpResponse, @Nullable Throwable error) {
|
||||
|
|
|
@ -8,10 +8,13 @@ import com.sun.jersey.api.client.ClientResponse
|
|||
import com.sun.jersey.api.client.WebResource
|
||||
import com.sun.jersey.api.client.filter.GZIPContentEncodingFilter
|
||||
import com.sun.jersey.api.client.filter.LoggingFilter
|
||||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpClientTest
|
||||
import spock.lang.Shared
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey
|
||||
|
||||
class JaxRsClientV1Test extends HttpClientTest<WebResource.Builder> implements AgentTestTrait {
|
||||
|
||||
@Shared
|
||||
|
@ -46,4 +49,12 @@ class JaxRsClientV1Test extends HttpClientTest<WebResource.Builder> implements A
|
|||
boolean testCallback() {
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
Set<AttributeKey<?>> httpAttributes(URI uri) {
|
||||
def attributes = super.httpAttributes(uri)
|
||||
attributes.remove(stringKey("net.protocol.name"))
|
||||
attributes.remove(stringKey("net.protocol.version"))
|
||||
return attributes
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,13 +109,14 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
|
|||
status ERROR
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||
"net.protocol.name" "http"
|
||||
"net.protocol.version" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_NAME" uri.host
|
||||
"$SemanticAttributes.NET_PEER_PORT" uri.port > 0 ? uri.port : { it == null || it == 443 }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null }
|
||||
"$SemanticAttributes.HTTP_URL" "${uri}"
|
||||
"$SemanticAttributes.HTTP_METHOD" method
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" statusCode
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.HTTP_USER_AGENT" { it == null || it instanceof String }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
|
|
|
@ -5,16 +5,11 @@
|
|||
|
||||
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 io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
|
||||
enum JettyClientHttpAttributesGetter implements HttpClientAttributesGetter<Request, Response> {
|
||||
INSTANCE;
|
||||
|
@ -36,30 +31,6 @@ enum JettyClientHttpAttributesGetter implements HttpClientAttributesGetter<Reque
|
|||
return request.getHeaders().getValuesList(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(Request request, @Nullable Response response) {
|
||||
|
||||
if (response == null) {
|
||||
return HTTP_1_1;
|
||||
}
|
||||
HttpVersion httpVersion = response.getVersion();
|
||||
httpVersion = (httpVersion != null) ? httpVersion : HttpVersion.HTTP_1_1;
|
||||
switch (httpVersion) {
|
||||
case HTTP_0_9:
|
||||
case HTTP_1_0:
|
||||
return HTTP_1_0;
|
||||
case HTTP_1_1:
|
||||
return HTTP_1_1;
|
||||
default:
|
||||
// version 2.0 enum name difference in later versions 9.2 and 9.4 versions
|
||||
if (httpVersion.toString().endsWith("2.0")) {
|
||||
return HTTP_2_0;
|
||||
}
|
||||
|
||||
return HTTP_1_1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatusCode(Request request, Response response, @Nullable Throwable error) {
|
||||
return response.getStatus();
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
|||
import javax.annotation.Nullable;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
|
||||
/**
|
||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||
|
@ -23,6 +24,32 @@ public class JettyHttpClientNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(Request request, @Nullable Response response) {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(Request request, @Nullable Response response) {
|
||||
HttpVersion httpVersion = null;
|
||||
if (response != null) {
|
||||
httpVersion = response.getVersion();
|
||||
}
|
||||
if (httpVersion == null) {
|
||||
httpVersion = request.getVersion();
|
||||
}
|
||||
if (httpVersion == null) {
|
||||
return null;
|
||||
}
|
||||
String version = httpVersion.toString();
|
||||
if (version.startsWith("HTTP/")) {
|
||||
version = version.substring("HTTP/".length());
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(Request request) {
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.jetty.httpclient.v9_2
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpClientTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.eclipse.jetty.client.HttpClient
|
||||
import org.eclipse.jetty.client.api.ContentResponse
|
||||
import org.eclipse.jetty.client.api.Request
|
||||
|
@ -119,15 +118,6 @@ abstract class AbstractJettyClient9Test extends HttpClientTest<Request> {
|
|||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
Set<AttributeKey<?>> httpAttributes(URI uri) {
|
||||
Set<AttributeKey<?>> extra = [
|
||||
SemanticAttributes.HTTP_SCHEME,
|
||||
SemanticAttributes.HTTP_TARGET,
|
||||
]
|
||||
super.httpAttributes(uri) + extra
|
||||
}
|
||||
|
||||
@Unroll
|
||||
def "test content of #method request #url"() {
|
||||
when:
|
||||
|
|
|
@ -5,28 +5,14 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.joddhttp.v4_2;
|
||||
|
||||
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 io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HttpFlavorValues.HTTP_3_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
import jodd.http.HttpRequest;
|
||||
import jodd.http.HttpResponse;
|
||||
|
||||
final class JoddHttpHttpAttributesGetter
|
||||
implements HttpClientAttributesGetter<HttpRequest, HttpResponse> {
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(JoddHttpHttpAttributesGetter.class.getName());
|
||||
private static final Set<String> ALLOWED_HTTP_FLAVORS =
|
||||
new HashSet<>(Arrays.asList(HTTP_1_0, HTTP_1_1, HTTP_2_0, HTTP_3_0));
|
||||
|
||||
@Override
|
||||
public String getMethod(HttpRequest request) {
|
||||
|
@ -49,26 +35,6 @@ final class JoddHttpHttpAttributesGetter
|
|||
return response.statusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(HttpRequest request, @Nullable HttpResponse response) {
|
||||
String httpVersion = request.httpVersion();
|
||||
if (httpVersion == null && response != null) {
|
||||
httpVersion = response.httpVersion();
|
||||
}
|
||||
if (httpVersion != null) {
|
||||
if (httpVersion.contains("/")) {
|
||||
httpVersion = httpVersion.substring(httpVersion.lastIndexOf("/") + 1);
|
||||
}
|
||||
|
||||
if (ALLOWED_HTTP_FLAVORS.contains(httpVersion)) {
|
||||
return httpVersion;
|
||||
}
|
||||
}
|
||||
logger.log(Level.FINE, "unexpected http protocol version: {0}", httpVersion);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(HttpRequest request, HttpResponse response, String name) {
|
||||
return response.headers(name);
|
||||
|
|
|
@ -19,6 +19,26 @@ final class JoddHttpNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(HttpRequest request, @Nullable HttpResponse response) {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse response) {
|
||||
String httpVersion = request.httpVersion();
|
||||
if (httpVersion == null && response != null) {
|
||||
httpVersion = response.httpVersion();
|
||||
}
|
||||
if (httpVersion != null) {
|
||||
if (httpVersion.contains("/")) {
|
||||
httpVersion = httpVersion.substring(httpVersion.lastIndexOf("/") + 1);
|
||||
}
|
||||
}
|
||||
return httpVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(HttpRequest request) {
|
||||
|
|
|
@ -10,12 +10,9 @@ import static jodd.http.HttpStatus.HTTP_INTERNAL_ERROR;
|
|||
import static jodd.http.HttpStatus.HTTP_NOT_FOUND;
|
||||
import static jodd.http.HttpStatus.HTTP_OK;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HttpFlavorValues;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import jodd.http.HttpBase;
|
||||
import jodd.http.HttpRequest;
|
||||
import jodd.http.HttpResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -72,21 +69,6 @@ class JoddHttpHttpAttributesGetterTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFlavor() {
|
||||
HttpRequest request = HttpRequest.get("/test").httpVersion(HttpBase.HTTP_1_1);
|
||||
assertEquals(HttpFlavorValues.HTTP_1_1, attributesGetter.getFlavor(request, null));
|
||||
request.httpVersion(null);
|
||||
assertNull(attributesGetter.getFlavor(request, null));
|
||||
request.httpVersion("INVALID-HTTP-Version");
|
||||
assertNull(attributesGetter.getFlavor(request, null));
|
||||
request.httpVersion(null);
|
||||
HttpResponse response = new HttpResponse().httpVersion(HttpBase.HTTP_1_0);
|
||||
assertEquals(HttpFlavorValues.HTTP_1_0, attributesGetter.getFlavor(request, response));
|
||||
response.httpVersion(null);
|
||||
assertNull(attributesGetter.getFlavor(request, response));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getResponseHeader() {
|
||||
HttpResponse response =
|
||||
|
|
|
@ -14,9 +14,6 @@ internal object KtorHttpClientAttributesGetter : HttpClientAttributesGetter<Http
|
|||
override fun getUrl(request: HttpRequestData) =
|
||||
request.url.toString()
|
||||
|
||||
override fun getFlavor(request: HttpRequestData, response: HttpResponse?) =
|
||||
null
|
||||
|
||||
override fun getMethod(request: HttpRequestData) =
|
||||
request.method.value
|
||||
|
||||
|
|
|
@ -14,6 +14,14 @@ internal object KtorNetClientAttributesGetter : NetClientAttributesGetter<HttpRe
|
|||
|
||||
override fun getTransport(request: HttpRequestData, response: HttpResponse?) = IP_TCP
|
||||
|
||||
override fun getProtocolName(request: HttpRequestData?, response: HttpResponse?): String? =
|
||||
response?.version?.name
|
||||
|
||||
override fun getProtocolVersion(request: HttpRequestData?, response: HttpResponse?): String? {
|
||||
val version = response?.version ?: return null
|
||||
return "${version.major}.${version.minor}"
|
||||
}
|
||||
|
||||
override fun getPeerName(request: HttpRequestData) = request.url.host
|
||||
|
||||
override fun getPeerPort(request: HttpRequestData) = request.url.port
|
||||
|
|
|
@ -12,12 +12,12 @@ import io.ktor.client.request.*
|
|||
import io.ktor.http.*
|
||||
import io.opentelemetry.context.Context
|
||||
import io.opentelemetry.extension.kotlin.asContextElement
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_FLAVOR
|
||||
import kotlinx.coroutines.*
|
||||
import org.junit.jupiter.api.extension.RegisterExtension
|
||||
import java.net.URI
|
||||
|
@ -58,7 +58,7 @@ class KtorHttpClientTest : AbstractHttpClientTest<HttpRequestBuilder>() {
|
|||
// related issue https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/5722
|
||||
disableTestRedirects()
|
||||
|
||||
setHttpAttributes { DEFAULT_HTTP_ATTRIBUTES - HTTP_FLAVOR }
|
||||
setHttpAttributes { DEFAULT_HTTP_ATTRIBUTES - setOf(NetAttributes.NET_PROTOCOL_NAME, NetAttributes.NET_PROTOCOL_VERSION) }
|
||||
|
||||
setSingleConnectionFactory { host, port ->
|
||||
KtorHttpClientSingleConnection(host, port) { installTracing() }
|
||||
|
|
|
@ -9,7 +9,6 @@ import static java.util.Collections.emptyList;
|
|||
|
||||
import io.kubernetes.client.openapi.ApiResponse;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import okhttp3.Request;
|
||||
|
@ -32,11 +31,6 @@ class KubernetesHttpAttributesGetter
|
|||
return request.headers(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(Request request, @Nullable ApiResponse<?> apiResponse) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatusCode(
|
||||
Request request, ApiResponse<?> apiResponse, @Nullable Throwable error) {
|
||||
|
|
|
@ -195,7 +195,6 @@ class KubernetesClientTest extends AgentInstrumentationSpecification {
|
|||
}
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" url
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_USER_AGENT" TEST_USER_AGENT
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" statusCode
|
||||
|
|
|
@ -22,13 +22,6 @@ enum NettyConnectHttpAttributesGetter
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getFlavor(
|
||||
NettyConnectionRequest nettyConnectionRequest, @Nullable Channel channel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getMethod(NettyConnectionRequest nettyConnectionRequest) {
|
||||
|
|
|
@ -39,16 +39,6 @@ final class NettyHttpClientAttributesGetter
|
|||
return values.isEmpty() ? null : values.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(
|
||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||
String flavor = requestAndChannel.request().getProtocolVersion().toString();
|
||||
if (flavor.startsWith("HTTP/")) {
|
||||
flavor = flavor.substring("HTTP/".length());
|
||||
}
|
||||
return flavor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod(HttpRequestAndChannel requestAndChannel) {
|
||||
return requestAndChannel.request().getMethod().getName();
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.net.SocketAddress;
|
|||
import javax.annotation.Nullable;
|
||||
import org.jboss.netty.channel.socket.DatagramChannel;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
|
||||
final class NettyNetClientAttributesGetter
|
||||
extends InetSocketAddressNetClientAttributesGetter<HttpRequestAndChannel, HttpResponse> {
|
||||
|
@ -25,6 +26,19 @@ final class NettyNetClientAttributesGetter
|
|||
return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(
|
||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) {
|
||||
return requestAndChannel.request().getProtocolVersion().getProtocolName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolVersion(
|
||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) {
|
||||
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
||||
return version.getMajorVersion() + "." + version.getMinorVersion();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPeerName(HttpRequestAndChannel requestAndChannel) {
|
||||
|
|
|
@ -22,13 +22,6 @@ enum NettyConnectHttpAttributesGetter
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getFlavor(
|
||||
NettyConnectionRequest nettyConnectionRequest, @Nullable Channel channel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getMethod(NettyConnectionRequest nettyConnectionRequest) {
|
||||
|
|
|
@ -39,16 +39,6 @@ final class NettyHttpClientAttributesGetter
|
|||
return values.isEmpty() ? null : values.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(
|
||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||
String flavor = requestAndChannel.request().getProtocolVersion().toString();
|
||||
if (flavor.startsWith("HTTP/")) {
|
||||
flavor = flavor.substring("HTTP/".length());
|
||||
}
|
||||
return flavor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod(HttpRequestAndChannel requestAndChannel) {
|
||||
return requestAndChannel.request().getMethod().name();
|
||||
|
|
|
@ -10,6 +10,7 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr
|
|||
|
||||
import io.netty.channel.socket.DatagramChannel;
|
||||
import io.netty.handler.codec.http.HttpResponse;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
|
||||
import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -25,6 +26,19 @@ final class NettyNetClientAttributesGetter
|
|||
return requestAndChannel.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(
|
||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||
return requestAndChannel.request().getProtocolVersion().protocolName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolVersion(
|
||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
||||
return version.majorVersion() + "." + version.minorVersion();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPeerName(HttpRequestAndChannel requestAndChannel) {
|
||||
|
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.javaagent.instrumentation.okhttp.v2_2;
|
|||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Response;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -34,25 +33,6 @@ final class OkHttp2HttpAttributesGetter implements HttpClientAttributesGetter<Re
|
|||
return response.code();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFlavor(Request request, @Nullable Response response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
switch (response.protocol()) {
|
||||
case HTTP_1_0:
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
|
||||
case HTTP_1_1:
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
case HTTP_2:
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
case SPDY_3:
|
||||
return SemanticAttributes.HttpFlavorValues.SPDY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(Request request, Response response, String name) {
|
||||
return response.headers(name);
|
||||
|
|
|
@ -19,6 +19,42 @@ public final class OkHttp2NetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(Request request, @Nullable Response response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
switch (response.protocol()) {
|
||||
case HTTP_1_0:
|
||||
case HTTP_1_1:
|
||||
case HTTP_2:
|
||||
return "http";
|
||||
case SPDY_3:
|
||||
return "spdy";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(Request request, @Nullable Response response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
switch (response.protocol()) {
|
||||
case HTTP_1_0:
|
||||
return "1.0";
|
||||
case HTTP_1_1:
|
||||
return "1.1";
|
||||
case HTTP_2:
|
||||
return "2.0";
|
||||
case SPDY_3:
|
||||
return "3.1";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(Request request) {
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.okhttp.v2_2;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
|
||||
import com.squareup.okhttp.Callback;
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
|
@ -18,7 +20,6 @@ import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTes
|
|||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashSet;
|
||||
|
@ -101,12 +102,13 @@ public class OkHttp2Test extends AbstractHttpClientTest<Request> {
|
|||
Set<AttributeKey<?>> attributes =
|
||||
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
|
||||
// flavor is extracted from the response, and those URLs cause exceptions (= null
|
||||
// protocol is extracted from the response, and those URLs cause exceptions (= null
|
||||
// response)
|
||||
if ("http://localhost:61/".equals(uri.toString())
|
||||
|| "https://192.0.2.1/".equals(uri.toString())
|
||||
|| resolveAddress("/read-timeout").toString().equals(uri.toString())) {
|
||||
attributes.remove(SemanticAttributes.HTTP_FLAVOR);
|
||||
attributes.remove(stringKey("net.protocol.name"));
|
||||
attributes.remove(stringKey("net.protocol.version"));
|
||||
}
|
||||
|
||||
return attributes;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package io.opentelemetry.instrumentation.okhttp.v3_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import okhttp3.Request;
|
||||
|
@ -30,28 +29,6 @@ enum OkHttpAttributesGetter implements HttpClientAttributesGetter<Request, Respo
|
|||
return request.headers(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnnecessaryDefaultInEnumSwitch")
|
||||
@Nullable
|
||||
public String getFlavor(Request request, @Nullable Response response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
switch (response.protocol()) {
|
||||
case HTTP_1_0:
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
|
||||
case HTTP_1_1:
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
case HTTP_2:
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
|
||||
case SPDY_3:
|
||||
return SemanticAttributes.HttpFlavorValues.SPDY;
|
||||
// No OTel mapping for other protocols like H2C.
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatusCode(Request request, Response response, @Nullable Throwable error) {
|
||||
return response.code();
|
||||
|
|
|
@ -23,6 +23,42 @@ public final class OkHttpNetAttributesGetter
|
|||
return SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(Request request, @Nullable Response response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
switch (response.protocol()) {
|
||||
case HTTP_1_0:
|
||||
case HTTP_1_1:
|
||||
case HTTP_2:
|
||||
return "http";
|
||||
case SPDY_3:
|
||||
return "spdy";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(Request request, @Nullable Response response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
switch (response.protocol()) {
|
||||
case HTTP_1_0:
|
||||
return "1.0";
|
||||
case HTTP_1_1:
|
||||
return "1.1";
|
||||
case HTTP_2:
|
||||
return "2.0";
|
||||
case SPDY_3:
|
||||
return "3.1";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPeerName(Request request) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.okhttp.v3_0;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -13,7 +14,6 @@ import io.opentelemetry.api.trace.SpanKind;
|
|||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
|
@ -119,12 +119,13 @@ public abstract class AbstractOkHttp3Test extends AbstractHttpClientTest<Request
|
|||
Set<AttributeKey<?>> attributes =
|
||||
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
|
||||
// flavor is extracted from the response, and those URLs cause exceptions (= null
|
||||
// protocol is extracted from the response, and those URLs cause exceptions (= null
|
||||
// response)
|
||||
if ("http://localhost:61/".equals(uri.toString())
|
||||
|| "https://192.0.2.1/".equals(uri.toString())
|
||||
|| resolveAddress("/read-timeout").toString().equals(uri.toString())) {
|
||||
attributes.remove(SemanticAttributes.HTTP_FLAVOR);
|
||||
attributes.remove(stringKey("net.protocol.name"));
|
||||
attributes.remove(stringKey("net.protocol.version"));
|
||||
}
|
||||
|
||||
return attributes;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
|
@ -103,12 +104,11 @@ public class OpenSearchRestTest {
|
|||
equalTo(
|
||||
SemanticAttributes.NET_TRANSPORT,
|
||||
SemanticAttributes.NetTransportValues.IP_TCP),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_FLAVOR,
|
||||
SemanticAttributes.HttpFlavorValues.HTTP_1_1),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
|
@ -178,12 +178,11 @@ public class OpenSearchRestTest {
|
|||
equalTo(
|
||||
SemanticAttributes.NET_TRANSPORT,
|
||||
SemanticAttributes.NetTransportValues.IP_TCP),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_FLAVOR,
|
||||
SemanticAttributes.HttpFlavorValues.HTTP_1_1),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
|
|
|
@ -10,8 +10,6 @@ import io.opentelemetry.instrumentation.test.AgentTestTrait
|
|||
import io.opentelemetry.instrumentation.test.base.HttpClientTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.SingleConnection
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import play.libs.ws.WS
|
||||
import play.libs.ws.WSRequest
|
||||
import play.libs.ws.WSResponse
|
||||
|
@ -19,8 +17,11 @@ import spock.lang.AutoCleanup
|
|||
import spock.lang.Shared
|
||||
import spock.lang.Subject
|
||||
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.CompletionStage
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey
|
||||
|
||||
class PlayWsClientTest extends HttpClientTest<WSRequest> implements AgentTestTrait {
|
||||
@Subject
|
||||
@Shared
|
||||
|
@ -51,10 +52,10 @@ class PlayWsClientTest extends HttpClientTest<WSRequest> implements AgentTestTra
|
|||
private static CompletionStage<WSResponse> internalSendRequest(WSRequest request, String method) {
|
||||
def result = new CompletableFuture<WSResponse>()
|
||||
def promise = request.execute(method)
|
||||
promise.onRedeem({response ->
|
||||
promise.onRedeem({ response ->
|
||||
result.complete(response)
|
||||
})
|
||||
promise.onFailure({throwable ->
|
||||
promise.onFailure({ throwable ->
|
||||
result.completeExceptionally(throwable)
|
||||
})
|
||||
return result
|
||||
|
@ -73,11 +74,10 @@ class PlayWsClientTest extends HttpClientTest<WSRequest> implements AgentTestTra
|
|||
|
||||
@Override
|
||||
Set<AttributeKey<?>> httpAttributes(URI uri) {
|
||||
Set<AttributeKey<?>> extra = [
|
||||
SemanticAttributes.HTTP_SCHEME,
|
||||
SemanticAttributes.HTTP_TARGET
|
||||
]
|
||||
super.httpAttributes(uri) + extra
|
||||
def attributes = super.httpAttributes(uri)
|
||||
attributes.remove(stringKey("net.protocol.name"))
|
||||
attributes.remove(stringKey("net.protocol.version"))
|
||||
attributes
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.playws;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import play.shaded.ahc.org.asynchttpclient.Request;
|
||||
|
@ -35,11 +34,6 @@ final class PlayWsClientHttpAttributesGetter
|
|||
return response.getStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(Request request, @Nullable Response response) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResponseHeader(Request request, Response response, String name) {
|
||||
return response.getHeaders().getAll(name);
|
||||
|
|
|
@ -21,6 +21,8 @@ import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClientConfig
|
|||
import play.shaded.ahc.org.asynchttpclient.RequestBuilderBase
|
||||
import spock.lang.Shared
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey
|
||||
|
||||
abstract class PlayWsClientTestBaseBase<REQUEST> extends HttpClientTest<REQUEST> implements AgentTestTrait {
|
||||
@Shared
|
||||
ActorSystem system
|
||||
|
@ -65,11 +67,9 @@ abstract class PlayWsClientTestBaseBase<REQUEST> extends HttpClientTest<REQUEST>
|
|||
|
||||
@Override
|
||||
Set<AttributeKey<?>> httpAttributes(URI uri) {
|
||||
Set<AttributeKey<?>> extra = [
|
||||
SemanticAttributes.HTTP_SCHEME,
|
||||
SemanticAttributes.HTTP_TARGET
|
||||
]
|
||||
def attributes = super.httpAttributes(uri) + extra
|
||||
def attributes = super.httpAttributes(uri)
|
||||
attributes.remove(stringKey("net.protocol.name"))
|
||||
attributes.remove(stringKey("net.protocol.version"))
|
||||
if (uri.toString().endsWith("/circular-redirect")) {
|
||||
attributes.remove(SemanticAttributes.NET_PEER_NAME)
|
||||
attributes.remove(SemanticAttributes.NET_PEER_PORT)
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package io.opentelemetry.instrumentation.ratpack.v1_7;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import ratpack.http.client.HttpResponse;
|
||||
|
@ -22,11 +21,6 @@ enum RatpackHttpClientAttributesGetter
|
|||
return requestSpec.getUri().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlavor(RequestSpec requestSpec, @Nullable HttpResponse httpResponse) {
|
||||
return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getMethod(RequestSpec requestSpec) {
|
||||
|
|
|
@ -5,15 +5,20 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.ratpack.v1_7;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.netty.channel.ConnectTimeoutException;
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
|
@ -147,5 +152,14 @@ abstract class AbstractRatpackHttpClientTest extends AbstractHttpClientTest<Void
|
|||
optionsBuilder.disableTestRedirects();
|
||||
optionsBuilder.disableTestReusedRequest();
|
||||
optionsBuilder.enableTestReadTimeout();
|
||||
|
||||
optionsBuilder.setHttpAttributes(this::getHttpAttributes);
|
||||
}
|
||||
|
||||
protected Set<AttributeKey<?>> getHttpAttributes(URI uri) {
|
||||
Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
attributes.remove(stringKey("net.protocol.name"));
|
||||
attributes.remove(stringKey("net.protocol.version"));
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,19 +57,6 @@ final class ReactorNettyHttpClientAttributesGetter
|
|||
return uri != null && !uri.isEmpty() && !uri.startsWith("/");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getFlavor(HttpClientConfig request, @Nullable HttpClientResponse response) {
|
||||
if (response != null) {
|
||||
String flavor = response.version().text();
|
||||
if (flavor.startsWith("HTTP/")) {
|
||||
flavor = flavor.substring("HTTP/".length());
|
||||
}
|
||||
return flavor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod(HttpClientConfig request) {
|
||||
return request.method().name();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0;
|
||||
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
@ -22,6 +23,26 @@ final class ReactorNettyNetClientAttributesGetter
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolName(HttpClientConfig request, @Nullable HttpClientResponse response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
return response.version().protocolName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProtocolVersion(
|
||||
HttpClientConfig request, @Nullable HttpClientResponse response) {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
HttpVersion version = response.version();
|
||||
return version.majorVersion() + "." + version.minorVersion();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPeerName(HttpClientConfig request) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
|
||||
import static io.opentelemetry.api.trace.SpanKind.SERVER;
|
||||
|
@ -133,9 +134,10 @@ abstract class AbstractReactorNettyHttpClientTest
|
|||
|
||||
Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
if (uri.toString().contains("/read-timeout")) {
|
||||
attributes.remove(stringKey("net.protocol.name"));
|
||||
attributes.remove(stringKey("net.protocol.version"));
|
||||
attributes.remove(SemanticAttributes.NET_PEER_NAME);
|
||||
attributes.remove(SemanticAttributes.NET_PEER_PORT);
|
||||
attributes.remove(SemanticAttributes.HTTP_FLAVOR);
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
|
||||
import static io.opentelemetry.api.trace.SpanKind.SERVER;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||
|
@ -109,11 +109,12 @@ class ReactorNettyBaseUrlOnlyTest {
|
|||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, uri + "/"),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, HTTP_1_1),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isNotNegative),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")),
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
|
||||
import static io.opentelemetry.api.trace.SpanKind.SERVER;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
|
||||
|
@ -154,11 +154,12 @@ class ReactorNettyClientSslTest {
|
|||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, uri),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, HTTP_1_1),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isNotNegative),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, server.httpsPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")),
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
|
||||
import static io.opentelemetry.api.trace.SpanKind.SERVER;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HttpFlavorValues.HTTP_1_1;
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
|
@ -80,11 +80,12 @@ class ReactorNettyConnectionSpanTest {
|
|||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, uri),
|
||||
equalTo(SemanticAttributes.HTTP_FLAVOR, HTTP_1_1),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isNotNegative),
|
||||
equalTo(stringKey("net.protocol.name"), "http"),
|
||||
equalTo(stringKey("net.protocol.version"), "1.1"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")),
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue