HTTP semconv: filter out default peer/host ports (#7258)

After a loooong break, the next part of the HTTP semconv implementation:
filtering out default HTTP ports, client and server.

>  [5]: If not default (80 for http scheme, 443 for https).


https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-client
This commit is contained in:
Mateusz Rzeszutek 2022-11-22 18:14:20 +01:00 committed by GitHub
parent 5c5bde7853
commit 95ec4a8c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 627 additions and 368 deletions

View File

@ -9,6 +9,8 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorU
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
@ -29,32 +31,79 @@ public final class HttpClientAttributesExtractor<REQUEST, RESPONSE>
REQUEST, RESPONSE, HttpClientAttributesGetter<REQUEST, RESPONSE>>
implements SpanKeyProvider {
/** Creates the HTTP client attributes extractor with default configuration. */
/**
* Creates the HTTP client attributes extractor with default configuration.
*
* @deprecated Use {@link #create(HttpClientAttributesGetter, NetClientAttributesGetter)} instead.
*/
@Deprecated
public static <REQUEST, RESPONSE> HttpClientAttributesExtractor<REQUEST, RESPONSE> create(
HttpClientAttributesGetter<REQUEST, RESPONSE> getter) {
return builder(getter).build();
}
/** Creates the HTTP client attributes extractor with default configuration. */
public static <REQUEST, RESPONSE> HttpClientAttributesExtractor<REQUEST, RESPONSE> create(
HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
return builder(httpAttributesGetter, netAttributesGetter).build();
}
/**
* Returns a new {@link HttpClientAttributesExtractorBuilder} that can be used to configure the
* HTTP client attributes extractor.
*
* @deprecated Use {@link #builder(HttpClientAttributesGetter, NetClientAttributesGetter)}
* instead.
*/
@Deprecated
public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> builder(
HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter) {
return builder(httpAttributesGetter, new NoopNetClientAttributesGetter<>());
}
/**
* Returns a new {@link HttpClientAttributesExtractorBuilder} that can be used to configure the
* HTTP client attributes extractor.
*/
public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> builder(
HttpClientAttributesGetter<REQUEST, RESPONSE> getter) {
return new HttpClientAttributesExtractorBuilder<>(getter);
HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
return new HttpClientAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter);
}
private final InternalNetClientAttributesExtractor<REQUEST, RESPONSE> internalNetExtractor;
HttpClientAttributesExtractor(
HttpClientAttributesGetter<REQUEST, RESPONSE> getter,
HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter,
List<String> capturedRequestHeaders,
List<String> responseHeaders) {
super(getter, capturedRequestHeaders, responseHeaders);
List<String> capturedResponseHeaders) {
super(httpAttributesGetter, capturedRequestHeaders, capturedResponseHeaders);
internalNetExtractor =
new InternalNetClientAttributesExtractor<>(
netAttributesGetter, this::shouldCapturePeerPort);
}
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);
internalSet(attributes, SemanticAttributes.HTTP_URL, stripSensitiveData(getter.url(request)));
internalNetExtractor.onStart(attributes, request);
}
private boolean shouldCapturePeerPort(int port, REQUEST request) {
String url = getter.url(request);
if (url == null) {
return true;
}
// according to spec: extract if not default (80 for http scheme, 443 for https).
if ((url.startsWith("http://") && port == 80) || (url.startsWith("https://") && port == 443)) {
return false;
}
return true;
}
@Nullable
@ -108,7 +157,10 @@ public final class HttpClientAttributesExtractor<REQUEST, RESPONSE>
@Nullable RESPONSE response,
@Nullable Throwable error) {
super.onEnd(attributes, context, request, response, error);
internalSet(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request, response));
internalNetExtractor.onEnd(attributes, request, response);
}
/**
@ -119,4 +171,26 @@ public final class HttpClientAttributesExtractor<REQUEST, RESPONSE>
public SpanKey internalGetSpanKey() {
return SpanKey.HTTP_CLIENT;
}
private static final class NoopNetClientAttributesGetter<REQUEST, RESPONSE>
implements NetClientAttributesGetter<REQUEST, RESPONSE> {
@Nullable
@Override
public String transport(REQUEST request, @Nullable RESPONSE response) {
return null;
}
@Nullable
@Override
public String peerName(REQUEST request) {
return null;
}
@Nullable
@Override
public Integer peerPort(REQUEST request) {
return null;
}
}
}

View File

@ -8,17 +8,22 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
import static java.util.Collections.emptyList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import java.util.List;
/** A builder of {@link HttpClientAttributesExtractor}. */
public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
final HttpClientAttributesGetter<REQUEST, RESPONSE> getter;
final HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter;
final NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter;
List<String> capturedRequestHeaders = emptyList();
List<String> capturedResponseHeaders = emptyList();
HttpClientAttributesExtractorBuilder(HttpClientAttributesGetter<REQUEST, RESPONSE> getter) {
this.getter = getter;
HttpClientAttributesExtractorBuilder(
HttpClientAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetClientAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
this.httpAttributesGetter = httpAttributesGetter;
this.netAttributesGetter = netAttributesGetter;
}
/**
@ -64,6 +69,6 @@ public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
*/
public HttpClientAttributesExtractor<REQUEST, RESPONSE> build() {
return new HttpClientAttributesExtractor<>(
getter, capturedRequestHeaders, capturedResponseHeaders);
httpAttributesGetter, netAttributesGetter, capturedRequestHeaders, capturedResponseHeaders);
}
}

View File

@ -53,7 +53,7 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
return new HttpServerAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter);
}
private final NetServerAttributesGetter<REQUEST> netAttributesGetter;
private final InternalNetServerAttributesExtractor<REQUEST> internalNetExtractor;
private final Function<Context, String> httpRouteHolderGetter;
HttpServerAttributesExtractor(
@ -74,10 +74,12 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
NetServerAttributesGetter<REQUEST> netAttributesGetter,
List<String> capturedRequestHeaders,
List<String> responseHeaders,
List<String> capturedResponseHeaders,
Function<Context, String> httpRouteHolderGetter) {
super(httpAttributesGetter, capturedRequestHeaders, responseHeaders);
this.netAttributesGetter = netAttributesGetter;
super(httpAttributesGetter, capturedRequestHeaders, capturedResponseHeaders);
internalNetExtractor =
new InternalNetServerAttributesExtractor<>(
netAttributesGetter, this::shouldCaptureHostPort);
this.httpRouteHolderGetter = httpRouteHolderGetter;
}
@ -93,8 +95,19 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
internalSet(attributes, SemanticAttributes.HTTP_ROUTE, getter.route(request));
internalSet(attributes, SemanticAttributes.HTTP_CLIENT_IP, clientIp(request));
InternalNetServerAttributesExtractor.onStart(
netAttributesGetter, attributes, request, host(request));
internalNetExtractor.onStart(attributes, request, host(request));
}
private boolean shouldCaptureHostPort(int port, REQUEST request) {
String scheme = getter.scheme(request);
if (scheme == null) {
return true;
}
// according to spec: extract if not default (80 for http scheme, 443 for https).
if ((scheme.equals("http") && port == 80) || (scheme.equals("https") && port == 443)) {
return false;
}
return true;
}
@Override

View File

@ -5,12 +5,10 @@
package io.opentelemetry.instrumentation.api.instrumenter.net;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
import javax.annotation.Nullable;
/**
@ -25,7 +23,7 @@ import javax.annotation.Nullable;
public final class NetClientAttributesExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> {
private final NetClientAttributesGetter<REQUEST, RESPONSE> getter;
private final InternalNetClientAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
public static <REQUEST, RESPONSE> NetClientAttributesExtractor<REQUEST, RESPONSE> create(
NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
@ -33,19 +31,12 @@ public final class NetClientAttributesExtractor<REQUEST, RESPONSE>
}
private NetClientAttributesExtractor(NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
this.getter = getter;
internalExtractor = new InternalNetClientAttributesExtractor<>(getter, (port, request) -> true);
}
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
String peerName = getter.peerName(request);
Integer peerPort = getter.peerPort(request);
if (peerName != null) {
internalSet(attributes, SemanticAttributes.NET_PEER_NAME, peerName);
if (peerPort != null && peerPort > 0) {
internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort);
}
}
internalExtractor.onStart(attributes, request);
}
@Override
@ -55,30 +46,6 @@ public final class NetClientAttributesExtractor<REQUEST, RESPONSE>
REQUEST request,
@Nullable RESPONSE response,
@Nullable Throwable error) {
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request, response));
String peerName = getter.peerName(request);
Integer peerPort = getter.peerPort(request);
String sockPeerAddr = getter.sockPeerAddr(request, response);
if (sockPeerAddr != null && !sockPeerAddr.equals(peerName)) {
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, sockPeerAddr);
Integer sockPeerPort = getter.sockPeerPort(request, response);
if (sockPeerPort != null && sockPeerPort > 0 && !sockPeerPort.equals(peerPort)) {
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) sockPeerPort);
}
String sockFamily = getter.sockFamily(request, response);
if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) {
internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily);
}
String sockPeerName = getter.sockPeerName(request, response);
if (sockPeerName != null && !sockPeerName.equals(peerName)) {
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_NAME, sockPeerName);
}
}
internalExtractor.onEnd(attributes, request, response);
}
}

View File

@ -20,7 +20,7 @@ import javax.annotation.Nullable;
public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> {
private final NetServerAttributesGetter<REQUEST> getter;
private final InternalNetServerAttributesExtractor<REQUEST> internalExtractor;
public static <REQUEST, RESPONSE> NetServerAttributesExtractor<REQUEST, RESPONSE> create(
NetServerAttributesGetter<REQUEST> getter) {
@ -28,12 +28,13 @@ public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
}
private NetServerAttributesExtractor(NetServerAttributesGetter<REQUEST> getter) {
this.getter = getter;
internalExtractor =
new InternalNetServerAttributesExtractor<>(getter, (integer, request) -> true);
}
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
InternalNetServerAttributesExtractor.onStart(getter, attributes, request, null);
internalExtractor.onStart(attributes, request, null);
}
@Override

View File

@ -0,0 +1,73 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter.net.internal;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.function.BiPredicate;
import javax.annotation.Nullable;
/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class InternalNetClientAttributesExtractor<REQUEST, RESPONSE> {
private final NetClientAttributesGetter<REQUEST, RESPONSE> getter;
private final BiPredicate<Integer, REQUEST> capturePeerPortCondition;
public InternalNetClientAttributesExtractor(
NetClientAttributesGetter<REQUEST, RESPONSE> getter,
BiPredicate<Integer, REQUEST> capturePeerPortCondition) {
this.getter = getter;
this.capturePeerPortCondition = capturePeerPortCondition;
}
public void onStart(AttributesBuilder attributes, REQUEST request) {
String peerName = getter.peerName(request);
Integer peerPort = getter.peerPort(request);
// TODO: add host header parsing
if (peerName != null) {
internalSet(attributes, SemanticAttributes.NET_PEER_NAME, peerName);
if (peerPort != null && peerPort > 0 && capturePeerPortCondition.test(peerPort, request)) {
internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort);
}
}
}
public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) {
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request, response));
String peerName = getter.peerName(request);
Integer peerPort = getter.peerPort(request);
String sockPeerAddr = getter.sockPeerAddr(request, response);
if (sockPeerAddr != null && !sockPeerAddr.equals(peerName)) {
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, sockPeerAddr);
Integer sockPeerPort = getter.sockPeerPort(request, response);
if (sockPeerPort != null && sockPeerPort > 0 && !sockPeerPort.equals(peerPort)) {
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) sockPeerPort);
}
String sockFamily = getter.sockFamily(request, response);
if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) {
internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily);
}
String sockPeerName = getter.sockPeerName(request, response);
if (sockPeerName != null && !sockPeerName.equals(peerName)) {
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_NAME, sockPeerName);
}
}
}
}

View File

@ -11,6 +11,7 @@ import static java.util.logging.Level.FINE;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.function.BiPredicate;
import java.util.logging.Logger;
import javax.annotation.Nullable;
@ -18,16 +19,22 @@ import javax.annotation.Nullable;
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public class InternalNetServerAttributesExtractor {
public final class InternalNetServerAttributesExtractor<REQUEST> {
private static final Logger logger =
Logger.getLogger(InternalNetServerAttributesExtractor.class.getName());
public static <REQUEST> void onStart(
private final NetServerAttributesGetter<REQUEST> getter;
private final BiPredicate<Integer, REQUEST> captureHostPortCondition;
public InternalNetServerAttributesExtractor(
NetServerAttributesGetter<REQUEST> getter,
AttributesBuilder attributes,
REQUEST request,
@Nullable String hostHeader) {
BiPredicate<Integer, REQUEST> captureHostPortCondition) {
this.getter = getter;
this.captureHostPortCondition = captureHostPortCondition;
}
public void onStart(AttributesBuilder attributes, REQUEST request, @Nullable String hostHeader) {
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request));
boolean setSockFamily = false;
@ -66,7 +73,7 @@ public class InternalNetServerAttributesExtractor {
if (hostName != null) {
internalSet(attributes, SemanticAttributes.NET_HOST_NAME, hostName);
if (hostPort != null && hostPort > 0) {
if (hostPort != null && hostPort > 0 && captureHostPortCondition.test(hostPort, request)) {
internalSet(attributes, SemanticAttributes.NET_HOST_PORT, (long) hostPort);
}
}
@ -90,6 +97,4 @@ public class InternalNetServerAttributesExtractor {
}
}
}
private InternalNetServerAttributesExtractor() {}
}

View File

@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.api.instrumenter.http;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
@ -16,6 +17,7 @@ import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashMap;
import java.util.List;
@ -23,9 +25,11 @@ import java.util.Map;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
class HttpClientAttributesExtractorTest {
@ -67,6 +71,29 @@ class HttpClientAttributesExtractorTest {
}
}
static class TestNetClientAttributesGetter
implements NetClientAttributesGetter<Map<String, String>, Map<String, String>> {
@Nullable
@Override
public String transport(Map<String, String> request, @Nullable Map<String, String> response) {
return response.get("transport");
}
@Nullable
@Override
public String peerName(Map<String, String> request) {
return request.get("peerName");
}
@Nullable
@Override
public Integer peerPort(Map<String, String> request) {
String statusCode = request.get("peerPort");
return statusCode == null ? null : Integer.parseInt(statusCode);
}
}
@Test
void normal() {
Map<String, String> request = new HashMap<>();
@ -76,31 +103,25 @@ class HttpClientAttributesExtractorTest {
request.put("flavor", "http/2");
request.put("header.user-agent", "okhttp 3.x");
request.put("header.custom-request-header", "123,456");
request.put("peerName", "github.com");
request.put("peerPort", "123");
Map<String, String> response = new HashMap<>();
response.put("statusCode", "202");
response.put("header.content-length", "20");
response.put("header.custom-response-header", "654,321");
response.put("transport", IP_TCP);
HttpClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor =
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter())
HttpClientAttributesExtractor.builder(
new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter())
.setCapturedRequestHeaders(singletonList("Custom-Request-Header"))
.setCapturedResponseHeaders(singletonList("Custom-Response-Header"))
.build();
AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, Context.root(), request);
assertThat(attributes.build())
.containsOnly(
entry(SemanticAttributes.HTTP_METHOD, "POST"),
entry(SemanticAttributes.HTTP_URL, "http://github.com"),
entry(SemanticAttributes.HTTP_USER_AGENT, "okhttp 3.x"),
entry(
AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
asList("123", "456")));
extractor.onEnd(attributes, Context.root(), request, response, null);
assertThat(attributes.build())
AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build())
.containsOnly(
entry(SemanticAttributes.HTTP_METHOD, "POST"),
entry(SemanticAttributes.HTTP_URL, "http://github.com"),
@ -108,46 +129,56 @@ class HttpClientAttributesExtractorTest {
entry(
AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
asList("123", "456")),
entry(SemanticAttributes.NET_PEER_NAME, "github.com"),
entry(SemanticAttributes.NET_PEER_PORT, 123L));
AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, response, null);
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(
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
asList("654", "321")));
asList("654", "321")),
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP));
}
@ParameterizedTest
@MethodSource("stripUrlArguments")
@ArgumentsSource(StripUrlArgumentSource.class)
void stripBasicAuthTest(String url, String expectedResult) {
Map<String, String> request = new HashMap<>();
request.put("url", url);
stripRequestTest(request, expectedResult);
}
private static Stream<Arguments> stripUrlArguments() {
return Stream.of(
arguments("https://user1:secret@github.com", "https://github.com"),
arguments("https://user1:secret@github.com/path/", "https://github.com/path/"),
arguments("https://user1:secret@github.com#test.html", "https://github.com#test.html"),
arguments("https://user1:secret@github.com?foo=b@r", "https://github.com?foo=b@r"),
arguments(
"https://user1:secret@github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"),
arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"),
arguments("https://github.com#t@st.html", "https://github.com#t@st.html"),
arguments("user1:secret@github.com", "user1:secret@github.com"),
arguments("https://github.com@", "https://github.com@"));
}
private static void stripRequestTest(Map<String, String> request, String expected) {
HttpClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor =
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()).build();
HttpClientAttributesExtractor.builder(
new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter())
.build();
AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, Context.root(), request);
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_URL, expected));
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_URL, expectedResult));
}
static final class StripUrlArgumentSource implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
arguments("https://user1:secret@github.com", "https://github.com"),
arguments("https://user1:secret@github.com/path/", "https://github.com/path/"),
arguments("https://user1:secret@github.com#test.html", "https://github.com#test.html"),
arguments("https://user1:secret@github.com?foo=b@r", "https://github.com?foo=b@r"),
arguments(
"https://user1:secret@github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"),
arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"),
arguments("https://github.com#t@st.html", "https://github.com#t@st.html"),
arguments("user1:secret@github.com", "user1:secret@github.com"),
arguments("https://github.com@", "https://github.com@"));
}
}
@Test
@ -158,7 +189,8 @@ class HttpClientAttributesExtractorTest {
response.put("statusCode", "0");
HttpClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor =
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter())
HttpClientAttributesExtractor.builder(
new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter())
.setCapturedRequestHeaders(emptyList())
.setCapturedResponseHeaders(emptyList())
.build();
@ -170,4 +202,30 @@ class HttpClientAttributesExtractorTest {
extractor.onEnd(attributes, Context.root(), request, response, null);
assertThat(attributes.build()).isEmpty();
}
@ParameterizedTest
@ArgumentsSource(DefaultPeerPortArgumentSource.class)
void defaultPeerPort(int peerPort, String url) {
Map<String, String> request = new HashMap<>();
request.put("url", url);
request.put("peerPort", String.valueOf(peerPort));
HttpClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor =
HttpClientAttributesExtractor.builder(
new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter())
.build();
AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, Context.root(), request);
assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NET_PEER_PORT);
}
static class DefaultPeerPortArgumentSource implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(arguments(80, "http://github.com"), arguments(443, "https://github.com"));
}
}
}

View File

@ -10,6 +10,7 @@ import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.entry;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
@ -21,8 +22,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
class HttpServerAttributesExtractorTest {
@ -247,4 +254,32 @@ class HttpServerAttributesExtractorTest {
entry(SemanticAttributes.NET_HOST_NAME, "thehost"),
entry(SemanticAttributes.NET_HOST_PORT, 777L));
}
@ParameterizedTest
@ArgumentsSource(DefaultHostPortArgumentSource.class)
void defaultHostPort(int hostPort, String scheme) {
Map<String, Object> request = new HashMap<>();
request.put("scheme", scheme);
request.put("hostPort", hostPort);
HttpServerAttributesExtractor<Map<String, Object>, Map<String, Object>> extractor =
HttpServerAttributesExtractor.builder(
new TestHttpServerAttributesGetter(), new TestNetServerAttributesGetter())
.setCapturedRequestHeaders(emptyList())
.setCapturedResponseHeaders(emptyList())
.build();
AttributesBuilder attributes = Attributes.builder();
extractor.onStart(attributes, Context.root(), request);
assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NET_HOST_PORT);
}
static class DefaultHostPortArgumentSource implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(arguments(80, "http"), arguments(443, "https"));
}
}
}

View File

@ -10,8 +10,7 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetSocketAddress;
import java.util.Collections;
@ -42,9 +41,8 @@ public class InstrumenterBenchmark {
"benchmark",
HttpSpanNameExtractor.create(ConstantHttpAttributesGetter.INSTANCE))
.addAttributesExtractor(
HttpClientAttributesExtractor.create(ConstantHttpAttributesGetter.INSTANCE))
.addAttributesExtractor(
NetServerAttributesExtractor.create(new ConstantNetAttributesGetter()))
HttpClientAttributesExtractor.create(
ConstantHttpAttributesGetter.INSTANCE, new ConstantNetAttributesGetter()))
.buildInstrumenter();
@Benchmark
@ -97,41 +95,33 @@ public class InstrumenterBenchmark {
}
static class ConstantNetAttributesGetter
extends InetSocketAddressNetServerAttributesGetter<Void> {
extends InetSocketAddressNetClientAttributesGetter<Void, Void> {
private static final InetSocketAddress PEER_ADDRESS =
InetSocketAddress.createUnresolved("localhost", 8080);
private static final InetSocketAddress HOST_ADDRESS =
InetSocketAddress.createUnresolved("localhost", 80);
@Override
@Nullable
public String transport(Void unused) {
@Override
public String transport(Void request, @Nullable Void response) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}
@Nullable
@Override
public String hostName(Void unused) {
public String peerName(Void request) {
return null;
}
@Nullable
@Override
public Integer hostPort(Void unused) {
public Integer peerPort(Void request) {
return null;
}
@Override
@Nullable
protected InetSocketAddress getPeerSocketAddress(Void unused) {
@Override
protected InetSocketAddress getPeerSocketAddress(Void request, @Nullable Void response) {
return PEER_ADDRESS;
}
@Nullable
@Override
protected InetSocketAddress getHostSocketAddress(Void unused) {
return HOST_ADDRESS;
}
}
}

View File

@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil;
@ -35,11 +34,10 @@ public class AkkaHttpClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import org.apache.http.HttpResponse;
@ -34,11 +33,10 @@ public final class ApacheHttpAsyncClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import org.apache.commons.httpclient.HttpMethod;
@ -34,11 +33,10 @@ public final class ApacheHttpClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import org.apache.http.HttpResponse;
@ -34,11 +33,10 @@ public final class ApacheHttpClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractorBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
@ -30,7 +29,9 @@ public final class ApacheHttpClientTelemetryBuilder {
additionalExtractors = new ArrayList<>();
private final HttpClientAttributesExtractorBuilder<ApacheHttpClientRequest, HttpResponse>
httpAttributesExtractorBuilder =
HttpClientAttributesExtractor.builder(ApacheHttpClientHttpAttributesGetter.INSTANCE);
HttpClientAttributesExtractor.builder(
ApacheHttpClientHttpAttributesGetter.INSTANCE,
new ApacheHttpClientNetAttributesGetter());
ApacheHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
@ -77,8 +78,6 @@ public final class ApacheHttpClientTelemetryBuilder {
public ApacheHttpClientTelemetry build() {
ApacheHttpClientHttpAttributesGetter httpAttributesGetter =
ApacheHttpClientHttpAttributesGetter.INSTANCE;
ApacheHttpClientNetAttributesGetter netAttributesGetter =
new ApacheHttpClientNetAttributesGetter();
Instrumenter<ApacheHttpClientRequest, HttpResponse> instrumenter =
Instrumenter.<ApacheHttpClientRequest, HttpResponse>builder(
@ -87,7 +86,6 @@ public final class ApacheHttpClientTelemetryBuilder {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(httpAttributesExtractorBuilder.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractors(additionalExtractors)
// We manually inject because we need to inject internal requests for redirects.
.buildInstrumenter(SpanKindExtractor.alwaysClient());

View File

@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import org.apache.hc.core5.http.HttpRequest;
@ -35,11 +34,10 @@ public final class ApacheHttpClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -24,7 +24,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaNetClientAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.ArrayList;
@ -47,7 +46,8 @@ public final class ArmeriaTelemetryBuilder {
private final HttpClientAttributesExtractorBuilder<RequestContext, RequestLog>
httpClientAttributesExtractorBuilder =
HttpClientAttributesExtractor.builder(ArmeriaHttpClientAttributesGetter.INSTANCE);
HttpClientAttributesExtractor.builder(
ArmeriaHttpClientAttributesGetter.INSTANCE, new ArmeriaNetClientAttributesGetter());
private final HttpServerAttributesExtractorBuilder<RequestContext, RequestLog>
httpServerAttributesExtractorBuilder =
HttpServerAttributesExtractor.builder(
@ -166,16 +166,10 @@ public final class ArmeriaTelemetryBuilder {
Stream.of(clientInstrumenterBuilder, serverInstrumenterBuilder)
.forEach(instrumenter -> instrumenter.addAttributesExtractors(additionalExtractors));
ArmeriaNetClientAttributesGetter netClientAttributesGetter =
new ArmeriaNetClientAttributesGetter();
NetClientAttributesExtractor<RequestContext, RequestLog> netClientAttributesExtractor =
NetClientAttributesExtractor.create(netClientAttributesGetter);
clientInstrumenterBuilder
.setSpanStatusExtractor(
statusExtractorTransformer.apply(
HttpSpanStatusExtractor.create(clientAttributesGetter)))
.addAttributesExtractor(netClientAttributesExtractor)
.addAttributesExtractor(httpClientAttributesExtractorBuilder.build())
.addAttributesExtractors(additionalClientExtractors)
.addOperationMetrics(HttpClientMetrics.get());

View File

@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
@ -35,11 +34,10 @@ public final class AsyncHttpClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import org.asynchttpclient.Response;
@ -34,11 +33,10 @@ public final class AsyncHttpClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributeGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributeGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributeGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -12,7 +12,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
import java.util.Arrays;
import java.util.List;
@ -21,25 +20,20 @@ final class AwsSdkInstrumenterFactory {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aws-sdk-1.11";
private static final AttributesExtractor<Request<?>, Response<?>> httpAttributesExtractor =
HttpClientAttributesExtractor.create(new AwsSdkHttpAttributesGetter());
HttpClientAttributesExtractor.create(
new AwsSdkHttpAttributesGetter(), new AwsSdkNetAttributesGetter());
private static final AttributesExtractor<Request<?>, Response<?>> rpcAttributesExtractor =
RpcClientAttributesExtractor.create(AwsSdkRpcAttributesGetter.INSTANCE);
private static final AttributesExtractor<Request<?>, Response<?>> netAttributesExtractor =
NetClientAttributesExtractor.create(new AwsSdkNetAttributesGetter());
private static final AwsSdkExperimentalAttributesExtractor experimentalAttributesExtractor =
new AwsSdkExperimentalAttributesExtractor();
private static final AwsSdkSpanKindExtractor spanKindExtractor = new AwsSdkSpanKindExtractor();
private static final List<AttributesExtractor<Request<?>, Response<?>>>
defaultAttributesExtractors =
Arrays.asList(httpAttributesExtractor, rpcAttributesExtractor, netAttributesExtractor);
defaultAttributesExtractors = Arrays.asList(httpAttributesExtractor, rpcAttributesExtractor);
private static final List<AttributesExtractor<Request<?>, Response<?>>>
extendedAttributesExtractors =
Arrays.asList(
httpAttributesExtractor,
rpcAttributesExtractor,
netAttributesExtractor,
experimentalAttributesExtractor);
httpAttributesExtractor, rpcAttributesExtractor, experimentalAttributesExtractor);
private static final AwsSdkSpanNameExtractor spanName = new AwsSdkSpanNameExtractor();
static Instrumenter<Request<?>, Response<?>> requestInstrumenter(

View File

@ -10,7 +10,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
import java.util.Arrays;
import java.util.List;
@ -22,29 +21,23 @@ final class AwsSdkInstrumenterFactory {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aws-sdk-2.2";
static final AwsSdkHttpAttributesGetter httpAttributesGetter = new AwsSdkHttpAttributesGetter();
static final AttributesExtractor<ExecutionAttributes, SdkHttpResponse> httpAttributesExtractor =
HttpClientAttributesExtractor.create(httpAttributesGetter);
static final AttributesExtractor<ExecutionAttributes, SdkHttpResponse> rpcAttributesExtractor =
RpcClientAttributesExtractor.create(AwsSdkRpcAttributesGetter.INSTANCE);
private static final AwsSdkNetAttributesGetter netAttributesGetter =
new AwsSdkNetAttributesGetter();
private static final NetClientAttributesExtractor<ExecutionAttributes, SdkHttpResponse>
netAttributesExtractor = NetClientAttributesExtractor.create(netAttributesGetter);
static final AttributesExtractor<ExecutionAttributes, SdkHttpResponse> httpAttributesExtractor =
HttpClientAttributesExtractor.create(httpAttributesGetter, netAttributesGetter);
static final AttributesExtractor<ExecutionAttributes, SdkHttpResponse> rpcAttributesExtractor =
RpcClientAttributesExtractor.create(AwsSdkRpcAttributesGetter.INSTANCE);
private static final AwsSdkExperimentalAttributesExtractor experimentalAttributesExtractor =
new AwsSdkExperimentalAttributesExtractor();
private static final AwsSdkSpanKindExtractor spanKindExtractor = new AwsSdkSpanKindExtractor();
private static final List<AttributesExtractor<ExecutionAttributes, SdkHttpResponse>>
defaultAttributesExtractors =
Arrays.asList(httpAttributesExtractor, rpcAttributesExtractor, netAttributesExtractor);
defaultAttributesExtractors = Arrays.asList(httpAttributesExtractor, rpcAttributesExtractor);
private static final List<AttributesExtractor<ExecutionAttributes, SdkHttpResponse>>
extendedAttributesExtractors =
Arrays.asList(
httpAttributesExtractor,
rpcAttributesExtractor,
netAttributesExtractor,
experimentalAttributesExtractor);
httpAttributesExtractor, rpcAttributesExtractor, experimentalAttributesExtractor);
static Instrumenter<ExecutionAttributes, SdkHttpResponse> requestInstrumenter(
OpenTelemetry openTelemetry, boolean captureExperimentalSpanAttributes) {

View File

@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
@ -35,11 +34,10 @@ public class GoogleHttpClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import java.net.HttpURLConnection;
@ -31,11 +30,10 @@ public final class HttpUrlConnectionSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import java.net.http.HttpRequest;
@ -35,11 +34,10 @@ public class JdkHttpClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
@ -33,11 +32,10 @@ public class JaxRsClientSingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.client.api.Request;
@ -34,7 +33,8 @@ public final class JettyClientInstrumenterBuilder {
new ArrayList<>();
private final HttpClientAttributesExtractorBuilder<Request, Response>
httpAttributesExtractorBuilder =
HttpClientAttributesExtractor.builder(JettyClientHttpAttributesGetter.INSTANCE);
HttpClientAttributesExtractor.builder(
JettyClientHttpAttributesGetter.INSTANCE, new JettyHttpClientNetAttributesGetter());
public JettyClientInstrumenterBuilder(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
@ -61,8 +61,6 @@ public final class JettyClientInstrumenterBuilder {
public Instrumenter<Request, Response> build() {
JettyClientHttpAttributesGetter httpAttributesGetter = JettyClientHttpAttributesGetter.INSTANCE;
JettyHttpClientNetAttributesGetter netAttributesGetter =
new JettyHttpClientNetAttributesGetter();
return Instrumenter.<Request, Response>builder(
this.openTelemetry,
@ -70,7 +68,6 @@ public final class JettyClientInstrumenterBuilder {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(httpAttributesExtractorBuilder.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractors(additionalExtractors)
.addOperationMetrics(HttpClientMetrics.get())
.buildClientInstrumenter(HttpHeaderSetter.INSTANCE);

View File

@ -13,10 +13,8 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig;
import okhttp3.Request;
@ -31,22 +29,19 @@ public class KubernetesClientSingletons {
static {
KubernetesHttpAttributesGetter httpAttributesGetter = new KubernetesHttpAttributesGetter();
SpanNameExtractor<Request> spanNameExtractor =
request -> KubernetesRequestDigest.parse(request).toString();
KubernetesNetAttributesGetter netAttributesGetter = new KubernetesNetAttributesGetter();
InstrumenterBuilder<Request, ApiResponse<?>> instrumenterBuilder =
Instrumenter.<Request, ApiResponse<?>>builder(
GlobalOpenTelemetry.get(),
"io.opentelemetry.kubernetes-client-7.0",
spanNameExtractor)
request -> KubernetesRequestDigest.parse(request).toString())
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(
NetClientAttributesExtractor.create(new KubernetesNetAttributesGetter()));
.build());
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
instrumenterBuilder.addAttributesExtractor(new KubernetesExperimentalAttributesExtractor());

View File

@ -12,9 +12,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.netty.common.internal.HttpClientSpanKeyAttributesExtractor;
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest;
import io.opentelemetry.instrumentation.netty.common.internal.NettyErrorHolder;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
@ -30,25 +28,23 @@ public final class NettyClientSingletons {
private static final Instrumenter<NettyConnectionRequest, Channel> CONNECTION_INSTRUMENTER;
static {
NettyHttpClientAttributesGetter httpClientAttributesGetter =
new NettyHttpClientAttributesGetter();
NettyNetClientAttributesGetter netClientAttributesGetter = new NettyNetClientAttributesGetter();
NettyHttpClientAttributesGetter httpAttributesGetter = new NettyHttpClientAttributesGetter();
NettyNetClientAttributesGetter netAttributesGetter = new NettyNetClientAttributesGetter();
INSTRUMENTER =
Instrumenter.<HttpRequestAndChannel, HttpResponse>builder(
GlobalOpenTelemetry.get(),
INSTRUMENTATION_NAME,
HttpSpanNameExtractor.create(httpClientAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpClientAttributesGetter))
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpClientAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netClientAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netClientAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get())
.addContextCustomizer(
(context, requestAndChannel, startAttributes) -> NettyErrorHolder.init(context))
@ -56,13 +52,12 @@ public final class NettyClientSingletons {
NettyConnectNetAttributesGetter nettyConnectAttributesGetter =
new NettyConnectNetAttributesGetter();
NetClientAttributesExtractor<NettyConnectionRequest, Channel> nettyConnectAttributesExtractor =
NetClientAttributesExtractor.create(nettyConnectAttributesGetter);
CONNECTION_INSTRUMENTER =
Instrumenter.<NettyConnectionRequest, Channel>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, NettyConnectionRequest::spanName)
.addAttributesExtractor(nettyConnectAttributesExtractor)
.addAttributesExtractor(HttpClientSpanKeyAttributesExtractor.INSTANCE)
.addAttributesExtractor(
HttpClientAttributesExtractor.create(
NettyConnectHttpAttributesGetter.INSTANCE, nettyConnectAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
nettyConnectAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -0,0 +1,54 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.netty.v3_8.client;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import org.jboss.netty.channel.Channel;
enum NettyConnectHttpAttributesGetter
implements HttpClientAttributesGetter<NettyConnectionRequest, Channel> {
INSTANCE;
@Nullable
@Override
public String url(NettyConnectionRequest nettyConnectionRequest) {
return null;
}
@Nullable
@Override
public String flavor(NettyConnectionRequest nettyConnectionRequest, @Nullable Channel channel) {
return null;
}
@Nullable
@Override
public String method(NettyConnectionRequest nettyConnectionRequest) {
return null;
}
@Override
public List<String> requestHeader(NettyConnectionRequest nettyConnectionRequest, String name) {
return Collections.emptyList();
}
@Nullable
@Override
public Integer statusCode(
NettyConnectionRequest nettyConnectionRequest, Channel channel, @Nullable Throwable error) {
return null;
}
@Override
public List<String> responseHeader(
NettyConnectionRequest nettyConnectionRequest, Channel channel, String name) {
return Collections.emptyList();
}
}

View File

@ -18,7 +18,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtrac
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.netty.common.internal.HttpClientSpanKeyAttributesExtractor;
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest;
import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel;
import java.util.List;
@ -54,21 +53,17 @@ public final class NettyClientInstrumenterFactory {
List<String> capturedResponseHeaders,
List<AttributesExtractor<HttpRequestAndChannel, HttpResponse>>
additionalHttpAttributeExtractors) {
NettyHttpClientAttributesGetter httpClientAttributesGetter =
new NettyHttpClientAttributesGetter();
NettyHttpClientAttributesGetter httpAttributesGetter = new NettyHttpClientAttributesGetter();
NettyNetClientAttributesGetter netAttributesGetter = new NettyNetClientAttributesGetter();
return Instrumenter.<HttpRequestAndChannel, HttpResponse>builder(
openTelemetry,
instrumentationName,
HttpSpanNameExtractor.create(httpClientAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpClientAttributesGetter))
openTelemetry, instrumentationName, HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpClientAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(capturedRequestHeaders)
.setCapturedResponseHeaders(capturedResponseHeaders)
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(netAttributesGetter, peerServiceMapping))
.addAttributesExtractors(additionalHttpAttributeExtractors)
@ -82,10 +77,18 @@ public final class NettyClientInstrumenterFactory {
InstrumenterBuilder<NettyConnectionRequest, Channel> instrumenterBuilder =
Instrumenter.<NettyConnectionRequest, Channel>builder(
openTelemetry, instrumentationName, NettyConnectionRequest::spanName)
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(netAttributesGetter, peerServiceMapping));
if (!connectionTelemetryEnabled) {
if (connectionTelemetryEnabled) {
// when the connection telemetry is enabled, we do not want these CONNECT spans to be
// suppressed by higher-level HTTP spans - this would happen in the reactor-netty
// instrumentation
// the solution for this is to deliberately avoid using the HTTP extractor and use the plain
// net attributes extractor instead
instrumenterBuilder.addAttributesExtractor(
NetClientAttributesExtractor.create(netAttributesGetter));
} else {
// when the connection telemetry is not enabled, netty creates CONNECT spans whenever a
// connection error occurs - because there is no HTTP span in that scenario, if raw netty
// connection occurs before an HTTP message is even formed
@ -93,7 +96,9 @@ public final class NettyClientInstrumenterFactory {
// client) is used, the connection phase is a part of the HTTP span for these
// for that to happen, the CONNECT span will "pretend" to be a full HTTP span when connection
// telemetry is off
instrumenterBuilder.addAttributesExtractor(HttpClientSpanKeyAttributesExtractor.INSTANCE);
instrumenterBuilder.addAttributesExtractor(
HttpClientAttributesExtractor.create(
NettyConnectHttpAttributesGetter.INSTANCE, netAttributesGetter));
}
Instrumenter<NettyConnectionRequest, Channel> instrumenter =

View File

@ -0,0 +1,54 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.netty.v4.common.internal.client;
import io.netty.channel.Channel;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
enum NettyConnectHttpAttributesGetter
implements HttpClientAttributesGetter<NettyConnectionRequest, Channel> {
INSTANCE;
@Nullable
@Override
public String url(NettyConnectionRequest nettyConnectionRequest) {
return null;
}
@Nullable
@Override
public String flavor(NettyConnectionRequest nettyConnectionRequest, @Nullable Channel channel) {
return null;
}
@Nullable
@Override
public String method(NettyConnectionRequest nettyConnectionRequest) {
return null;
}
@Override
public List<String> requestHeader(NettyConnectionRequest nettyConnectionRequest, String name) {
return Collections.emptyList();
}
@Nullable
@Override
public Integer statusCode(
NettyConnectionRequest nettyConnectionRequest, Channel channel, @Nullable Throwable error) {
return null;
}
@Override
public List<String> responseHeader(
NettyConnectionRequest nettyConnectionRequest, Channel channel, String name) {
return Collections.emptyList();
}
}

View File

@ -1,45 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.netty.common.internal;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
import javax.annotation.Nullable;
/**
* Attributes extractor that pretends it's a {@link HttpClientAttributesExtractor} so that error
* only CONNECT spans can be suppressed by higher level HTTP clients based on netty.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public enum HttpClientSpanKeyAttributesExtractor
implements AttributesExtractor<NettyConnectionRequest, Object>, SpanKeyProvider {
INSTANCE;
@Override
public void onStart(
AttributesBuilder attributes,
Context parentContext,
NettyConnectionRequest nettyConnectionRequest) {}
@Override
public void onEnd(
AttributesBuilder attributes,
Context context,
NettyConnectionRequest nettyConnectionRequest,
@Nullable Object channel,
@Nullable Throwable error) {}
@Override
public SpanKey internalGetSpanKey() {
return SpanKey.HTTP_CLIENT;
}
}

View File

@ -17,7 +17,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
@ -29,7 +28,7 @@ public final class OkHttp2Singletons {
static {
OkHttp2HttpAttributesGetter httpAttributesGetter = new OkHttp2HttpAttributesGetter();
OkHttp2NetAttributesGetter netClientAttributesGetter = new OkHttp2NetAttributesGetter();
OkHttp2NetAttributesGetter netAttributesGetter = new OkHttp2NetAttributesGetter();
OpenTelemetry openTelemetry = GlobalOpenTelemetry.get();
@ -40,14 +39,13 @@ public final class OkHttp2Singletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netClientAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netClientAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get())
.buildInstrumenter(alwaysClient());

View File

@ -16,7 +16,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.okhttp.v3_0.internal.OkHttpNetAttributesGetter;
import java.util.ArrayList;
import java.util.List;
@ -32,7 +31,8 @@ public final class OkHttpTelemetryBuilder {
new ArrayList<>();
private final HttpClientAttributesExtractorBuilder<Request, Response>
httpAttributesExtractorBuilder =
HttpClientAttributesExtractor.builder(OkHttpAttributesGetter.INSTANCE);
HttpClientAttributesExtractor.builder(
OkHttpAttributesGetter.INSTANCE, new OkHttpNetAttributesGetter());
OkHttpTelemetryBuilder(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
@ -76,7 +76,6 @@ public final class OkHttpTelemetryBuilder {
*/
public OkHttpTelemetry build() {
OkHttpAttributesGetter httpAttributesGetter = OkHttpAttributesGetter.INSTANCE;
OkHttpNetAttributesGetter attributesGetter = new OkHttpNetAttributesGetter();
Instrumenter<Request, Response> instrumenter =
Instrumenter.<Request, Response>builder(
@ -85,7 +84,6 @@ public final class OkHttpTelemetryBuilder {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(httpAttributesExtractorBuilder.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(attributesGetter))
.addAttributesExtractors(additionalExtractors)
.addOperationMetrics(HttpClientMetrics.get())
.buildInstrumenter(alwaysClient());

View File

@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import play.shaded.ahc.org.asynchttpclient.Request;
@ -29,11 +28,10 @@ public final class PlayWsClientInstrumenterFactory {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -16,9 +16,8 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.ratpack.internal.RatpackHttpNetAttributesGetter;
import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetAttributesGetter;
import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetClientAttributesGetter;
import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetServerAttributesGetter;
import java.util.ArrayList;
import java.util.List;
import ratpack.http.Request;
@ -37,11 +36,12 @@ public final class RatpackTelemetryBuilder {
new ArrayList<>();
private final HttpClientAttributesExtractorBuilder<RequestSpec, HttpResponse>
httpClientAttributesExtractorBuilder =
HttpClientAttributesExtractor.builder(RatpackHttpClientAttributesGetter.INSTANCE);
HttpClientAttributesExtractor.builder(
RatpackHttpClientAttributesGetter.INSTANCE, new RatpackNetClientAttributesGetter());
private final HttpServerAttributesExtractorBuilder<Request, Response>
httpServerAttributesExtractorBuilder =
HttpServerAttributesExtractor.builder(
RatpackHttpAttributesGetter.INSTANCE, new RatpackNetAttributesGetter());
RatpackHttpAttributesGetter.INSTANCE, new RatpackNetServerAttributesGetter());
private final List<AttributesExtractor<? super RequestSpec, ? super HttpResponse>>
additionalHttpClientExtractors = new ArrayList<>();
@ -129,13 +129,11 @@ public final class RatpackTelemetryBuilder {
}
private Instrumenter<RequestSpec, HttpResponse> httpClientInstrumenter() {
RatpackHttpNetAttributesGetter netAttributes = new RatpackHttpNetAttributesGetter();
RatpackHttpClientAttributesGetter httpAttributes = RatpackHttpClientAttributesGetter.INSTANCE;
return Instrumenter.<RequestSpec, HttpResponse>builder(
openTelemetry, INSTRUMENTATION_NAME, HttpSpanNameExtractor.create(httpAttributes))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributes))
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributes))
.addAttributesExtractor(httpClientAttributesExtractorBuilder.build())
.addAttributesExtractors(additionalHttpClientExtractors)
.addOperationMetrics(HttpServerMetrics.get())

View File

@ -15,7 +15,7 @@ import ratpack.http.client.RequestSpec;
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class RatpackHttpNetAttributesGetter
public final class RatpackNetClientAttributesGetter
implements NetClientAttributesGetter<RequestSpec, HttpResponse> {
@Override

View File

@ -16,7 +16,7 @@ import ratpack.server.PublicAddress;
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class RatpackNetAttributesGetter implements NetServerAttributesGetter<Request> {
public final class RatpackNetServerAttributesGetter implements NetServerAttributesGetter<Request> {
@Override
public String transport(Request request) {
return SemanticAttributes.NetTransportValues.IP_TCP;

View File

@ -12,7 +12,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterFactory;
import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyConnectionInstrumenter;
@ -54,11 +53,10 @@ public final class ReactorNettySingletons {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))

View File

@ -14,7 +14,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import java.util.ArrayList;
import java.util.List;
import org.springframework.http.HttpRequest;
@ -29,7 +28,8 @@ public final class SpringWebTelemetryBuilder {
new ArrayList<>();
private final HttpClientAttributesExtractorBuilder<HttpRequest, ClientHttpResponse>
httpAttributesExtractorBuilder =
HttpClientAttributesExtractor.builder(SpringWebHttpAttributesGetter.INSTANCE);
HttpClientAttributesExtractor.builder(
SpringWebHttpAttributesGetter.INSTANCE, new SpringWebNetAttributesGetter());
SpringWebTelemetryBuilder(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
@ -74,7 +74,6 @@ public final class SpringWebTelemetryBuilder {
*/
public SpringWebTelemetry build() {
SpringWebHttpAttributesGetter httpAttributeGetter = SpringWebHttpAttributesGetter.INSTANCE;
SpringWebNetAttributesGetter netAttributesGetter = new SpringWebNetAttributesGetter();
Instrumenter<HttpRequest, ClientHttpResponse> instrumenter =
Instrumenter.<HttpRequest, ClientHttpResponse>builder(
@ -83,7 +82,6 @@ public final class SpringWebTelemetryBuilder {
HttpSpanNameExtractor.create(httpAttributeGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributeGetter))
.addAttributesExtractor(httpAttributesExtractorBuilder.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractors(additionalExtractors)
.addOperationMetrics(HttpClientMetrics.get())
.buildClientInstrumenter(HttpRequestSetter.INSTANCE);

View File

@ -17,7 +17,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.spring.webflux.client.internal.SpringWebfluxNetAttributesGetter;
import java.util.ArrayList;
import java.util.List;
@ -32,7 +31,8 @@ public final class SpringWebfluxTelemetryBuilder {
new ArrayList<>();
private final HttpClientAttributesExtractorBuilder<ClientRequest, ClientResponse>
httpAttributesExtractorBuilder =
HttpClientAttributesExtractor.builder(SpringWebfluxHttpAttributesGetter.INSTANCE);
HttpClientAttributesExtractor.builder(
SpringWebfluxHttpAttributesGetter.INSTANCE, new SpringWebfluxNetAttributesGetter());
private boolean captureExperimentalSpanAttributes = false;
@ -92,7 +92,6 @@ public final class SpringWebfluxTelemetryBuilder {
public SpringWebfluxTelemetry build() {
SpringWebfluxHttpAttributesGetter httpAttributesGetter =
SpringWebfluxHttpAttributesGetter.INSTANCE;
SpringWebfluxNetAttributesGetter netAttributesGetter = new SpringWebfluxNetAttributesGetter();
InstrumenterBuilder<ClientRequest, ClientResponse> builder =
Instrumenter.<ClientRequest, ClientResponse>builder(
@ -101,7 +100,6 @@ public final class SpringWebfluxTelemetryBuilder {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(httpAttributesExtractorBuilder.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractors(additionalExtractors)
.addOperationMetrics(HttpClientMetrics.get());

View File

@ -250,7 +250,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification {
attributes {
"$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP
"$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com"
"$SemanticAttributes.NET_PEER_PORT.key" 443
"$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_METHOD.key" "POST"
"$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json"
@ -318,7 +317,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification {
attributes {
"$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP
"$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com"
"$SemanticAttributes.NET_PEER_PORT.key" 443
"$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_METHOD.key" "POST"
"$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json"
@ -332,7 +330,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification {
attributes {
"$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP
"$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com"
"$SemanticAttributes.NET_PEER_PORT.key" 443
"$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_METHOD.key" "POST"
"$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json"
@ -407,7 +404,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification {
attributes {
"$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP
"$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com"
"$SemanticAttributes.NET_PEER_PORT.key" 443
"$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_METHOD.key" "POST"
"$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json"
@ -421,7 +417,6 @@ class TwilioClientTest extends AgentInstrumentationSpecification {
attributes {
"$SemanticAttributes.NET_TRANSPORT.key" SemanticAttributes.NetTransportValues.IP_TCP
"$SemanticAttributes.NET_PEER_NAME.key" "api.twilio.com"
"$SemanticAttributes.NET_PEER_PORT.key" 443
"$SemanticAttributes.HTTP_FLAVOR.key" SemanticAttributes.HttpFlavorValues.HTTP_1_1
"$SemanticAttributes.HTTP_METHOD.key" "POST"
"$SemanticAttributes.HTTP_URL.key" "https://api.twilio.com/2010-04-01/Accounts/abc/Messages.json"

View File

@ -0,0 +1,54 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.vertx.v3_0.client;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.net.SocketAddress;
import javax.annotation.Nullable;
enum Vertx3NetAttributesGetter
implements NetClientAttributesGetter<HttpClientRequest, HttpClientResponse> {
INSTANCE;
@Override
public String transport(HttpClientRequest request, @Nullable HttpClientResponse response) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}
@Nullable
@Override
public String peerName(HttpClientRequest request) {
return null;
}
@Override
public Integer peerPort(HttpClientRequest request) {
return null;
}
@Nullable
@Override
public String sockPeerName(HttpClientRequest request, @Nullable HttpClientResponse response) {
if (response == null) {
return null;
}
SocketAddress socketAddress = response.netSocket().remoteAddress();
return socketAddress == null ? null : socketAddress.host();
}
@Nullable
@Override
public Integer sockPeerPort(HttpClientRequest request, @Nullable HttpClientResponse response) {
if (response == null) {
return null;
}
SocketAddress socketAddress = response.netSocket().remoteAddress();
return socketAddress == null ? null : socketAddress.port();
}
}

View File

@ -14,7 +14,9 @@ public final class VertxClientSingletons {
private static final Instrumenter<HttpClientRequest, HttpClientResponse> INSTRUMENTER =
VertxClientInstrumenterFactory.create(
"io.opentelemetry.vertx-http-client-3.0", new Vertx3HttpAttributesGetter(), null);
"io.opentelemetry.vertx-http-client-3.0",
new Vertx3HttpAttributesGetter(),
Vertx3NetAttributesGetter.INSTANCE);
public static Instrumenter<HttpClientRequest, HttpClientResponse> instrumenter() {
return INSTRUMENTER;

View File

@ -5,16 +5,15 @@
package io.opentelemetry.javaagent.instrumentation.vertx.v4_0.client;
import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.net.SocketAddress;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
final class Vertx4NetAttributesGetter
extends InetSocketAddressNetClientAttributesGetter<HttpClientRequest, HttpClientResponse> {
implements NetClientAttributesGetter<HttpClientRequest, HttpClientResponse> {
@Override
public String transport(HttpClientRequest request, @Nullable HttpClientResponse response) {
@ -34,15 +33,31 @@ final class Vertx4NetAttributesGetter
@Nullable
@Override
protected InetSocketAddress getPeerSocketAddress(
HttpClientRequest request, @Nullable HttpClientResponse response) {
public String sockPeerAddr(HttpClientRequest request, @Nullable HttpClientResponse response) {
if (response == null) {
return null;
}
SocketAddress address = response.netSocket().remoteAddress();
if (address instanceof InetSocketAddress) {
return (InetSocketAddress) address;
SocketAddress socketAddress = response.netSocket().remoteAddress();
return socketAddress == null ? null : socketAddress.hostAddress();
}
@Nullable
@Override
public String sockPeerName(HttpClientRequest request, @Nullable HttpClientResponse response) {
if (response == null) {
return null;
}
return null;
SocketAddress socketAddress = response.netSocket().remoteAddress();
return socketAddress == null ? null : socketAddress.host();
}
@Nullable
@Override
public Integer sockPeerPort(HttpClientRequest request, @Nullable HttpClientResponse response) {
if (response == null) {
return null;
}
SocketAddress socketAddress = response.netSocket().remoteAddress();
return socketAddress == null ? null : socketAddress.port();
}
}

View File

@ -12,21 +12,18 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.PeerServiceAttributesExtractor;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpClientResponse;
import javax.annotation.Nullable;
public final class VertxClientInstrumenterFactory {
public static Instrumenter<HttpClientRequest, HttpClientResponse> create(
String instrumentationName,
AbstractVertxHttpAttributesGetter httpAttributesGetter,
@Nullable
NetClientAttributesGetter<HttpClientRequest, HttpClientResponse> netAttributesGetter) {
NetClientAttributesGetter<HttpClientRequest, HttpClientResponse> netAttributesGetter) {
InstrumenterBuilder<HttpClientRequest, HttpClientResponse> builder =
Instrumenter.<HttpClientRequest, HttpClientResponse>builder(
@ -35,20 +32,15 @@ public final class VertxClientInstrumenterFactory {
HttpSpanNameExtractor.create(httpAttributesGetter))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))
.addAttributesExtractor(
HttpClientAttributesExtractor.builder(httpAttributesGetter)
HttpClientAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
.setCapturedRequestHeaders(CommonConfig.get().getClientRequestHeaders())
.setCapturedResponseHeaders(CommonConfig.get().getClientResponseHeaders())
.build())
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get());
if (netAttributesGetter != null) {
builder
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()));
}
return builder.buildClientInstrumenter(new HttpRequestHeaderSetter());
}

View File

@ -934,32 +934,20 @@ public abstract class AbstractHttpClientTest<REQUEST> {
if (attrs.get(SemanticAttributes.NET_TRANSPORT) != null) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP);
}
if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_NAME)) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost());
}
if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_PORT)) {
int uriPort = uri.getPort();
// default values are ignored
if (uriPort <= 0 || uriPort == 80 || uriPort == 443) {
assertThat(attrs).doesNotContainKey(SemanticAttributes.NET_PEER_PORT);
} else {
assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_PORT, uriPort);
}
}
if (uri.getPort() == PortUtils.UNUSABLE_PORT || uri.getHost().equals("192.0.2.1")) {
// TODO: net.peer.name and net.peer.port should always be populated from the URI or
// the Host header, verify these assertions below
if (attrs.get(SemanticAttributes.NET_PEER_NAME) != null) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost());
}
if (attrs.get(SemanticAttributes.NET_PEER_PORT) != null) {
if (uri.getPort() > 0) {
assertThat(attrs)
.containsEntry(SemanticAttributes.NET_PEER_PORT, (long) uri.getPort());
} else {
// https://192.0.2.1/ where some instrumentation may have set this to 443, but
// not all.
assertThat(attrs)
.hasEntrySatisfying(
SemanticAttributes.NET_PEER_PORT,
port -> {
// Some instrumentation seem to set NET_PEER_PORT to -1 incorrectly.
if (port > 0) {
assertThat(port).isEqualTo(options.testHttps ? 443 : 80);
}
});
}
}
// In these cases the peer connection is not established, so the HTTP client should
// not report any socket-level attributes
assertThat(attrs)
@ -970,13 +958,6 @@ public abstract class AbstractHttpClientTest<REQUEST> {
.doesNotContainKey("net.sock.peer.port");
} else {
if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_NAME)) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost());
}
if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_PORT)) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_PORT, uri.getPort());
}
// TODO: Move to test knob rather than always treating as optional
if (attrs.get(SemanticAttributes.NET_SOCK_PEER_ADDR) != null) {
assertThat(attrs)

View File

@ -554,6 +554,7 @@ public abstract class AbstractHttpServerTest<SERVER> {
assertThat(attrs).containsEntry(SemanticAttributes.NET_HOST_NAME, "localhost");
// TODO: Move to test knob rather than always treating as optional
// TODO: once httpAttributes test knob is used, verify default port values
if (attrs.get(SemanticAttributes.NET_HOST_PORT) != null) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_HOST_PORT, port);
}