Implement new stable network semantic conventions (#8616)
This commit is contained in:
parent
40ed895517
commit
506ccb6b7d
|
@ -12,6 +12,7 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
||||||
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||||
import io.opentelemetry.instrumentation.api.internal.SpanKey;
|
import io.opentelemetry.instrumentation.api.internal.SpanKey;
|
||||||
|
@ -53,6 +54,7 @@ public final class HttpClientAttributesExtractor<REQUEST, RESPONSE>
|
||||||
}
|
}
|
||||||
|
|
||||||
private final InternalNetClientAttributesExtractor<REQUEST, RESPONSE> internalNetExtractor;
|
private final InternalNetClientAttributesExtractor<REQUEST, RESPONSE> internalNetExtractor;
|
||||||
|
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalNetworkExtractor;
|
||||||
private final ToIntFunction<Context> resendCountIncrementer;
|
private final ToIntFunction<Context> resendCountIncrementer;
|
||||||
|
|
||||||
HttpClientAttributesExtractor(
|
HttpClientAttributesExtractor(
|
||||||
|
@ -80,7 +82,14 @@ public final class HttpClientAttributesExtractor<REQUEST, RESPONSE>
|
||||||
new InternalNetClientAttributesExtractor<>(
|
new InternalNetClientAttributesExtractor<>(
|
||||||
netAttributesGetter,
|
netAttributesGetter,
|
||||||
this::shouldCapturePeerPort,
|
this::shouldCapturePeerPort,
|
||||||
new HttpNetNamePortGetter<>(httpAttributesGetter));
|
new HttpNetNamePortGetter<>(httpAttributesGetter),
|
||||||
|
SemconvStability.emitOldHttpSemconv());
|
||||||
|
internalNetworkExtractor =
|
||||||
|
new InternalNetworkAttributesExtractor<>(
|
||||||
|
netAttributesGetter,
|
||||||
|
HttpNetworkTransportFilter.INSTANCE,
|
||||||
|
SemconvStability.emitStableHttpSemconv(),
|
||||||
|
SemconvStability.emitOldHttpSemconv());
|
||||||
this.resendCountIncrementer = resendCountIncrementer;
|
this.resendCountIncrementer = resendCountIncrementer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +130,7 @@ public final class HttpClientAttributesExtractor<REQUEST, RESPONSE>
|
||||||
super.onEnd(attributes, context, request, response, error);
|
super.onEnd(attributes, context, request, response, error);
|
||||||
|
|
||||||
internalNetExtractor.onEnd(attributes, request, response);
|
internalNetExtractor.onEnd(attributes, request, response);
|
||||||
|
internalNetworkExtractor.onEnd(attributes, request, response);
|
||||||
|
|
||||||
int resendCount = resendCountIncrementer.applyAsInt(context);
|
int resendCount = resendCountIncrementer.applyAsInt(context);
|
||||||
if (resendCount > 0) {
|
if (resendCount > 0) {
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||||
|
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
enum HttpNetworkTransportFilter implements NetworkTransportFilter {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldAddNetworkTransport(
|
||||||
|
@Nullable String protocolName,
|
||||||
|
@Nullable String protocolVersion,
|
||||||
|
@Nullable String proposedTransport) {
|
||||||
|
// tcp is the default transport for http/1* and http/2*, we're skipping it
|
||||||
|
if ("http".equals(protocolName)
|
||||||
|
&& protocolVersion != null
|
||||||
|
&& (protocolVersion.startsWith("1") || protocolVersion.startsWith("2"))
|
||||||
|
&& "tcp".equals(proposedTransport)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// udp is the default transport for http/3*, we're skipping it
|
||||||
|
if ("http".equals(protocolName)
|
||||||
|
&& protocolVersion != null
|
||||||
|
&& protocolVersion.startsWith("3")
|
||||||
|
&& "udp".equals(proposedTransport)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.InternalUrlAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.InternalUrlAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
|
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
|
||||||
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||||
|
@ -43,7 +44,7 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
/** Creates the HTTP server attributes extractor with default configuration. */
|
/** Creates the HTTP server attributes extractor with default configuration. */
|
||||||
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
|
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
|
||||||
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
||||||
NetServerAttributesGetter<REQUEST> netAttributesGetter) {
|
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
|
||||||
return builder(httpAttributesGetter, netAttributesGetter).build();
|
return builder(httpAttributesGetter, netAttributesGetter).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
*/
|
*/
|
||||||
public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> builder(
|
public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> builder(
|
||||||
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
||||||
NetServerAttributesGetter<REQUEST> netAttributesGetter) {
|
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
|
||||||
return new HttpServerAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter);
|
return new HttpServerAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,12 +65,13 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
"otel.instrumentation.http.prefer-forwarded-url-scheme", false);
|
"otel.instrumentation.http.prefer-forwarded-url-scheme", false);
|
||||||
|
|
||||||
private final InternalUrlAttributesExtractor<REQUEST> internalUrlExtractor;
|
private final InternalUrlAttributesExtractor<REQUEST> internalUrlExtractor;
|
||||||
private final InternalNetServerAttributesExtractor<REQUEST> internalNetExtractor;
|
private final InternalNetServerAttributesExtractor<REQUEST, RESPONSE> internalNetExtractor;
|
||||||
|
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalNetworkExtractor;
|
||||||
private final Function<Context, String> httpRouteHolderGetter;
|
private final Function<Context, String> httpRouteHolderGetter;
|
||||||
|
|
||||||
HttpServerAttributesExtractor(
|
HttpServerAttributesExtractor(
|
||||||
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
||||||
NetServerAttributesGetter<REQUEST> netAttributesGetter,
|
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter,
|
||||||
List<String> capturedRequestHeaders,
|
List<String> capturedRequestHeaders,
|
||||||
List<String> capturedResponseHeaders) {
|
List<String> capturedResponseHeaders) {
|
||||||
this(
|
this(
|
||||||
|
@ -83,7 +85,7 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
// visible for tests
|
// visible for tests
|
||||||
HttpServerAttributesExtractor(
|
HttpServerAttributesExtractor(
|
||||||
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
||||||
NetServerAttributesGetter<REQUEST> netAttributesGetter,
|
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter,
|
||||||
List<String> capturedRequestHeaders,
|
List<String> capturedRequestHeaders,
|
||||||
List<String> capturedResponseHeaders,
|
List<String> capturedResponseHeaders,
|
||||||
Function<Context, String> httpRouteHolderGetter) {
|
Function<Context, String> httpRouteHolderGetter) {
|
||||||
|
@ -98,7 +100,14 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
new InternalNetServerAttributesExtractor<>(
|
new InternalNetServerAttributesExtractor<>(
|
||||||
netAttributesGetter,
|
netAttributesGetter,
|
||||||
this::shouldCaptureHostPort,
|
this::shouldCaptureHostPort,
|
||||||
new HttpNetNamePortGetter<>(httpAttributesGetter));
|
new HttpNetNamePortGetter<>(httpAttributesGetter),
|
||||||
|
SemconvStability.emitOldHttpSemconv());
|
||||||
|
internalNetworkExtractor =
|
||||||
|
new InternalNetworkAttributesExtractor<>(
|
||||||
|
netAttributesGetter,
|
||||||
|
HttpNetworkTransportFilter.INSTANCE,
|
||||||
|
SemconvStability.emitStableHttpSemconv(),
|
||||||
|
SemconvStability.emitOldHttpSemconv());
|
||||||
this.httpRouteHolderGetter = httpRouteHolderGetter;
|
this.httpRouteHolderGetter = httpRouteHolderGetter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +143,9 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
@Nullable Throwable error) {
|
@Nullable Throwable error) {
|
||||||
|
|
||||||
super.onEnd(attributes, context, request, response, error);
|
super.onEnd(attributes, context, request, response, error);
|
||||||
|
|
||||||
|
internalNetworkExtractor.onEnd(attributes, request, response);
|
||||||
|
|
||||||
internalSet(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteHolderGetter.apply(context));
|
internalSet(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteHolderGetter.apply(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,13 @@ import java.util.List;
|
||||||
public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
|
public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
final HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter;
|
final HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter;
|
||||||
final NetServerAttributesGetter<REQUEST> netAttributesGetter;
|
final NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter;
|
||||||
List<String> capturedRequestHeaders = emptyList();
|
List<String> capturedRequestHeaders = emptyList();
|
||||||
List<String> capturedResponseHeaders = emptyList();
|
List<String> capturedResponseHeaders = emptyList();
|
||||||
|
|
||||||
HttpServerAttributesExtractorBuilder(
|
HttpServerAttributesExtractorBuilder(
|
||||||
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
||||||
NetServerAttributesGetter<REQUEST> netAttributesGetter) {
|
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
|
||||||
this.httpAttributesGetter = httpAttributesGetter;
|
this.httpAttributesGetter = httpAttributesGetter;
|
||||||
this.netAttributesGetter = netAttributesGetter;
|
this.netAttributesGetter = netAttributesGetter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ import javax.annotation.Nullable;
|
||||||
* NetServerAttributesGetter#getHostSocketAddress(Object)} methods instead.
|
* NetServerAttributesGetter#getHostSocketAddress(Object)} methods instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class InetSocketAddressNetServerAttributesGetter<REQUEST>
|
public abstract class InetSocketAddressNetServerAttributesGetter<REQUEST, RESPONSE>
|
||||||
implements NetServerAttributesGetter<REQUEST> {
|
implements NetServerAttributesGetter<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,6 +28,19 @@ final class InetSocketAddressUtil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
static String getNetworkType(
|
||||||
|
@Nullable InetSocketAddress address, @Nullable InetSocketAddress otherAddress) {
|
||||||
|
if (address == null) {
|
||||||
|
address = otherAddress;
|
||||||
|
}
|
||||||
|
if (address == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
InetAddress remoteAddress = address.getAddress();
|
||||||
|
return remoteAddress instanceof Inet6Address ? "ipv6" : "ipv4";
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
static String getHostName(@Nullable InetSocketAddress address) {
|
static String getHostName(@Nullable InetSocketAddress address) {
|
||||||
if (address == null) {
|
if (address == null) {
|
||||||
|
|
|
@ -10,6 +10,9 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.FallbackNamePortGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.FallbackNamePortGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetClientAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
|
||||||
|
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +28,7 @@ public final class NetClientAttributesExtractor<REQUEST, RESPONSE>
|
||||||
implements AttributesExtractor<REQUEST, RESPONSE> {
|
implements AttributesExtractor<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
private final InternalNetClientAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
private final InternalNetClientAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
||||||
|
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalNetworkExtractor;
|
||||||
|
|
||||||
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
|
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
|
||||||
NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
|
NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
|
@ -34,7 +38,16 @@ public final class NetClientAttributesExtractor<REQUEST, RESPONSE>
|
||||||
private NetClientAttributesExtractor(NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
|
private NetClientAttributesExtractor(NetClientAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
internalExtractor =
|
internalExtractor =
|
||||||
new InternalNetClientAttributesExtractor<>(
|
new InternalNetClientAttributesExtractor<>(
|
||||||
getter, (port, request) -> true, FallbackNamePortGetter.noop());
|
getter,
|
||||||
|
(port, request) -> true,
|
||||||
|
FallbackNamePortGetter.noop(),
|
||||||
|
SemconvStability.emitOldHttpSemconv());
|
||||||
|
internalNetworkExtractor =
|
||||||
|
new InternalNetworkAttributesExtractor<>(
|
||||||
|
getter,
|
||||||
|
NetworkTransportFilter.alwaysTrue(),
|
||||||
|
SemconvStability.emitStableHttpSemconv(),
|
||||||
|
SemconvStability.emitOldHttpSemconv());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,5 +63,6 @@ public final class NetClientAttributesExtractor<REQUEST, RESPONSE>
|
||||||
@Nullable RESPONSE response,
|
@Nullable RESPONSE response,
|
||||||
@Nullable Throwable error) {
|
@Nullable Throwable error) {
|
||||||
internalExtractor.onEnd(attributes, request, response);
|
internalExtractor.onEnd(attributes, request, response);
|
||||||
|
internalNetworkExtractor.onEnd(attributes, request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||||
|
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -16,7 +17,8 @@ import javax.annotation.Nullable;
|
||||||
* library/framework. It will be used by the NetClientAttributesExtractor to obtain the various
|
* library/framework. It will be used by the NetClientAttributesExtractor to obtain the various
|
||||||
* network attributes in a type-generic way.
|
* network attributes in a type-generic way.
|
||||||
*/
|
*/
|
||||||
public interface NetClientAttributesGetter<REQUEST, RESPONSE> {
|
public interface NetClientAttributesGetter<REQUEST, RESPONSE>
|
||||||
|
extends NetworkAttributesGetter<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
default String getTransport(REQUEST request, @Nullable RESPONSE response) {
|
default String getTransport(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
@ -27,7 +29,11 @@ public interface NetClientAttributesGetter<REQUEST, RESPONSE> {
|
||||||
* Returns the application protocol used.
|
* Returns the application protocol used.
|
||||||
*
|
*
|
||||||
* <p>Examples: `amqp`, `http`, `mqtt`.
|
* <p>Examples: `amqp`, `http`, `mqtt`.
|
||||||
|
*
|
||||||
|
* @deprecated This method is deprecated and will be removed in the following release. Implement
|
||||||
|
* {@link #getNetworkProtocolName(Object, Object)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@Nullable
|
@Nullable
|
||||||
default String getProtocolName(REQUEST request, @Nullable RESPONSE response) {
|
default String getProtocolName(REQUEST request, @Nullable RESPONSE response) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -37,12 +43,37 @@ public interface NetClientAttributesGetter<REQUEST, RESPONSE> {
|
||||||
* Returns the version of the application protocol used.
|
* Returns the version of the application protocol used.
|
||||||
*
|
*
|
||||||
* <p>Examples: `3.1.1`.
|
* <p>Examples: `3.1.1`.
|
||||||
|
*
|
||||||
|
* @deprecated This method is deprecated and will be removed in the following release. Implement
|
||||||
|
* {@link #getNetworkProtocolVersion(Object, Object)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@Nullable
|
@Nullable
|
||||||
default String getProtocolVersion(REQUEST request, @Nullable RESPONSE response) {
|
default String getProtocolVersion(REQUEST request, @Nullable RESPONSE response) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
default String getNetworkType(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return InetSocketAddressUtil.getNetworkType(getPeerSocketAddress(request, response), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
default String getNetworkProtocolName(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return getProtocolName(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
default String getNetworkProtocolVersion(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return getProtocolVersion(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
String getPeerName(REQUEST request);
|
String getPeerName(REQUEST request);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.FallbackNamePortGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.FallbackNamePortGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
|
||||||
|
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,17 +23,27 @@ import javax.annotation.Nullable;
|
||||||
public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
|
public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
implements AttributesExtractor<REQUEST, RESPONSE> {
|
implements AttributesExtractor<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
private final InternalNetServerAttributesExtractor<REQUEST> internalExtractor;
|
|
||||||
|
|
||||||
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
|
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
|
||||||
NetServerAttributesGetter<REQUEST> getter) {
|
NetServerAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
return new NetServerAttributesExtractor<>(getter);
|
return new NetServerAttributesExtractor<>(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetServerAttributesExtractor(NetServerAttributesGetter<REQUEST> getter) {
|
private final InternalNetServerAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
||||||
|
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalNetworkExtractor;
|
||||||
|
|
||||||
|
private NetServerAttributesExtractor(NetServerAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
internalExtractor =
|
internalExtractor =
|
||||||
new InternalNetServerAttributesExtractor<>(
|
new InternalNetServerAttributesExtractor<>(
|
||||||
getter, (integer, request) -> true, FallbackNamePortGetter.noop());
|
getter,
|
||||||
|
(integer, request) -> true,
|
||||||
|
FallbackNamePortGetter.noop(),
|
||||||
|
SemconvStability.emitOldHttpSemconv());
|
||||||
|
internalNetworkExtractor =
|
||||||
|
new InternalNetworkAttributesExtractor<>(
|
||||||
|
getter,
|
||||||
|
NetworkTransportFilter.alwaysTrue(),
|
||||||
|
SemconvStability.emitStableHttpSemconv(),
|
||||||
|
SemconvStability.emitOldHttpSemconv());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,5 +57,7 @@ public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
Context context,
|
Context context,
|
||||||
REQUEST request,
|
REQUEST request,
|
||||||
@Nullable RESPONSE response,
|
@Nullable RESPONSE response,
|
||||||
@Nullable Throwable error) {}
|
@Nullable Throwable error) {
|
||||||
|
internalNetworkExtractor.onEnd(attributes, request, response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||||
|
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -16,7 +17,8 @@ import javax.annotation.Nullable;
|
||||||
* server library/framework. It will be used by the {@link NetServerAttributesExtractor} to obtain
|
* server library/framework. It will be used by the {@link NetServerAttributesExtractor} to obtain
|
||||||
* the various network attributes in a type-generic way.
|
* the various network attributes in a type-generic way.
|
||||||
*/
|
*/
|
||||||
public interface NetServerAttributesGetter<REQUEST> {
|
public interface NetServerAttributesGetter<REQUEST, RESPONSE>
|
||||||
|
extends NetworkAttributesGetter<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
default String getTransport(REQUEST request) {
|
default String getTransport(REQUEST request) {
|
||||||
|
@ -27,7 +29,11 @@ public interface NetServerAttributesGetter<REQUEST> {
|
||||||
* Returns the application protocol used.
|
* Returns the application protocol used.
|
||||||
*
|
*
|
||||||
* <p>Examples: `amqp`, `http`, `mqtt`.
|
* <p>Examples: `amqp`, `http`, `mqtt`.
|
||||||
|
*
|
||||||
|
* @deprecated This method is deprecated and will be removed in the following release. Implement
|
||||||
|
* {@link #getNetworkProtocolName(Object, Object)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@Nullable
|
@Nullable
|
||||||
default String getProtocolName(REQUEST request) {
|
default String getProtocolName(REQUEST request) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -37,12 +43,38 @@ public interface NetServerAttributesGetter<REQUEST> {
|
||||||
* Returns the version of the application protocol used.
|
* Returns the version of the application protocol used.
|
||||||
*
|
*
|
||||||
* <p>Examples: `3.1.1`.
|
* <p>Examples: `3.1.1`.
|
||||||
|
*
|
||||||
|
* @deprecated This method is deprecated and will be removed in the following release. Implement
|
||||||
|
* {@link #getNetworkProtocolVersion(Object, Object)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@Nullable
|
@Nullable
|
||||||
default String getProtocolVersion(REQUEST request) {
|
default String getProtocolVersion(REQUEST request) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
default String getNetworkType(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return InetSocketAddressUtil.getNetworkType(
|
||||||
|
getPeerSocketAddress(request), getHostSocketAddress(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
default String getNetworkProtocolName(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return getProtocolName(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
default String getNetworkProtocolVersion(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return getProtocolVersion(request);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
String getHostName(REQUEST request);
|
String getHostName(REQUEST request);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorU
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -23,14 +22,17 @@ public final class InternalNetClientAttributesExtractor<REQUEST, RESPONSE> {
|
||||||
private final NetClientAttributesGetter<REQUEST, RESPONSE> getter;
|
private final NetClientAttributesGetter<REQUEST, RESPONSE> getter;
|
||||||
private final BiPredicate<Integer, REQUEST> capturePeerPortCondition;
|
private final BiPredicate<Integer, REQUEST> capturePeerPortCondition;
|
||||||
private final FallbackNamePortGetter<REQUEST> fallbackNamePortGetter;
|
private final FallbackNamePortGetter<REQUEST> fallbackNamePortGetter;
|
||||||
|
private final boolean emitOldHttpAttributes;
|
||||||
|
|
||||||
public InternalNetClientAttributesExtractor(
|
public InternalNetClientAttributesExtractor(
|
||||||
NetClientAttributesGetter<REQUEST, RESPONSE> getter,
|
NetClientAttributesGetter<REQUEST, RESPONSE> getter,
|
||||||
BiPredicate<Integer, REQUEST> capturePeerPortCondition,
|
BiPredicate<Integer, REQUEST> capturePeerPortCondition,
|
||||||
FallbackNamePortGetter<REQUEST> fallbackNamePortGetter) {
|
FallbackNamePortGetter<REQUEST> fallbackNamePortGetter,
|
||||||
|
boolean emitOldHttpAttributes) {
|
||||||
this.getter = getter;
|
this.getter = getter;
|
||||||
this.capturePeerPortCondition = capturePeerPortCondition;
|
this.capturePeerPortCondition = capturePeerPortCondition;
|
||||||
this.fallbackNamePortGetter = fallbackNamePortGetter;
|
this.fallbackNamePortGetter = fallbackNamePortGetter;
|
||||||
|
this.emitOldHttpAttributes = emitOldHttpAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStart(AttributesBuilder attributes, REQUEST request) {
|
public void onStart(AttributesBuilder attributes, REQUEST request) {
|
||||||
|
@ -48,17 +50,10 @@ public final class InternalNetClientAttributesExtractor<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) {
|
public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
|
||||||
internalSet(
|
if (emitOldHttpAttributes) {
|
||||||
attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request, response));
|
|
||||||
String protocolName = getter.getProtocolName(request, response);
|
|
||||||
if (protocolName != null) {
|
|
||||||
internalSet(
|
internalSet(
|
||||||
attributes, NetAttributes.NET_PROTOCOL_NAME, protocolName.toLowerCase(Locale.ROOT));
|
attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request, response));
|
||||||
}
|
}
|
||||||
internalSet(
|
|
||||||
attributes,
|
|
||||||
NetAttributes.NET_PROTOCOL_VERSION,
|
|
||||||
getter.getProtocolVersion(request, response));
|
|
||||||
|
|
||||||
String peerName = extractPeerName(request);
|
String peerName = extractPeerName(request);
|
||||||
|
|
||||||
|
@ -72,9 +67,11 @@ public final class InternalNetClientAttributesExtractor<REQUEST, RESPONSE> {
|
||||||
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) sockPeerPort);
|
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) sockPeerPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
String sockFamily = getter.getSockFamily(request, response);
|
if (emitOldHttpAttributes) {
|
||||||
if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) {
|
String sockFamily = getter.getSockFamily(request, response);
|
||||||
internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily);
|
if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) {
|
||||||
|
internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String sockPeerName = getter.getSockPeerName(request, response);
|
String sockPeerName = getter.getSockPeerName(request, response);
|
||||||
|
|
|
@ -10,37 +10,35 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorU
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||||
* any time.
|
* any time.
|
||||||
*/
|
*/
|
||||||
public final class InternalNetServerAttributesExtractor<REQUEST> {
|
public final class InternalNetServerAttributesExtractor<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
private final NetServerAttributesGetter<REQUEST> getter;
|
private final NetServerAttributesGetter<REQUEST, RESPONSE> getter;
|
||||||
private final BiPredicate<Integer, REQUEST> captureHostPortCondition;
|
private final BiPredicate<Integer, REQUEST> captureHostPortCondition;
|
||||||
private final FallbackNamePortGetter<REQUEST> fallbackNamePortGetter;
|
private final FallbackNamePortGetter<REQUEST> fallbackNamePortGetter;
|
||||||
|
private final boolean emitOldHttpAttributes;
|
||||||
|
|
||||||
public InternalNetServerAttributesExtractor(
|
public InternalNetServerAttributesExtractor(
|
||||||
NetServerAttributesGetter<REQUEST> getter,
|
NetServerAttributesGetter<REQUEST, RESPONSE> getter,
|
||||||
BiPredicate<Integer, REQUEST> captureHostPortCondition,
|
BiPredicate<Integer, REQUEST> captureHostPortCondition,
|
||||||
FallbackNamePortGetter<REQUEST> fallbackNamePortGetter) {
|
FallbackNamePortGetter<REQUEST> fallbackNamePortGetter,
|
||||||
|
boolean emitOldHttpAttributes) {
|
||||||
this.getter = getter;
|
this.getter = getter;
|
||||||
this.captureHostPortCondition = captureHostPortCondition;
|
this.captureHostPortCondition = captureHostPortCondition;
|
||||||
this.fallbackNamePortGetter = fallbackNamePortGetter;
|
this.fallbackNamePortGetter = fallbackNamePortGetter;
|
||||||
|
this.emitOldHttpAttributes = emitOldHttpAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStart(AttributesBuilder attributes, REQUEST request) {
|
public void onStart(AttributesBuilder attributes, REQUEST request) {
|
||||||
|
|
||||||
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request));
|
if (emitOldHttpAttributes) {
|
||||||
String protocolName = getter.getProtocolName(request);
|
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.getTransport(request));
|
||||||
if (protocolName != null) {
|
|
||||||
internalSet(
|
|
||||||
attributes, NetAttributes.NET_PROTOCOL_NAME, protocolName.toLowerCase(Locale.ROOT));
|
|
||||||
}
|
}
|
||||||
internalSet(attributes, NetAttributes.NET_PROTOCOL_VERSION, getter.getProtocolVersion(request));
|
|
||||||
|
|
||||||
boolean setSockFamily = false;
|
boolean setSockFamily = false;
|
||||||
|
|
||||||
|
@ -79,7 +77,7 @@ public final class InternalNetServerAttributesExtractor<REQUEST> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setSockFamily) {
|
if (emitOldHttpAttributes && setSockFamily) {
|
||||||
String sockFamily = getter.getSockFamily(request);
|
String sockFamily = getter.getSockFamily(request);
|
||||||
if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) {
|
if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) {
|
||||||
internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily);
|
internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily);
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.network;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
|
import io.opentelemetry.context.Context;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extractor of <a
|
||||||
|
* href="https://github.com/open-telemetry/semantic-conventions/blob/main/specification/trace/semantic_conventions/span-general.md#network-attributes">network
|
||||||
|
* attributes</a>.
|
||||||
|
*/
|
||||||
|
public final class NetworkAttributesExtractor<REQUEST, RESPONSE>
|
||||||
|
implements AttributesExtractor<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link NetworkAttributesExtractor} that will use the passed {@link
|
||||||
|
* NetworkAttributesGetter}.
|
||||||
|
*/
|
||||||
|
public static <REQUEST, RESPONSE> NetworkAttributesExtractor<REQUEST, RESPONSE> create(
|
||||||
|
NetworkAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
|
return new NetworkAttributesExtractor<>(getter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
||||||
|
|
||||||
|
NetworkAttributesExtractor(NetworkAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
|
// the NetworkAttributesExtractor will always emit new semconv
|
||||||
|
internalExtractor =
|
||||||
|
new InternalNetworkAttributesExtractor<>(
|
||||||
|
getter,
|
||||||
|
NetworkTransportFilter.alwaysTrue(),
|
||||||
|
/* emitStableUrlAttributes= */ true,
|
||||||
|
/* emitOldHttpAttributes= */ false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnd(
|
||||||
|
AttributesBuilder attributes,
|
||||||
|
Context context,
|
||||||
|
REQUEST request,
|
||||||
|
@Nullable RESPONSE response,
|
||||||
|
@Nullable Throwable error) {
|
||||||
|
internalExtractor.onEnd(attributes, request, response);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.network;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for getting network attributes.
|
||||||
|
*
|
||||||
|
* <p>Instrumentation authors will create implementations of this interface for their specific
|
||||||
|
* library/framework. It will be used by the {@link NetworkAttributesExtractor} (or other convention
|
||||||
|
* specific extractors) to obtain the various network attributes in a type-generic way.
|
||||||
|
*/
|
||||||
|
public interface NetworkAttributesGetter<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the <a href="https://osi-model.com/transport-layer/">OSI Transport Layer</a> or <a
|
||||||
|
* href="https://en.wikipedia.org/wiki/Inter-process_communication">Inter-process Communication
|
||||||
|
* method</a>.
|
||||||
|
*
|
||||||
|
* <p>Examples: {@code tcp}, {@code udp}
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
default String getNetworkTransport(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the <a href="https://osi-model.com/network-layer/">OSI Network Layer</a> or non-OSI
|
||||||
|
* equivalent.
|
||||||
|
*
|
||||||
|
* <p>Examples: {@code ipv4}, {@code ipv6}
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
default String getNetworkType(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the <a href="https://osi-model.com/application-layer/">OSI Application Layer</a> or
|
||||||
|
* non-OSI equivalent.
|
||||||
|
*
|
||||||
|
* <p>Examples: {@code ampq}, {@code http}, {@code mqtt}
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
default String getNetworkProtocolName(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the version of the application layer protocol used.
|
||||||
|
*
|
||||||
|
* <p>Examples: {@code 3.1.1}
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
default String getNetworkProtocolVersion(REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.network.internal;
|
||||||
|
|
||||||
|
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
|
||||||
|
import java.util.Locale;
|
||||||
|
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 InternalNetworkAttributesExtractor<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
|
private final NetworkAttributesGetter<REQUEST, RESPONSE> getter;
|
||||||
|
private final NetworkTransportFilter networkTransportFilter;
|
||||||
|
private final boolean emitStableUrlAttributes;
|
||||||
|
private final boolean emitOldHttpAttributes;
|
||||||
|
|
||||||
|
public InternalNetworkAttributesExtractor(
|
||||||
|
NetworkAttributesGetter<REQUEST, RESPONSE> getter,
|
||||||
|
NetworkTransportFilter networkTransportFilter,
|
||||||
|
boolean emitStableUrlAttributes,
|
||||||
|
boolean emitOldHttpAttributes) {
|
||||||
|
this.getter = getter;
|
||||||
|
this.networkTransportFilter = networkTransportFilter;
|
||||||
|
this.emitStableUrlAttributes = emitStableUrlAttributes;
|
||||||
|
this.emitOldHttpAttributes = emitOldHttpAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) {
|
||||||
|
String protocolName = lowercase(getter.getNetworkProtocolName(request, response));
|
||||||
|
String protocolVersion = lowercase(getter.getNetworkProtocolVersion(request, response));
|
||||||
|
|
||||||
|
if (emitStableUrlAttributes) {
|
||||||
|
String transport = lowercase(getter.getNetworkTransport(request, response));
|
||||||
|
if (networkTransportFilter.shouldAddNetworkTransport(
|
||||||
|
protocolName, protocolVersion, transport)) {
|
||||||
|
internalSet(attributes, NetworkAttributes.NETWORK_TRANSPORT, transport);
|
||||||
|
}
|
||||||
|
internalSet(
|
||||||
|
attributes,
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
lowercase(getter.getNetworkType(request, response)));
|
||||||
|
internalSet(attributes, NetworkAttributes.NETWORK_PROTOCOL_NAME, protocolName);
|
||||||
|
internalSet(attributes, NetworkAttributes.NETWORK_PROTOCOL_VERSION, protocolVersion);
|
||||||
|
}
|
||||||
|
if (emitOldHttpAttributes) {
|
||||||
|
// net.transport and net.sock.family are not 1:1 convertible with network.transport and
|
||||||
|
// network.type; they must be handled separately in the old net.* extractors
|
||||||
|
internalSet(attributes, NetAttributes.NET_PROTOCOL_NAME, protocolName);
|
||||||
|
internalSet(attributes, NetAttributes.NET_PROTOCOL_VERSION, protocolVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static String lowercase(@Nullable String str) {
|
||||||
|
return str == null ? null : str.toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.network.internal;
|
||||||
|
|
||||||
|
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.AttributeKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||||
|
* any time.
|
||||||
|
*/
|
||||||
|
public final class NetworkAttributes {
|
||||||
|
|
||||||
|
// FIXME: remove this class and replace its usages with SemanticAttributes once schema 1.20 is
|
||||||
|
// released
|
||||||
|
|
||||||
|
public static final AttributeKey<String> NETWORK_TRANSPORT = stringKey("network.transport");
|
||||||
|
|
||||||
|
public static final AttributeKey<String> NETWORK_TYPE = stringKey("network.type");
|
||||||
|
|
||||||
|
public static final AttributeKey<String> NETWORK_PROTOCOL_NAME =
|
||||||
|
stringKey("network.protocol.name");
|
||||||
|
|
||||||
|
public static final AttributeKey<String> NETWORK_PROTOCOL_VERSION =
|
||||||
|
stringKey("network.protocol.version");
|
||||||
|
|
||||||
|
private NetworkAttributes() {}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.network.internal;
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface NetworkTransportFilter {
|
||||||
|
|
||||||
|
boolean shouldAddNetworkTransport(
|
||||||
|
@Nullable String protocolName,
|
||||||
|
@Nullable String protocolVersion,
|
||||||
|
@Nullable String proposedTransport);
|
||||||
|
|
||||||
|
static NetworkTransportFilter alwaysTrue() {
|
||||||
|
return (protocolName, protocolVersion, proposedTransport) -> true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -73,14 +73,28 @@ class HttpClientAttributesExtractorTest {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(
|
public String getNetworkTransport(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
return request.get("protocolName");
|
return request.get("protocolName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
return request.get("protocolVersion");
|
return request.get("protocolVersion");
|
||||||
}
|
}
|
||||||
|
@ -107,6 +121,8 @@ class HttpClientAttributesExtractorTest {
|
||||||
request.put("header.content-length", "10");
|
request.put("header.content-length", "10");
|
||||||
request.put("header.user-agent", "okhttp 3.x");
|
request.put("header.user-agent", "okhttp 3.x");
|
||||||
request.put("header.custom-request-header", "123,456");
|
request.put("header.custom-request-header", "123,456");
|
||||||
|
request.put("transport", "tcp");
|
||||||
|
request.put("type", "ipv4");
|
||||||
request.put("protocolName", "http");
|
request.put("protocolName", "http");
|
||||||
request.put("protocolVersion", "1.1");
|
request.put("protocolVersion", "1.1");
|
||||||
request.put("peerName", "github.com");
|
request.put("peerName", "github.com");
|
||||||
|
|
|
@ -87,17 +87,33 @@ class HttpServerAttributesExtractorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestNetServerAttributesGetter
|
static class TestNetServerAttributesGetter
|
||||||
implements NetServerAttributesGetter<Map<String, Object>> {
|
implements NetServerAttributesGetter<Map<String, Object>, Map<String, Object>> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Map<String, Object> request) {
|
public String getNetworkTransport(
|
||||||
|
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||||
|
return (String) request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||||
|
return (String) request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
|
Map<String, Object> request, Map<String, Object> response) {
|
||||||
return (String) request.get("protocolName");
|
return (String) request.get("protocolName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Map<String, Object> request) {
|
public String getNetworkProtocolVersion(
|
||||||
|
Map<String, Object> request, Map<String, Object> response) {
|
||||||
return (String) request.get("protocolVersion");
|
return (String) request.get("protocolVersion");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +144,8 @@ class HttpServerAttributesExtractorTest {
|
||||||
request.put("header.host", "github.com");
|
request.put("header.host", "github.com");
|
||||||
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
||||||
request.put("header.custom-request-header", "123,456");
|
request.put("header.custom-request-header", "123,456");
|
||||||
|
request.put("transport", "tcp");
|
||||||
|
request.put("type", "ipv4");
|
||||||
request.put("protocolName", "http");
|
request.put("protocolName", "http");
|
||||||
request.put("protocolVersion", "2.0");
|
request.put("protocolVersion", "2.0");
|
||||||
|
|
||||||
|
@ -151,8 +169,6 @@ class HttpServerAttributesExtractorTest {
|
||||||
assertThat(startAttributes.build())
|
assertThat(startAttributes.build())
|
||||||
.containsOnly(
|
.containsOnly(
|
||||||
entry(SemanticAttributes.NET_HOST_NAME, "github.com"),
|
entry(SemanticAttributes.NET_HOST_NAME, "github.com"),
|
||||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
|
||||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
|
||||||
entry(SemanticAttributes.HTTP_METHOD, "POST"),
|
entry(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||||
entry(SemanticAttributes.HTTP_SCHEME, "https"),
|
entry(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||||
entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"),
|
entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"),
|
||||||
|
@ -167,6 +183,8 @@ class HttpServerAttributesExtractorTest {
|
||||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||||
assertThat(endAttributes.build())
|
assertThat(endAttributes.build())
|
||||||
.containsOnly(
|
.containsOnly(
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
||||||
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
|
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
|
||||||
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
|
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
|
||||||
|
|
|
@ -21,7 +21,8 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class InetSocketAddressNetServerAttributesGetterTest {
|
class InetSocketAddressNetServerAttributesGetterTest {
|
||||||
|
|
||||||
static class TestNetServerAttributesGetter implements NetServerAttributesGetter<Addresses> {
|
static class TestNetServerAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<Addresses, Addresses> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHostName(Addresses request) {
|
public String getHostName(Addresses request) {
|
||||||
|
|
|
@ -29,19 +29,33 @@ class NetClientAttributesExtractorTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransport(Map<String, String> request, Map<String, String> response) {
|
public String getTransport(Map<String, String> request, Map<String, String> response) {
|
||||||
return response.get("transport");
|
return response.get("netTransport");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(
|
public String getNetworkTransport(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
return request.get("protocolName");
|
return request.get("protocolName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
return request.get("protocolVersion");
|
return request.get("protocolVersion");
|
||||||
}
|
}
|
||||||
|
@ -86,7 +100,9 @@ class NetClientAttributesExtractorTest {
|
||||||
void normal() {
|
void normal() {
|
||||||
// given
|
// given
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("transport", IP_TCP);
|
map.put("netTransport", IP_TCP);
|
||||||
|
map.put("transport", "tcp");
|
||||||
|
map.put("type", "ipv6");
|
||||||
map.put("protocolName", "http");
|
map.put("protocolName", "http");
|
||||||
map.put("protocolVersion", "1.1");
|
map.put("protocolVersion", "1.1");
|
||||||
map.put("peerName", "opentelemetry.io");
|
map.put("peerName", "opentelemetry.io");
|
||||||
|
@ -144,7 +160,7 @@ class NetClientAttributesExtractorTest {
|
||||||
void doesNotSetDuplicates1() {
|
void doesNotSetDuplicates1() {
|
||||||
// given
|
// given
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("transport", IP_TCP);
|
map.put("netTransport", IP_TCP);
|
||||||
map.put("peerName", "1:2:3:4::");
|
map.put("peerName", "1:2:3:4::");
|
||||||
map.put("peerPort", "42");
|
map.put("peerPort", "42");
|
||||||
map.put("sockFamily", "inet6");
|
map.put("sockFamily", "inet6");
|
||||||
|
@ -176,7 +192,7 @@ class NetClientAttributesExtractorTest {
|
||||||
void doesNotSetDuplicates2() {
|
void doesNotSetDuplicates2() {
|
||||||
// given
|
// given
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("transport", IP_TCP);
|
map.put("netTransport", IP_TCP);
|
||||||
map.put("peerName", "opentelemetry.io");
|
map.put("peerName", "opentelemetry.io");
|
||||||
map.put("peerPort", "42");
|
map.put("peerPort", "42");
|
||||||
map.put("sockFamily", "inet6");
|
map.put("sockFamily", "inet6");
|
||||||
|
|
|
@ -25,22 +25,34 @@ import org.junit.jupiter.api.Test;
|
||||||
class NetServerAttributesExtractorTest {
|
class NetServerAttributesExtractorTest {
|
||||||
|
|
||||||
static class TestNetServerAttributesGetter
|
static class TestNetServerAttributesGetter
|
||||||
implements NetServerAttributesGetter<Map<String, String>> {
|
implements NetServerAttributesGetter<Map<String, String>, Void> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransport(Map<String, String> request) {
|
public String getTransport(Map<String, String> request) {
|
||||||
|
return request.get("netTransport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(Map<String, String> request, @Nullable Void response) {
|
||||||
return request.get("transport");
|
return request.get("transport");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Map<String, String> request) {
|
public String getNetworkType(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(Map<String, String> request, Void response) {
|
||||||
return request.get("protocolName");
|
return request.get("protocolName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Map<String, String> request) {
|
public String getNetworkProtocolVersion(Map<String, String> request, Void response) {
|
||||||
return request.get("protocolVersion");
|
return request.get("protocolVersion");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,14 +100,16 @@ class NetServerAttributesExtractorTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||||
NetServerAttributesExtractor.create(new TestNetServerAttributesGetter());
|
NetServerAttributesExtractor.create(new TestNetServerAttributesGetter());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void normal() {
|
void normal() {
|
||||||
// given
|
// given
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("transport", IP_TCP);
|
map.put("netTransport", IP_TCP);
|
||||||
|
map.put("transport", "tcp");
|
||||||
|
map.put("type", "ipv6");
|
||||||
map.put("protocolName", "http");
|
map.put("protocolName", "http");
|
||||||
map.put("protocolVersion", "1.1");
|
map.put("protocolVersion", "1.1");
|
||||||
map.put("hostName", "opentelemetry.io");
|
map.put("hostName", "opentelemetry.io");
|
||||||
|
@ -113,14 +127,12 @@ class NetServerAttributesExtractorTest {
|
||||||
extractor.onStart(startAttributes, context, map);
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
AttributesBuilder endAttributes = Attributes.builder();
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
extractor.onEnd(endAttributes, context, map, map, null);
|
extractor.onEnd(endAttributes, context, map, null, null);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(startAttributes.build())
|
assertThat(startAttributes.build())
|
||||||
.containsOnly(
|
.containsOnly(
|
||||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
|
||||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
|
||||||
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
|
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
|
||||||
entry(SemanticAttributes.NET_HOST_PORT, 80L),
|
entry(SemanticAttributes.NET_HOST_PORT, 80L),
|
||||||
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
|
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
|
||||||
|
@ -129,7 +141,10 @@ class NetServerAttributesExtractorTest {
|
||||||
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"),
|
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"),
|
||||||
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L));
|
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L));
|
||||||
|
|
||||||
assertThat(endAttributes.build()).isEmpty();
|
assertThat(endAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -142,7 +157,7 @@ class NetServerAttributesExtractorTest {
|
||||||
extractor.onStart(startAttributes, context, emptyMap());
|
extractor.onStart(startAttributes, context, emptyMap());
|
||||||
|
|
||||||
AttributesBuilder endAttributes = Attributes.builder();
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
extractor.onEnd(endAttributes, context, emptyMap(), emptyMap(), null);
|
extractor.onEnd(endAttributes, context, emptyMap(), null, null);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(startAttributes.build()).isEmpty();
|
assertThat(startAttributes.build()).isEmpty();
|
||||||
|
@ -155,7 +170,7 @@ class NetServerAttributesExtractorTest {
|
||||||
void doesNotSetDuplicates1() {
|
void doesNotSetDuplicates1() {
|
||||||
// given
|
// given
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("transport", IP_TCP);
|
map.put("netTransport", IP_TCP);
|
||||||
map.put("hostName", "4:3:2:1::");
|
map.put("hostName", "4:3:2:1::");
|
||||||
map.put("hostPort", "80");
|
map.put("hostPort", "80");
|
||||||
map.put("sockFamily", "inet6");
|
map.put("sockFamily", "inet6");
|
||||||
|
@ -169,7 +184,7 @@ class NetServerAttributesExtractorTest {
|
||||||
extractor.onStart(startAttributes, context, map);
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
AttributesBuilder endAttributes = Attributes.builder();
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
extractor.onEnd(endAttributes, context, map, map, null);
|
extractor.onEnd(endAttributes, context, map, null, null);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(startAttributes.build())
|
assertThat(startAttributes.build())
|
||||||
|
@ -187,7 +202,7 @@ class NetServerAttributesExtractorTest {
|
||||||
void doesNotSetDuplicates2() {
|
void doesNotSetDuplicates2() {
|
||||||
// given
|
// given
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("transport", IP_TCP);
|
map.put("netTransport", IP_TCP);
|
||||||
map.put("hostName", "opentelemetry.io");
|
map.put("hostName", "opentelemetry.io");
|
||||||
map.put("hostPort", "80");
|
map.put("hostPort", "80");
|
||||||
map.put("sockFamily", "inet6");
|
map.put("sockFamily", "inet6");
|
||||||
|
@ -201,7 +216,7 @@ class NetServerAttributesExtractorTest {
|
||||||
extractor.onStart(startAttributes, context, map);
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
AttributesBuilder endAttributes = Attributes.builder();
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
extractor.onEnd(endAttributes, context, map, map, null);
|
extractor.onEnd(endAttributes, context, map, null, null);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(startAttributes.build())
|
assertThat(startAttributes.build())
|
||||||
|
@ -233,7 +248,7 @@ class NetServerAttributesExtractorTest {
|
||||||
extractor.onStart(startAttributes, context, map);
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
AttributesBuilder endAttributes = Attributes.builder();
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
extractor.onEnd(endAttributes, context, map, map, null);
|
extractor.onEnd(endAttributes, context, map, null, null);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(startAttributes.build())
|
assertThat(startAttributes.build())
|
||||||
|
@ -260,7 +275,7 @@ class NetServerAttributesExtractorTest {
|
||||||
extractor.onStart(startAttributes, context, map);
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
AttributesBuilder endAttributes = Attributes.builder();
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
extractor.onEnd(endAttributes, context, map, map, null);
|
extractor.onEnd(endAttributes, context, map, null, null);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(startAttributes.build())
|
assertThat(startAttributes.build())
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.network;
|
||||||
|
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
|
import io.opentelemetry.context.Context;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class NetworkAttributesExtractorTest {
|
||||||
|
|
||||||
|
static class TestNetworkAttributesGetter
|
||||||
|
implements NetworkAttributesGetter<Map<String, String>, Void> {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("protocolName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolVersion(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("protocolVersion");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void allAttributes() {
|
||||||
|
Map<String, String> request = new HashMap<>();
|
||||||
|
request.put("transport", "TcP");
|
||||||
|
request.put("type", "IPv4");
|
||||||
|
request.put("protocolName", "Http");
|
||||||
|
request.put("protocolVersion", "1.1");
|
||||||
|
|
||||||
|
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||||
|
NetworkAttributesExtractor.create(new TestNetworkAttributesGetter());
|
||||||
|
|
||||||
|
AttributesBuilder startAttributes = Attributes.builder();
|
||||||
|
extractor.onStart(startAttributes, Context.root(), request);
|
||||||
|
assertThat(startAttributes.build()).isEmpty();
|
||||||
|
|
||||||
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
|
extractor.onEnd(endAttributes, Context.root(), request, null, null);
|
||||||
|
assertThat(endAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void noAttributes() {
|
||||||
|
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||||
|
NetworkAttributesExtractor.create(new TestNetworkAttributesGetter());
|
||||||
|
|
||||||
|
AttributesBuilder startAttributes = Attributes.builder();
|
||||||
|
extractor.onStart(startAttributes, Context.root(), emptyMap());
|
||||||
|
assertThat(startAttributes.build()).isEmpty();
|
||||||
|
|
||||||
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
|
extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null);
|
||||||
|
assertThat(endAttributes.build()).isEmpty();
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -67,14 +68,28 @@ class HttpClientAttributesExtractorBothSemconvTest {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(
|
public String getNetworkTransport(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
return request.get("protocolName");
|
return request.get("protocolName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
return request.get("protocolVersion");
|
return request.get("protocolVersion");
|
||||||
}
|
}
|
||||||
|
@ -101,6 +116,8 @@ class HttpClientAttributesExtractorBothSemconvTest {
|
||||||
request.put("header.content-length", "10");
|
request.put("header.content-length", "10");
|
||||||
request.put("header.user-agent", "okhttp 3.x");
|
request.put("header.user-agent", "okhttp 3.x");
|
||||||
request.put("header.custom-request-header", "123,456");
|
request.put("header.custom-request-header", "123,456");
|
||||||
|
request.put("transport", "udp");
|
||||||
|
request.put("type", "ipv4");
|
||||||
request.put("protocolName", "http");
|
request.put("protocolName", "http");
|
||||||
request.put("protocolVersion", "1.1");
|
request.put("protocolVersion", "1.1");
|
||||||
request.put("peerName", "github.com");
|
request.put("peerName", "github.com");
|
||||||
|
@ -151,6 +168,10 @@ class HttpClientAttributesExtractorBothSemconvTest {
|
||||||
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
||||||
asList("654", "321")),
|
asList("654", "321")),
|
||||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"));
|
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -80,17 +81,33 @@ class HttpServerAttributesExtractorBothSemconvTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestNetServerAttributesGetter
|
static class TestNetServerAttributesGetter
|
||||||
implements NetServerAttributesGetter<Map<String, Object>> {
|
implements NetServerAttributesGetter<Map<String, Object>, Map<String, Object>> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Map<String, Object> request) {
|
public String getNetworkTransport(
|
||||||
|
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||||
|
return (String) request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||||
|
return (String) request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
|
Map<String, Object> request, Map<String, Object> response) {
|
||||||
return (String) request.get("protocolName");
|
return (String) request.get("protocolName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Map<String, Object> request) {
|
public String getNetworkProtocolVersion(
|
||||||
|
Map<String, Object> request, Map<String, Object> response) {
|
||||||
return (String) request.get("protocolVersion");
|
return (String) request.get("protocolVersion");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +138,8 @@ class HttpServerAttributesExtractorBothSemconvTest {
|
||||||
request.put("header.host", "github.com");
|
request.put("header.host", "github.com");
|
||||||
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
||||||
request.put("header.custom-request-header", "123,456");
|
request.put("header.custom-request-header", "123,456");
|
||||||
|
request.put("transport", "udp");
|
||||||
|
request.put("type", "ipv4");
|
||||||
request.put("protocolName", "http");
|
request.put("protocolName", "http");
|
||||||
request.put("protocolVersion", "2.0");
|
request.put("protocolVersion", "2.0");
|
||||||
|
|
||||||
|
@ -144,8 +163,6 @@ class HttpServerAttributesExtractorBothSemconvTest {
|
||||||
assertThat(startAttributes.build())
|
assertThat(startAttributes.build())
|
||||||
.containsOnly(
|
.containsOnly(
|
||||||
entry(SemanticAttributes.NET_HOST_NAME, "github.com"),
|
entry(SemanticAttributes.NET_HOST_NAME, "github.com"),
|
||||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
|
||||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
|
||||||
entry(SemanticAttributes.HTTP_METHOD, "POST"),
|
entry(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||||
entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"),
|
entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||||
entry(SemanticAttributes.HTTP_SCHEME, "http"),
|
entry(SemanticAttributes.HTTP_SCHEME, "http"),
|
||||||
|
@ -164,6 +181,12 @@ class HttpServerAttributesExtractorBothSemconvTest {
|
||||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||||
assertThat(endAttributes.build())
|
assertThat(endAttributes.build())
|
||||||
.containsOnly(
|
.containsOnly(
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
||||||
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
|
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
|
||||||
entry(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 10L),
|
entry(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 10L),
|
||||||
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||||
|
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||||
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
|
import io.opentelemetry.context.Context;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class NetClientAttributesExtractorBothSemconvTest {
|
||||||
|
|
||||||
|
static class TestNetClientAttributesGetter
|
||||||
|
implements NetClientAttributesGetter<Map<String, String>, Map<String, String>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTransport(Map<String, String> request, Map<String, String> response) {
|
||||||
|
return response.get("netTransport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("protocolName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolVersion(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("protocolVersion");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPeerName(Map<String, String> request) {
|
||||||
|
return request.get("peerName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getPeerPort(Map<String, String> request) {
|
||||||
|
String peerPort = request.get("peerPort");
|
||||||
|
return peerPort == null ? null : Integer.valueOf(peerPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSockFamily(Map<String, String> request, Map<String, String> response) {
|
||||||
|
return response.get("sockFamily");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSockPeerAddr(Map<String, String> request, Map<String, String> response) {
|
||||||
|
return response.get("sockPeerAddr");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSockPeerName(Map<String, String> request, Map<String, String> response) {
|
||||||
|
return response.get("sockPeerName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getSockPeerPort(Map<String, String> request, Map<String, String> response) {
|
||||||
|
String sockPeerPort = response.get("sockPeerPort");
|
||||||
|
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||||
|
NetClientAttributesExtractor.create(new TestNetClientAttributesGetter());
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void normal() {
|
||||||
|
// given
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("netTransport", IP_TCP);
|
||||||
|
map.put("transport", "tcp");
|
||||||
|
map.put("type", "ipv6");
|
||||||
|
map.put("protocolName", "http");
|
||||||
|
map.put("protocolVersion", "1.1");
|
||||||
|
map.put("peerName", "opentelemetry.io");
|
||||||
|
map.put("peerPort", "42");
|
||||||
|
map.put("sockFamily", "inet6");
|
||||||
|
map.put("sockPeerAddr", "1:2:3:4::");
|
||||||
|
map.put("sockPeerName", "proxy.opentelemetry.io");
|
||||||
|
map.put("sockPeerPort", "123");
|
||||||
|
|
||||||
|
Context context = Context.root();
|
||||||
|
|
||||||
|
// when
|
||||||
|
AttributesBuilder startAttributes = Attributes.builder();
|
||||||
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
|
extractor.onEnd(endAttributes, context, map, map, null);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(startAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"),
|
||||||
|
entry(SemanticAttributes.NET_PEER_PORT, 42L));
|
||||||
|
|
||||||
|
assertThat(endAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv6"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||||
|
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||||
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
|
import io.opentelemetry.context.Context;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class NetServerAttributesExtractorBothSemconvTest {
|
||||||
|
|
||||||
|
static class TestNetServerAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<Map<String, String>, Void> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTransport(Map<String, String> request) {
|
||||||
|
return request.get("netTransport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(Map<String, String> request, Void response) {
|
||||||
|
return request.get("protocolName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolVersion(Map<String, String> request, Void response) {
|
||||||
|
return request.get("protocolVersion");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getHostName(Map<String, String> request) {
|
||||||
|
return request.get("hostName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Integer getHostPort(Map<String, String> request) {
|
||||||
|
String hostPort = request.get("hostPort");
|
||||||
|
return hostPort == null ? null : Integer.valueOf(hostPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getSockFamily(Map<String, String> request) {
|
||||||
|
return request.get("sockFamily");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSockPeerAddr(Map<String, String> request) {
|
||||||
|
return request.get("sockPeerAddr");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getSockPeerPort(Map<String, String> request) {
|
||||||
|
String sockPeerPort = request.get("sockPeerPort");
|
||||||
|
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getSockHostAddr(Map<String, String> request) {
|
||||||
|
return request.get("sockHostAddr");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Integer getSockHostPort(Map<String, String> request) {
|
||||||
|
String sockHostPort = request.get("sockHostPort");
|
||||||
|
return sockHostPort == null ? null : Integer.valueOf(sockHostPort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||||
|
NetServerAttributesExtractor.create(new TestNetServerAttributesGetter());
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void normal() {
|
||||||
|
// given
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("netTransport", IP_TCP);
|
||||||
|
map.put("transport", "tcp");
|
||||||
|
map.put("type", "ipv6");
|
||||||
|
map.put("protocolName", "http");
|
||||||
|
map.put("protocolVersion", "1.1");
|
||||||
|
map.put("hostName", "opentelemetry.io");
|
||||||
|
map.put("hostPort", "80");
|
||||||
|
map.put("sockFamily", "inet6");
|
||||||
|
map.put("sockPeerAddr", "1:2:3:4::");
|
||||||
|
map.put("sockPeerPort", "42");
|
||||||
|
map.put("sockHostAddr", "4:3:2:1::");
|
||||||
|
map.put("sockHostPort", "8080");
|
||||||
|
|
||||||
|
Context context = Context.root();
|
||||||
|
|
||||||
|
// when
|
||||||
|
AttributesBuilder startAttributes = Attributes.builder();
|
||||||
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
|
extractor.onEnd(endAttributes, context, map, null, null);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(startAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||||
|
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
|
||||||
|
entry(SemanticAttributes.NET_HOST_PORT, 80L),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L));
|
||||||
|
|
||||||
|
assertThat(endAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv6"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,8 +8,10 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static org.assertj.core.api.Assertions.entry;
|
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.AttributeKey;
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
@ -17,15 +19,21 @@ import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.ToIntFunction;
|
import java.util.function.ToIntFunction;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.junit.jupiter.api.Test;
|
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 HttpClientAttributesExtractorStableSemconvTest {
|
class HttpClientAttributesExtractorStableSemconvTest {
|
||||||
|
|
||||||
|
@ -51,7 +59,8 @@ class HttpClientAttributesExtractorStableSemconvTest {
|
||||||
@Override
|
@Override
|
||||||
public Integer getHttpResponseStatusCode(
|
public Integer getHttpResponseStatusCode(
|
||||||
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
|
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
|
||||||
return Integer.parseInt(response.get("statusCode"));
|
String value = response.get("statusCode");
|
||||||
|
return value == null ? null : Integer.parseInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,14 +76,28 @@ class HttpClientAttributesExtractorStableSemconvTest {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(
|
public String getNetworkTransport(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
return request.get("protocolName");
|
return request.get("protocolName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
return request.get("protocolVersion");
|
return request.get("protocolVersion");
|
||||||
}
|
}
|
||||||
|
@ -88,8 +111,8 @@ class HttpClientAttributesExtractorStableSemconvTest {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Integer getPeerPort(Map<String, String> request) {
|
public Integer getPeerPort(Map<String, String> request) {
|
||||||
String statusCode = request.get("peerPort");
|
String value = request.get("peerPort");
|
||||||
return statusCode == null ? null : Integer.parseInt(statusCode);
|
return value == null ? null : Integer.parseInt(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +124,8 @@ class HttpClientAttributesExtractorStableSemconvTest {
|
||||||
request.put("header.content-length", "10");
|
request.put("header.content-length", "10");
|
||||||
request.put("header.user-agent", "okhttp 3.x");
|
request.put("header.user-agent", "okhttp 3.x");
|
||||||
request.put("header.custom-request-header", "123,456");
|
request.put("header.custom-request-header", "123,456");
|
||||||
|
request.put("transport", "udp");
|
||||||
|
request.put("type", "ipv4");
|
||||||
request.put("protocolName", "http");
|
request.put("protocolName", "http");
|
||||||
request.put("protocolVersion", "1.1");
|
request.put("protocolVersion", "1.1");
|
||||||
request.put("peerName", "github.com");
|
request.put("peerName", "github.com");
|
||||||
|
@ -145,7 +170,53 @@ class HttpClientAttributesExtractorStableSemconvTest {
|
||||||
entry(
|
entry(
|
||||||
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
||||||
asList("654", "321")),
|
asList("654", "321")),
|
||||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"),
|
||||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "1.1"));
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ArgumentsSource(NetworkTransportAndProtocolProvider.class)
|
||||||
|
void skipNetworkTransportIfDefaultForProtocol(
|
||||||
|
String observedProtocolName,
|
||||||
|
String observedProtocolVersion,
|
||||||
|
String observedTransport,
|
||||||
|
@Nullable String extractedTransport) {
|
||||||
|
Map<String, String> request = new HashMap<>();
|
||||||
|
request.put("protocolName", observedProtocolName);
|
||||||
|
request.put("protocolVersion", observedProtocolVersion);
|
||||||
|
request.put("transport", observedTransport);
|
||||||
|
|
||||||
|
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||||
|
HttpClientAttributesExtractor.create(
|
||||||
|
new TestHttpClientAttributesGetter(), new TestNetClientAttributesGetter());
|
||||||
|
|
||||||
|
AttributesBuilder attributes = Attributes.builder();
|
||||||
|
extractor.onStart(attributes, Context.root(), request);
|
||||||
|
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||||
|
|
||||||
|
if (extractedTransport != null) {
|
||||||
|
assertThat(attributes.build())
|
||||||
|
.containsEntry(NetworkAttributes.NETWORK_TRANSPORT, extractedTransport);
|
||||||
|
} else {
|
||||||
|
assertThat(attributes.build()).doesNotContainKey(NetworkAttributes.NETWORK_TRANSPORT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class NetworkTransportAndProtocolProvider implements ArgumentsProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
|
||||||
|
return Stream.of(
|
||||||
|
arguments("http", "1.0", "tcp", null),
|
||||||
|
arguments("http", "1.1", "tcp", null),
|
||||||
|
arguments("http", "2.0", "tcp", null),
|
||||||
|
arguments("http", "3.0", "udp", null),
|
||||||
|
arguments("http", "1.1", "udp", "udp"),
|
||||||
|
arguments("ftp", "2.0", "tcp", "tcp"),
|
||||||
|
arguments("http", "3.0", "tcp", "tcp"),
|
||||||
|
arguments("http", "42", "tcp", "tcp"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,23 +8,32 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static org.assertj.core.api.Assertions.entry;
|
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.AttributeKey;
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.junit.jupiter.api.Test;
|
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 HttpServerAttributesExtractorStableSemconvTest {
|
class HttpServerAttributesExtractorStableSemconvTest {
|
||||||
|
|
||||||
|
@ -80,17 +89,33 @@ class HttpServerAttributesExtractorStableSemconvTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestNetServerAttributesGetter
|
static class TestNetServerAttributesGetter
|
||||||
implements NetServerAttributesGetter<Map<String, Object>> {
|
implements NetServerAttributesGetter<Map<String, Object>, Map<String, Object>> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Map<String, Object> request) {
|
public String getNetworkTransport(
|
||||||
|
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||||
|
return (String) request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||||
|
return (String) request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
|
Map<String, Object> request, Map<String, Object> response) {
|
||||||
return (String) request.get("protocolName");
|
return (String) request.get("protocolName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Map<String, Object> request) {
|
public String getNetworkProtocolVersion(
|
||||||
|
Map<String, Object> request, Map<String, Object> response) {
|
||||||
return (String) request.get("protocolVersion");
|
return (String) request.get("protocolVersion");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +146,8 @@ class HttpServerAttributesExtractorStableSemconvTest {
|
||||||
request.put("header.host", "github.com");
|
request.put("header.host", "github.com");
|
||||||
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
||||||
request.put("header.custom-request-header", "123,456");
|
request.put("header.custom-request-header", "123,456");
|
||||||
|
request.put("transport", "udp");
|
||||||
|
request.put("type", "ipv4");
|
||||||
request.put("protocolName", "http");
|
request.put("protocolName", "http");
|
||||||
request.put("protocolVersion", "2.0");
|
request.put("protocolVersion", "2.0");
|
||||||
|
|
||||||
|
@ -144,8 +171,6 @@ class HttpServerAttributesExtractorStableSemconvTest {
|
||||||
assertThat(startAttributes.build())
|
assertThat(startAttributes.build())
|
||||||
.containsOnly(
|
.containsOnly(
|
||||||
entry(SemanticAttributes.NET_HOST_NAME, "github.com"),
|
entry(SemanticAttributes.NET_HOST_NAME, "github.com"),
|
||||||
entry(NetAttributes.NET_PROTOCOL_NAME, "http"),
|
|
||||||
entry(NetAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
|
||||||
entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"),
|
entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||||
entry(UrlAttributes.URL_SCHEME, "http"),
|
entry(UrlAttributes.URL_SCHEME, "http"),
|
||||||
entry(UrlAttributes.URL_PATH, "/repositories/1"),
|
entry(UrlAttributes.URL_PATH, "/repositories/1"),
|
||||||
|
@ -161,6 +186,10 @@ class HttpServerAttributesExtractorStableSemconvTest {
|
||||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||||
assertThat(endAttributes.build())
|
assertThat(endAttributes.build())
|
||||||
.containsOnly(
|
.containsOnly(
|
||||||
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
||||||
entry(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 10L),
|
entry(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 10L),
|
||||||
entry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
|
entry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
|
||||||
|
@ -169,4 +198,49 @@ class HttpServerAttributesExtractorStableSemconvTest {
|
||||||
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
||||||
asList("654", "321")));
|
asList("654", "321")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ArgumentsSource(NetworkTransportAndProtocolProvider.class)
|
||||||
|
void skipNetworkTransportIfDefaultForProtocol(
|
||||||
|
String observedProtocolName,
|
||||||
|
String observedProtocolVersion,
|
||||||
|
String observedTransport,
|
||||||
|
@Nullable String extractedTransport) {
|
||||||
|
Map<String, String> request = new HashMap<>();
|
||||||
|
request.put("protocolName", observedProtocolName);
|
||||||
|
request.put("protocolVersion", observedProtocolVersion);
|
||||||
|
request.put("transport", observedTransport);
|
||||||
|
|
||||||
|
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||||
|
HttpClientAttributesExtractor.create(
|
||||||
|
new HttpClientAttributesExtractorStableSemconvTest.TestHttpClientAttributesGetter(),
|
||||||
|
new HttpClientAttributesExtractorStableSemconvTest.TestNetClientAttributesGetter());
|
||||||
|
|
||||||
|
AttributesBuilder attributes = Attributes.builder();
|
||||||
|
extractor.onStart(attributes, Context.root(), request);
|
||||||
|
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||||
|
|
||||||
|
if (extractedTransport != null) {
|
||||||
|
assertThat(attributes.build())
|
||||||
|
.containsEntry(NetworkAttributes.NETWORK_TRANSPORT, extractedTransport);
|
||||||
|
} else {
|
||||||
|
assertThat(attributes.build()).doesNotContainKey(NetworkAttributes.NETWORK_TRANSPORT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class NetworkTransportAndProtocolProvider implements ArgumentsProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
|
||||||
|
return Stream.of(
|
||||||
|
arguments("http", "1.0", "tcp", null),
|
||||||
|
arguments("http", "1.1", "tcp", null),
|
||||||
|
arguments("http", "2.0", "tcp", null),
|
||||||
|
arguments("http", "3.0", "udp", null),
|
||||||
|
arguments("http", "1.1", "udp", "udp"),
|
||||||
|
arguments("ftp", "2.0", "tcp", "tcp"),
|
||||||
|
arguments("http", "3.0", "tcp", "tcp"),
|
||||||
|
arguments("http", "42", "tcp", "tcp"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||||
|
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||||
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
|
import io.opentelemetry.context.Context;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class NetClientAttributesExtractorStableSemconvTest {
|
||||||
|
|
||||||
|
static class TestNetClientAttributesGetter
|
||||||
|
implements NetClientAttributesGetter<Map<String, String>, Map<String, String>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTransport(Map<String, String> request, Map<String, String> response) {
|
||||||
|
return response.get("netTransport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("protocolName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolVersion(
|
||||||
|
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||||
|
return request.get("protocolVersion");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPeerName(Map<String, String> request) {
|
||||||
|
return request.get("peerName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getPeerPort(Map<String, String> request) {
|
||||||
|
String peerPort = request.get("peerPort");
|
||||||
|
return peerPort == null ? null : Integer.valueOf(peerPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSockFamily(Map<String, String> request, Map<String, String> response) {
|
||||||
|
return response.get("sockFamily");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSockPeerAddr(Map<String, String> request, Map<String, String> response) {
|
||||||
|
return response.get("sockPeerAddr");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSockPeerName(Map<String, String> request, Map<String, String> response) {
|
||||||
|
return response.get("sockPeerName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getSockPeerPort(Map<String, String> request, Map<String, String> response) {
|
||||||
|
String sockPeerPort = response.get("sockPeerPort");
|
||||||
|
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||||
|
NetClientAttributesExtractor.create(new TestNetClientAttributesGetter());
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void normal() {
|
||||||
|
// given
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("netTransport", IP_TCP);
|
||||||
|
map.put("transport", "tcp");
|
||||||
|
map.put("type", "ipv6");
|
||||||
|
map.put("protocolName", "http");
|
||||||
|
map.put("protocolVersion", "1.1");
|
||||||
|
map.put("peerName", "opentelemetry.io");
|
||||||
|
map.put("peerPort", "42");
|
||||||
|
map.put("sockFamily", "inet6");
|
||||||
|
map.put("sockPeerAddr", "1:2:3:4::");
|
||||||
|
map.put("sockPeerName", "proxy.opentelemetry.io");
|
||||||
|
map.put("sockPeerPort", "123");
|
||||||
|
|
||||||
|
Context context = Context.root();
|
||||||
|
|
||||||
|
// when
|
||||||
|
AttributesBuilder startAttributes = Attributes.builder();
|
||||||
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
|
extractor.onEnd(endAttributes, context, map, map, null);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(startAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"),
|
||||||
|
entry(SemanticAttributes.NET_PEER_PORT, 42L));
|
||||||
|
|
||||||
|
assertThat(endAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv6"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,147 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||||
|
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||||
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||||
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
|
import io.opentelemetry.context.Context;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||||
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class NetServerAttributesExtractorStableSemconvTest {
|
||||||
|
|
||||||
|
static class TestNetServerAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<Map<String, String>, Void> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTransport(Map<String, String> request) {
|
||||||
|
return request.get("netTransport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkType(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(Map<String, String> request, Void response) {
|
||||||
|
return request.get("protocolName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolVersion(Map<String, String> request, Void response) {
|
||||||
|
return request.get("protocolVersion");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getHostName(Map<String, String> request) {
|
||||||
|
return request.get("hostName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Integer getHostPort(Map<String, String> request) {
|
||||||
|
String hostPort = request.get("hostPort");
|
||||||
|
return hostPort == null ? null : Integer.valueOf(hostPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getSockFamily(Map<String, String> request) {
|
||||||
|
return request.get("sockFamily");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSockPeerAddr(Map<String, String> request) {
|
||||||
|
return request.get("sockPeerAddr");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getSockPeerPort(Map<String, String> request) {
|
||||||
|
String sockPeerPort = request.get("sockPeerPort");
|
||||||
|
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getSockHostAddr(Map<String, String> request) {
|
||||||
|
return request.get("sockHostAddr");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Integer getSockHostPort(Map<String, String> request) {
|
||||||
|
String sockHostPort = request.get("sockHostPort");
|
||||||
|
return sockHostPort == null ? null : Integer.valueOf(sockHostPort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||||
|
NetServerAttributesExtractor.create(new TestNetServerAttributesGetter());
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void normal() {
|
||||||
|
// given
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("netTransport", IP_TCP);
|
||||||
|
map.put("transport", "tcp");
|
||||||
|
map.put("type", "ipv6");
|
||||||
|
map.put("protocolName", "http");
|
||||||
|
map.put("protocolVersion", "1.1");
|
||||||
|
map.put("hostName", "opentelemetry.io");
|
||||||
|
map.put("hostPort", "80");
|
||||||
|
map.put("sockFamily", "inet6");
|
||||||
|
map.put("sockPeerAddr", "1:2:3:4::");
|
||||||
|
map.put("sockPeerPort", "42");
|
||||||
|
map.put("sockHostAddr", "4:3:2:1::");
|
||||||
|
map.put("sockHostPort", "8080");
|
||||||
|
|
||||||
|
Context context = Context.root();
|
||||||
|
|
||||||
|
// when
|
||||||
|
AttributesBuilder startAttributes = Attributes.builder();
|
||||||
|
extractor.onStart(startAttributes, context, map);
|
||||||
|
|
||||||
|
AttributesBuilder endAttributes = Attributes.builder();
|
||||||
|
extractor.onEnd(endAttributes, context, map, null, null);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(startAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
|
||||||
|
entry(SemanticAttributes.NET_HOST_PORT, 80L),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L));
|
||||||
|
|
||||||
|
assertThat(endAttributes.build())
|
||||||
|
.containsOnly(
|
||||||
|
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||||
|
entry(NetworkAttributes.NETWORK_TYPE, "ipv6"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||||
|
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -95,13 +95,13 @@ public class InstrumenterBenchmark {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Void unused, @Nullable Void unused2) {
|
public String getNetworkProtocolName(Void unused, @Nullable Void unused2) {
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Void unused, @Nullable Void unused2) {
|
public String getNetworkProtocolVersion(Void unused, @Nullable Void unused2) {
|
||||||
return "2.0";
|
return "2.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,15 @@ class AkkaHttpNetAttributesGetter implements NetClientAttributesGetter<HttpReque
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
|
public String getNetworkProtocolName(
|
||||||
|
HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
|
||||||
return AkkaHttpUtil.protocolName(httpRequest);
|
return AkkaHttpUtil.protocolName(httpRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
|
public String getNetworkProtocolVersion(
|
||||||
|
HttpRequest httpRequest, @Nullable HttpResponse httpResponse) {
|
||||||
return AkkaHttpUtil.protocolVersion(httpRequest);
|
return AkkaHttpUtil.protocolVersion(httpRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,34 +6,37 @@
|
||||||
package io.opentelemetry.javaagent.instrumentation.akkahttp.server;
|
package io.opentelemetry.javaagent.instrumentation.akkahttp.server;
|
||||||
|
|
||||||
import akka.http.scaladsl.model.HttpRequest;
|
import akka.http.scaladsl.model.HttpRequest;
|
||||||
|
import akka.http.scaladsl.model.HttpResponse;
|
||||||
|
import akka.http.scaladsl.model.Uri;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil;
|
import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
// TODO (trask) capture net attributes?
|
class AkkaNetServerAttributesGetter
|
||||||
class AkkaNetServerAttributesGetter implements NetServerAttributesGetter<HttpRequest> {
|
implements NetServerAttributesGetter<HttpRequest, HttpResponse> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpRequest request) {
|
public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse httpResponse) {
|
||||||
return AkkaHttpUtil.protocolName(request);
|
return AkkaHttpUtil.protocolName(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpRequest request) {
|
public String getNetworkProtocolVersion(
|
||||||
|
HttpRequest request, @Nullable HttpResponse httpResponse) {
|
||||||
return AkkaHttpUtil.protocolVersion(request);
|
return AkkaHttpUtil.protocolVersion(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getHostName(HttpRequest request) {
|
public String getHostName(HttpRequest request) {
|
||||||
return null;
|
Uri.Host host = request.uri().authority().host();
|
||||||
|
return host.isEmpty() ? null : host.address();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getHostPort(HttpRequest request) {
|
public Integer getHostPort(HttpRequest request) {
|
||||||
return null;
|
return request.uri().authority().port();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,14 @@ import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import org.apache.dubbo.rpc.Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||||
* any time.
|
* any time.
|
||||||
*/
|
*/
|
||||||
public final class DubboNetServerAttributesGetter
|
public final class DubboNetServerAttributesGetter
|
||||||
implements NetServerAttributesGetter<DubboRequest> {
|
implements NetServerAttributesGetter<DubboRequest, Result> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -14,12 +14,13 @@ final class ApacheHttpAsyncClientNetAttributesGetter
|
||||||
implements NetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {
|
implements NetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
public String getNetworkProtocolName(
|
||||||
|
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||||
return request.getProtocolName();
|
return request.getProtocolName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||||
return request.getProtocolVersion();
|
return request.getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@ final class ApacheHttpClientNetAttributesGetter
|
||||||
implements NetClientAttributesGetter<HttpMethod, HttpMethod> {
|
implements NetClientAttributesGetter<HttpMethod, HttpMethod> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpMethod request, @Nullable HttpMethod response) {
|
public String getNetworkProtocolName(HttpMethod request, @Nullable HttpMethod response) {
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpMethod request, @Nullable HttpMethod response) {
|
public String getNetworkProtocolVersion(HttpMethod request, @Nullable HttpMethod response) {
|
||||||
if (request instanceof HttpMethodBase) {
|
if (request instanceof HttpMethodBase) {
|
||||||
return ((HttpMethodBase) request).isHttp11() ? "1.1" : "1.0";
|
return ((HttpMethodBase) request).isHttp11() ? "1.1" : "1.0";
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,13 @@ final class ApacheHttpClientNetAttributesGetter
|
||||||
implements NetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {
|
implements NetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
public String getNetworkProtocolName(
|
||||||
|
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||||
return request.getProtocolName();
|
return request.getProtocolName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||||
return request.getProtocolVersion();
|
return request.getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,13 @@ final class ApacheHttpClientNetAttributesGetter
|
||||||
implements NetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {
|
implements NetClientAttributesGetter<ApacheHttpClientRequest, HttpResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
public String getNetworkProtocolName(
|
||||||
|
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||||
return request.getProtocolName();
|
return request.getProtocolName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
ApacheHttpClientRequest request, @Nullable HttpResponse response) {
|
||||||
return request.getProtocolVersion();
|
return request.getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ final class ApacheHttpClientNetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpRequest request, @Nullable HttpResponse response) {
|
public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse response) {
|
||||||
ProtocolVersion protocolVersion = getVersion(request, response);
|
ProtocolVersion protocolVersion = getVersion(request, response);
|
||||||
if (protocolVersion == null) {
|
if (protocolVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -26,7 +26,7 @@ final class ApacheHttpClientNetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse response) {
|
public String getNetworkProtocolVersion(HttpRequest request, @Nullable HttpResponse response) {
|
||||||
ProtocolVersion protocolVersion = getVersion(request, response);
|
ProtocolVersion protocolVersion = getVersion(request, response);
|
||||||
if (protocolVersion == null) {
|
if (protocolVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -7,20 +7,22 @@ package io.opentelemetry.instrumentation.armeria.v1_3;
|
||||||
|
|
||||||
import com.linecorp.armeria.common.RequestContext;
|
import com.linecorp.armeria.common.RequestContext;
|
||||||
import com.linecorp.armeria.common.SessionProtocol;
|
import com.linecorp.armeria.common.SessionProtocol;
|
||||||
|
import com.linecorp.armeria.common.logging.RequestLog;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
final class ArmeriaNetServerAttributesGetter implements NetServerAttributesGetter<RequestContext> {
|
final class ArmeriaNetServerAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<RequestContext, RequestLog> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(RequestContext ctx) {
|
public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) {
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(RequestContext ctx) {
|
public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) {
|
||||||
SessionProtocol protocol = ctx.sessionProtocol();
|
SessionProtocol protocol = ctx.sessionProtocol();
|
||||||
return protocol.isMultiplex() ? "2.0" : "1.1";
|
return protocol.isMultiplex() ? "2.0" : "1.1";
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,12 @@ public final class ArmeriaNetClientAttributesGetter
|
||||||
implements NetClientAttributesGetter<RequestContext, RequestLog> {
|
implements NetClientAttributesGetter<RequestContext, RequestLog> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) {
|
public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) {
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) {
|
public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) {
|
||||||
SessionProtocol protocol = ctx.sessionProtocol();
|
SessionProtocol protocol = ctx.sessionProtocol();
|
||||||
return protocol.isMultiplex() ? "2.0" : "1.1";
|
return protocol.isMultiplex() ? "2.0" : "1.1";
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@ final class AsyncHttpClientNetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request request, @Nullable Response response) {
|
public String getNetworkProtocolName(Request request, @Nullable Response response) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request request, @Nullable Response response) {
|
public String getNetworkProtocolVersion(Request request, @Nullable Response response) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ final class AsyncHttpClientNetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(RequestContext request, @Nullable Response response) {
|
public String getNetworkProtocolName(RequestContext request, @Nullable Response response) {
|
||||||
HttpVersion httpVersion = getHttpVersion(request);
|
HttpVersion httpVersion = getHttpVersion(request);
|
||||||
if (httpVersion == null) {
|
if (httpVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -28,7 +28,7 @@ final class AsyncHttpClientNetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(RequestContext request, @Nullable Response response) {
|
public String getNetworkProtocolVersion(RequestContext request, @Nullable Response response) {
|
||||||
HttpVersion httpVersion = getHttpVersion(request);
|
HttpVersion httpVersion = getHttpVersion(request);
|
||||||
if (httpVersion == null) {
|
if (httpVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -17,7 +17,7 @@ class AwsSdkNetAttributesGetter implements NetClientAttributesGetter<Request<?>,
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request<?> request, @Nullable Response<?> response) {
|
public String getNetworkProtocolName(Request<?> request, @Nullable Response<?> response) {
|
||||||
ProtocolVersion protocolVersion = getProtocolVersion(response);
|
ProtocolVersion protocolVersion = getProtocolVersion(response);
|
||||||
if (protocolVersion == null) {
|
if (protocolVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -27,7 +27,7 @@ class AwsSdkNetAttributesGetter implements NetClientAttributesGetter<Request<?>,
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request<?> request, @Nullable Response<?> response) {
|
public String getNetworkProtocolVersion(Request<?> request, @Nullable Response<?> response) {
|
||||||
ProtocolVersion protocolVersion = getProtocolVersion(response);
|
ProtocolVersion protocolVersion = getProtocolVersion(response);
|
||||||
if (protocolVersion == null) {
|
if (protocolVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -12,17 +12,20 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.glassfish.grizzly.Transport;
|
import org.glassfish.grizzly.Transport;
|
||||||
import org.glassfish.grizzly.http.HttpRequestPacket;
|
import org.glassfish.grizzly.http.HttpRequestPacket;
|
||||||
|
import org.glassfish.grizzly.http.HttpResponsePacket;
|
||||||
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
|
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
|
||||||
import org.glassfish.grizzly.nio.transport.UDPNIOTransport;
|
import org.glassfish.grizzly.nio.transport.UDPNIOTransport;
|
||||||
|
|
||||||
final class GrizzlyNetAttributesGetter implements NetServerAttributesGetter<HttpRequestPacket> {
|
final class GrizzlyNetAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<HttpRequestPacket, HttpResponsePacket> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransport(HttpRequestPacket request) {
|
public String getTransport(HttpRequestPacket request) {
|
||||||
Transport transport = request.getConnection().getTransport();
|
Transport transport = request.getConnection().getTransport();
|
||||||
if (transport instanceof TCPNIOTransport) {
|
if (transport instanceof TCPNIOTransport) {
|
||||||
return IP_TCP;
|
return IP_TCP;
|
||||||
} else if (transport instanceof UDPNIOTransport) {
|
}
|
||||||
|
if (transport instanceof UDPNIOTransport) {
|
||||||
return IP_UDP;
|
return IP_UDP;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -30,7 +33,21 @@ final class GrizzlyNetAttributesGetter implements NetServerAttributesGetter<Http
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpRequestPacket request) {
|
public String getNetworkTransport(
|
||||||
|
HttpRequestPacket request, @Nullable HttpResponsePacket response) {
|
||||||
|
Transport transport = request.getConnection().getTransport();
|
||||||
|
if (transport instanceof TCPNIOTransport) {
|
||||||
|
return "tcp";
|
||||||
|
} else if (transport instanceof UDPNIOTransport) {
|
||||||
|
return "udp";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
|
HttpRequestPacket request, @Nullable HttpResponsePacket response) {
|
||||||
String protocol = request.getProtocolString();
|
String protocol = request.getProtocolString();
|
||||||
if (protocol.startsWith("HTTP/")) {
|
if (protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -40,7 +57,8 @@ final class GrizzlyNetAttributesGetter implements NetServerAttributesGetter<Http
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpRequestPacket request) {
|
public String getNetworkProtocolVersion(
|
||||||
|
HttpRequestPacket request, @Nullable HttpResponsePacket response) {
|
||||||
String protocol = request.getProtocolString();
|
String protocol = request.getProtocolString();
|
||||||
if (protocol.startsWith("HTTP/")) {
|
if (protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.grpc.v1_6.internal;
|
package io.opentelemetry.instrumentation.grpc.v1_6.internal;
|
||||||
|
|
||||||
|
import io.grpc.Status;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest;
|
import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
@ -15,7 +16,8 @@ import javax.annotation.Nullable;
|
||||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||||
* any time.
|
* any time.
|
||||||
*/
|
*/
|
||||||
public final class GrpcNetServerAttributesGetter implements NetServerAttributesGetter<GrpcRequest> {
|
public final class GrpcNetServerAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<GrpcRequest, Status> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,14 +13,14 @@ class HttpUrlNetAttributesGetter implements NetClientAttributesGetter<HttpURLCon
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpURLConnection connection, @Nullable Integer integer) {
|
public String getNetworkProtocolName(HttpURLConnection connection, @Nullable Integer integer) {
|
||||||
// HttpURLConnection hardcodes the protocol name&version
|
// HttpURLConnection hardcodes the protocol name&version
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpURLConnection connection, @Nullable Integer integer) {
|
public String getNetworkProtocolVersion(HttpURLConnection connection, @Nullable Integer integer) {
|
||||||
// HttpURLConnection hardcodes the protocol name&version
|
// HttpURLConnection hardcodes the protocol name&version
|
||||||
return "1.1";
|
return "1.1";
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,13 @@ public class JavaHttpClientNetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpRequest request, @Nullable HttpResponse<?> response) {
|
public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse<?> response) {
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse<?> response) {
|
public String getNetworkProtocolVersion(HttpRequest request, @Nullable HttpResponse<?> response) {
|
||||||
HttpClient.Version version;
|
HttpClient.Version version;
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
version = response.version();
|
version = response.version();
|
||||||
|
|
|
@ -20,13 +20,13 @@ public class JettyHttpClientNetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request request, @Nullable Response response) {
|
public String getNetworkProtocolName(Request request, @Nullable Response response) {
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request request, @Nullable Response response) {
|
public String getNetworkProtocolVersion(Request request, @Nullable Response response) {
|
||||||
HttpVersion httpVersion = null;
|
HttpVersion httpVersion = null;
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
httpVersion = response.getVersion();
|
httpVersion = response.getVersion();
|
||||||
|
|
|
@ -14,13 +14,13 @@ final class JoddHttpNetAttributesGetter
|
||||||
implements NetClientAttributesGetter<HttpRequest, HttpResponse> {
|
implements NetClientAttributesGetter<HttpRequest, HttpResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpRequest request, @Nullable HttpResponse response) {
|
public String getNetworkProtocolName(HttpRequest request, @Nullable HttpResponse response) {
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpRequest request, @Nullable HttpResponse response) {
|
public String getNetworkProtocolVersion(HttpRequest request, @Nullable HttpResponse response) {
|
||||||
String httpVersion = request.httpVersion();
|
String httpVersion = request.httpVersion();
|
||||||
if (httpVersion == null && response != null) {
|
if (httpVersion == null && response != null) {
|
||||||
httpVersion = response.httpVersion();
|
httpVersion = response.httpVersion();
|
||||||
|
|
|
@ -6,15 +6,16 @@
|
||||||
package io.opentelemetry.instrumentation.ktor.v1_0
|
package io.opentelemetry.instrumentation.ktor.v1_0
|
||||||
|
|
||||||
import io.ktor.request.*
|
import io.ktor.request.*
|
||||||
|
import io.ktor.response.*
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter
|
||||||
import io.opentelemetry.instrumentation.ktor.isIpAddress
|
import io.opentelemetry.instrumentation.ktor.isIpAddress
|
||||||
|
|
||||||
internal class KtorNetServerAttributesGetter : NetServerAttributesGetter<ApplicationRequest> {
|
internal class KtorNetServerAttributesGetter : NetServerAttributesGetter<ApplicationRequest, ApplicationResponse> {
|
||||||
|
|
||||||
override fun getProtocolName(request: ApplicationRequest): String? =
|
override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? =
|
||||||
if (request.httpVersion.startsWith("HTTP/")) "http" else null
|
if (request.httpVersion.startsWith("HTTP/")) "http" else null
|
||||||
|
|
||||||
override fun getProtocolVersion(request: ApplicationRequest): String? =
|
override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? =
|
||||||
if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null
|
if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null
|
||||||
|
|
||||||
override fun getSockPeerAddr(request: ApplicationRequest): String? {
|
override fun getSockPeerAddr(request: ApplicationRequest): String? {
|
||||||
|
|
|
@ -11,10 +11,10 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributes
|
||||||
|
|
||||||
internal object KtorNetClientAttributesGetter : NetClientAttributesGetter<HttpRequestData, HttpResponse> {
|
internal object KtorNetClientAttributesGetter : NetClientAttributesGetter<HttpRequestData, HttpResponse> {
|
||||||
|
|
||||||
override fun getProtocolName(request: HttpRequestData?, response: HttpResponse?): String? =
|
override fun getNetworkProtocolName(request: HttpRequestData?, response: HttpResponse?): String? =
|
||||||
response?.version?.name
|
response?.version?.name
|
||||||
|
|
||||||
override fun getProtocolVersion(request: HttpRequestData?, response: HttpResponse?): String? {
|
override fun getNetworkProtocolVersion(request: HttpRequestData?, response: HttpResponse?): String? {
|
||||||
val version = response?.version ?: return null
|
val version = response?.version ?: return null
|
||||||
return "${version.major}.${version.minor}"
|
return "${version.major}.${version.minor}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,16 @@
|
||||||
package io.opentelemetry.instrumentation.ktor.v2_0.server
|
package io.opentelemetry.instrumentation.ktor.v2_0.server
|
||||||
|
|
||||||
import io.ktor.server.request.*
|
import io.ktor.server.request.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter
|
||||||
import io.opentelemetry.instrumentation.ktor.isIpAddress
|
import io.opentelemetry.instrumentation.ktor.isIpAddress
|
||||||
|
|
||||||
internal class KtorNetServerAttributesGetter : NetServerAttributesGetter<ApplicationRequest> {
|
internal class KtorNetServerAttributesGetter : NetServerAttributesGetter<ApplicationRequest, ApplicationResponse> {
|
||||||
|
|
||||||
override fun getProtocolName(request: ApplicationRequest): String? =
|
override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? =
|
||||||
if (request.httpVersion.startsWith("HTTP/")) "http" else null
|
if (request.httpVersion.startsWith("HTTP/")) "http" else null
|
||||||
|
|
||||||
override fun getProtocolVersion(request: ApplicationRequest): String? =
|
override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? =
|
||||||
if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null
|
if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null
|
||||||
|
|
||||||
override fun getHostName(request: ApplicationRequest): String {
|
override fun getHostName(request: ApplicationRequest): String {
|
||||||
|
|
|
@ -9,11 +9,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class LibertyDispatcherNetAttributesGetter
|
public class LibertyDispatcherNetAttributesGetter
|
||||||
implements NetServerAttributesGetter<LibertyRequest> {
|
implements NetServerAttributesGetter<LibertyRequest, LibertyResponse> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(LibertyRequest request) {
|
public String getNetworkProtocolName(
|
||||||
|
LibertyRequest request, @Nullable LibertyResponse libertyResponse) {
|
||||||
String protocol = request.getProtocol();
|
String protocol = request.getProtocol();
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -23,7 +24,8 @@ public class LibertyDispatcherNetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(LibertyRequest request) {
|
public String getNetworkProtocolVersion(
|
||||||
|
LibertyRequest request, @Nullable LibertyResponse libertyResponse) {
|
||||||
String protocol = request.getProtocol();
|
String protocol = request.getProtocol();
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest;
|
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.ChannelUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -24,6 +25,11 @@ final class NettyConnectNetAttributesGetter
|
||||||
return channel instanceof DatagramChannel ? IP_UDP : IP_TCP;
|
return channel instanceof DatagramChannel ? IP_UDP : IP_TCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(NettyConnectionRequest request, @Nullable Channel channel) {
|
||||||
|
return ChannelUtil.getNetworkTransport(channel);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getPeerName(NettyConnectionRequest request) {
|
public String getPeerName(NettyConnectionRequest request) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel;
|
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.ChannelUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -27,13 +28,19 @@ final class NettyNetClientAttributesGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(
|
public String getNetworkTransport(
|
||||||
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||||
|
return ChannelUtil.getNetworkTransport(requestAndChannel.channel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) {
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) {
|
||||||
return requestAndChannel.request().getProtocolVersion().getProtocolName();
|
return requestAndChannel.request().getProtocolVersion().getProtocolName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) {
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse httpResponse) {
|
||||||
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
||||||
return version.getMajorVersion() + "." + version.getMinorVersion();
|
return version.getMajorVersion() + "." + version.getMinorVersion();
|
||||||
|
|
|
@ -10,14 +10,16 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel;
|
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.util.ChannelUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.jboss.netty.channel.socket.DatagramChannel;
|
import org.jboss.netty.channel.socket.DatagramChannel;
|
||||||
|
import org.jboss.netty.handler.codec.http.HttpResponse;
|
||||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||||
|
|
||||||
final class NettyNetServerAttributesGetter
|
final class NettyNetServerAttributesGetter
|
||||||
implements NetServerAttributesGetter<HttpRequestAndChannel> {
|
implements NetServerAttributesGetter<HttpRequestAndChannel, HttpResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransport(HttpRequestAndChannel requestAndChannel) {
|
public String getTransport(HttpRequestAndChannel requestAndChannel) {
|
||||||
|
@ -25,12 +27,20 @@ final class NettyNetServerAttributesGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpRequestAndChannel requestAndChannel) {
|
public String getNetworkTransport(
|
||||||
|
HttpRequestAndChannel requestAndChannel, HttpResponse response) {
|
||||||
|
return ChannelUtil.getNetworkTransport(requestAndChannel.channel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||||
return requestAndChannel.request().getProtocolVersion().getProtocolName();
|
return requestAndChannel.request().getProtocolVersion().getProtocolName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpRequestAndChannel requestAndChannel) {
|
public String getNetworkProtocolVersion(
|
||||||
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||||
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
||||||
return version.getMajorVersion() + "." + version.getMinorVersion();
|
return version.getMajorVersion() + "." + version.getMinorVersion();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.netty.v3_8.util;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.jboss.netty.channel.Channel;
|
||||||
|
import org.jboss.netty.channel.socket.DatagramChannel;
|
||||||
|
|
||||||
|
public final class ChannelUtil {
|
||||||
|
|
||||||
|
public static String getNetworkTransport(@Nullable Channel channel) {
|
||||||
|
if (channel == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return channel instanceof DatagramChannel ? "udp" : "tcp";
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChannelUtil() {}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.netty.v4.common.internal;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.socket.DatagramChannel;
|
||||||
|
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 ChannelUtil {
|
||||||
|
|
||||||
|
public static String getNetworkTransport(@Nullable Channel channel) {
|
||||||
|
if (channel == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return channel instanceof DatagramChannel ? "udp" : "tcp";
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChannelUtil() {}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import io.netty.channel.Channel;
|
||||||
import io.netty.channel.socket.DatagramChannel;
|
import io.netty.channel.socket.DatagramChannel;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest;
|
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest;
|
||||||
|
import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -24,6 +25,11 @@ final class NettyConnectNetAttributesGetter
|
||||||
return channel instanceof DatagramChannel ? IP_UDP : IP_TCP;
|
return channel instanceof DatagramChannel ? IP_UDP : IP_TCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(NettyConnectionRequest request, @Nullable Channel channel) {
|
||||||
|
return ChannelUtil.getNetworkTransport(channel);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getPeerName(NettyConnectionRequest request) {
|
public String getPeerName(NettyConnectionRequest request) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel;
|
import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel;
|
||||||
|
import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -27,13 +28,19 @@ final class NettyNetClientAttributesGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(
|
public String getNetworkTransport(
|
||||||
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||||
|
return ChannelUtil.getNetworkTransport(requestAndChannel.channel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||||
return requestAndChannel.request().getProtocolVersion().protocolName();
|
return requestAndChannel.request().getProtocolVersion().protocolName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||||
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
||||||
return version.majorVersion() + "." + version.minorVersion();
|
return version.majorVersion() + "." + version.minorVersion();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr
|
||||||
|
|
||||||
import io.netty.channel.socket.DatagramChannel;
|
import io.netty.channel.socket.DatagramChannel;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
|
||||||
|
import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -21,6 +22,11 @@ final class NettySslNetAttributesGetter
|
||||||
return request.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP;
|
return request.channel() instanceof DatagramChannel ? IP_UDP : IP_TCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNetworkTransport(NettySslRequest request, @Nullable Void unused) {
|
||||||
|
return ChannelUtil.getNetworkTransport(request.channel());
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getPeerName(NettySslRequest nettySslRequest) {
|
public String getPeerName(NettySslRequest nettySslRequest) {
|
||||||
|
|
|
@ -9,15 +9,17 @@ import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTr
|
||||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP;
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_UDP;
|
||||||
|
|
||||||
import io.netty.channel.socket.DatagramChannel;
|
import io.netty.channel.socket.DatagramChannel;
|
||||||
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel;
|
import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel;
|
||||||
|
import io.opentelemetry.instrumentation.netty.v4.common.internal.ChannelUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
final class NettyNetServerAttributesGetter
|
final class NettyNetServerAttributesGetter
|
||||||
implements NetServerAttributesGetter<HttpRequestAndChannel> {
|
implements NetServerAttributesGetter<HttpRequestAndChannel, HttpResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransport(HttpRequestAndChannel requestAndChannel) {
|
public String getTransport(HttpRequestAndChannel requestAndChannel) {
|
||||||
|
@ -25,12 +27,20 @@ final class NettyNetServerAttributesGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpRequestAndChannel requestAndChannel) {
|
public String getNetworkTransport(
|
||||||
|
HttpRequestAndChannel requestAndChannel, HttpResponse response) {
|
||||||
|
return ChannelUtil.getNetworkTransport(requestAndChannel.channel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNetworkProtocolName(
|
||||||
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||||
return requestAndChannel.request().getProtocolVersion().protocolName();
|
return requestAndChannel.request().getProtocolVersion().protocolName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpRequestAndChannel requestAndChannel) {
|
public String getNetworkProtocolVersion(
|
||||||
|
HttpRequestAndChannel requestAndChannel, @Nullable HttpResponse response) {
|
||||||
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
HttpVersion version = requestAndChannel.request().getProtocolVersion();
|
||||||
return version.majorVersion() + "." + version.minorVersion();
|
return version.majorVersion() + "." + version.minorVersion();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public final class OkHttp2NetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request request, @Nullable Response response) {
|
public String getNetworkProtocolName(Request request, @Nullable Response response) {
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public final class OkHttp2NetAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request request, @Nullable Response response) {
|
public String getNetworkProtocolVersion(Request request, @Nullable Response response) {
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public enum OkHttpNetAttributesGetter implements NetClientAttributesGetter<Reque
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request request, @Nullable Response response) {
|
public String getNetworkProtocolName(Request request, @Nullable Response response) {
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public enum OkHttpNetAttributesGetter implements NetClientAttributesGetter<Reque
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request request, @Nullable Response response) {
|
public String getNetworkProtocolVersion(Request request, @Nullable Response response) {
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
// only needed so that HttpServerAttributesExtractor can be added to the HTTP server instrumenter
|
// only needed so that HttpServerAttributesExtractor can be added to the HTTP server instrumenter
|
||||||
enum MockNetServerAttributesGetter implements NetServerAttributesGetter<String> {
|
enum MockNetServerAttributesGetter implements NetServerAttributesGetter<String, Void> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -9,17 +9,19 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import ratpack.handling.Context;
|
import ratpack.handling.Context;
|
||||||
import ratpack.http.Request;
|
import ratpack.http.Request;
|
||||||
|
import ratpack.http.Response;
|
||||||
import ratpack.server.PublicAddress;
|
import ratpack.server.PublicAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||||
* any time.
|
* any time.
|
||||||
*/
|
*/
|
||||||
public final class RatpackNetServerAttributesGetter implements NetServerAttributesGetter<Request> {
|
public final class RatpackNetServerAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<Request, Response> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request request) {
|
public String getNetworkProtocolName(Request request, @Nullable Response response) {
|
||||||
String protocol = request.getProtocol();
|
String protocol = request.getProtocol();
|
||||||
if (protocol.startsWith("HTTP/")) {
|
if (protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -29,7 +31,7 @@ public final class RatpackNetServerAttributesGetter implements NetServerAttribut
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request request) {
|
public String getNetworkProtocolVersion(Request request, @Nullable Response response) {
|
||||||
String protocol = request.getProtocol();
|
String protocol = request.getProtocol();
|
||||||
if (protocol.startsWith("HTTP/")) {
|
if (protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -19,7 +19,8 @@ final class ReactorNettyNetClientAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpClientConfig request, @Nullable HttpClientResponse response) {
|
public String getNetworkProtocolName(
|
||||||
|
HttpClientConfig request, @Nullable HttpClientResponse response) {
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +29,7 @@ final class ReactorNettyNetClientAttributesGetter
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
HttpClientConfig request, @Nullable HttpClientResponse response) {
|
HttpClientConfig request, @Nullable HttpClientResponse response) {
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -10,12 +10,13 @@ import com.noelios.restlet.http.HttpRequest;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.restlet.data.Request;
|
import org.restlet.data.Request;
|
||||||
|
import org.restlet.data.Response;
|
||||||
|
|
||||||
final class RestletNetAttributesGetter implements NetServerAttributesGetter<Request> {
|
final class RestletNetAttributesGetter implements NetServerAttributesGetter<Request, Response> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request request) {
|
public String getNetworkProtocolName(Request request, @Nullable Response response) {
|
||||||
String protocol = getProtocolString(request);
|
String protocol = getProtocolString(request);
|
||||||
if (protocol.startsWith("HTTP/")) {
|
if (protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -25,7 +26,7 @@ final class RestletNetAttributesGetter implements NetServerAttributesGetter<Requ
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request request) {
|
public String getNetworkProtocolVersion(Request request, @Nullable Response response) {
|
||||||
String protocol = getProtocolString(request);
|
String protocol = getProtocolString(request);
|
||||||
if (protocol.startsWith("HTTP/")) {
|
if (protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -12,12 +12,14 @@ import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.restlet.Request;
|
import org.restlet.Request;
|
||||||
|
import org.restlet.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||||
* any time.
|
* any time.
|
||||||
*/
|
*/
|
||||||
public final class RestletNetAttributesGetter implements NetServerAttributesGetter<Request> {
|
public final class RestletNetAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<Request, Response> {
|
||||||
|
|
||||||
private static final Class<?> HTTP_REQUEST_CLASS;
|
private static final Class<?> HTTP_REQUEST_CLASS;
|
||||||
private static final MethodHandle GET_HTTP_CALL;
|
private static final MethodHandle GET_HTTP_CALL;
|
||||||
|
@ -79,13 +81,13 @@ public final class RestletNetAttributesGetter implements NetServerAttributesGett
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request request) {
|
public String getNetworkProtocolName(Request request, @Nullable Response response) {
|
||||||
return request.getProtocol().getSchemeName();
|
return request.getProtocol().getSchemeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request request) {
|
public String getNetworkProtocolVersion(Request request, @Nullable Response response) {
|
||||||
return request.getProtocol().getVersion();
|
return request.getProtocol().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ServletNetAttributesGetter<REQUEST, RESPONSE>
|
public class ServletNetAttributesGetter<REQUEST, RESPONSE>
|
||||||
implements NetServerAttributesGetter<ServletRequestContext<REQUEST>> {
|
implements NetServerAttributesGetter<
|
||||||
|
ServletRequestContext<REQUEST>, ServletResponseContext<RESPONSE>> {
|
||||||
|
|
||||||
private final ServletAccessor<REQUEST, RESPONSE> accessor;
|
private final ServletAccessor<REQUEST, RESPONSE> accessor;
|
||||||
|
|
||||||
|
@ -19,7 +20,9 @@ public class ServletNetAttributesGetter<REQUEST, RESPONSE>
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(ServletRequestContext<REQUEST> requestContext) {
|
public String getNetworkProtocolName(
|
||||||
|
ServletRequestContext<REQUEST> requestContext,
|
||||||
|
@Nullable ServletResponseContext<RESPONSE> responseContext) {
|
||||||
String protocol = accessor.getRequestProtocol(requestContext.request());
|
String protocol = accessor.getRequestProtocol(requestContext.request());
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -29,7 +32,9 @@ public class ServletNetAttributesGetter<REQUEST, RESPONSE>
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(ServletRequestContext<REQUEST> requestContext) {
|
public String getNetworkProtocolVersion(
|
||||||
|
ServletRequestContext<REQUEST> requestContext,
|
||||||
|
@Nullable ServletResponseContext<RESPONSE> responseContext) {
|
||||||
String protocol = accessor.getRequestProtocol(requestContext.request());
|
String protocol = accessor.getRequestProtocol(requestContext.request());
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -11,7 +11,7 @@ import javax.annotation.Nullable;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
final class WebfluxServerNetAttributesGetter
|
final class WebfluxServerNetAttributesGetter
|
||||||
implements NetServerAttributesGetter<ServerWebExchange> {
|
implements NetServerAttributesGetter<ServerWebExchange, ServerWebExchange> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,13 +8,16 @@ package io.opentelemetry.instrumentation.spring.webmvc.v5_3;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
enum SpringWebMvcNetAttributesGetter implements NetServerAttributesGetter<HttpServletRequest> {
|
enum SpringWebMvcNetAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<HttpServletRequest, HttpServletResponse> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpServletRequest request) {
|
public String getNetworkProtocolName(
|
||||||
|
HttpServletRequest request, @Nullable HttpServletResponse response) {
|
||||||
String protocol = request.getProtocol();
|
String protocol = request.getProtocol();
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -24,7 +27,8 @@ enum SpringWebMvcNetAttributesGetter implements NetServerAttributesGetter<HttpSe
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpServletRequest request) {
|
public String getNetworkProtocolVersion(
|
||||||
|
HttpServletRequest request, @Nullable HttpServletResponse response) {
|
||||||
String protocol = request.getProtocol();
|
String protocol = request.getProtocol();
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -7,14 +7,17 @@ package io.opentelemetry.instrumentation.spring.webmvc.v6_0;
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
enum SpringWebMvcNetAttributesGetter implements NetServerAttributesGetter<HttpServletRequest> {
|
enum SpringWebMvcNetAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<HttpServletRequest, HttpServletResponse> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpServletRequest request) {
|
public String getNetworkProtocolName(
|
||||||
|
HttpServletRequest request, @Nullable HttpServletResponse response) {
|
||||||
String protocol = request.getProtocol();
|
String protocol = request.getProtocol();
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -24,7 +27,8 @@ enum SpringWebMvcNetAttributesGetter implements NetServerAttributesGetter<HttpSe
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpServletRequest request) {
|
public String getNetworkProtocolVersion(
|
||||||
|
HttpServletRequest request, @Nullable HttpServletResponse response) {
|
||||||
String protocol = request.getProtocol();
|
String protocol = request.getProtocol();
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -11,12 +11,13 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributes
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.apache.coyote.ActionCode;
|
import org.apache.coyote.ActionCode;
|
||||||
import org.apache.coyote.Request;
|
import org.apache.coyote.Request;
|
||||||
|
import org.apache.coyote.Response;
|
||||||
|
|
||||||
public class TomcatNetAttributesGetter implements NetServerAttributesGetter<Request> {
|
public class TomcatNetAttributesGetter implements NetServerAttributesGetter<Request, Response> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(Request request) {
|
public String getNetworkProtocolName(Request request, @Nullable Response response) {
|
||||||
String protocol = messageBytesToString(request.protocol());
|
String protocol = messageBytesToString(request.protocol());
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -26,7 +27,7 @@ public class TomcatNetAttributesGetter implements NetServerAttributesGetter<Requ
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(Request request) {
|
public String getNetworkProtocolVersion(Request request, @Nullable Response response) {
|
||||||
String protocol = messageBytesToString(request.protocol());
|
String protocol = messageBytesToString(request.protocol());
|
||||||
if (protocol != null && protocol.startsWith("HTTP/")) {
|
if (protocol != null && protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -10,11 +10,13 @@ import io.undertow.server.HttpServerExchange;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class UndertowNetAttributesGetter implements NetServerAttributesGetter<HttpServerExchange> {
|
public class UndertowNetAttributesGetter
|
||||||
|
implements NetServerAttributesGetter<HttpServerExchange, HttpServerExchange> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpServerExchange exchange) {
|
public String getNetworkProtocolName(
|
||||||
|
HttpServerExchange exchange, @Nullable HttpServerExchange unused) {
|
||||||
String protocol = exchange.getProtocol().toString();
|
String protocol = exchange.getProtocol().toString();
|
||||||
if (protocol.startsWith("HTTP/")) {
|
if (protocol.startsWith("HTTP/")) {
|
||||||
return "http";
|
return "http";
|
||||||
|
@ -24,7 +26,8 @@ public class UndertowNetAttributesGetter implements NetServerAttributesGetter<Ht
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(HttpServerExchange exchange) {
|
public String getNetworkProtocolVersion(
|
||||||
|
HttpServerExchange exchange, @Nullable HttpServerExchange unused) {
|
||||||
String protocol = exchange.getProtocol().toString();
|
String protocol = exchange.getProtocol().toString();
|
||||||
if (protocol.startsWith("HTTP/")) {
|
if (protocol.startsWith("HTTP/")) {
|
||||||
return protocol.substring("HTTP/".length());
|
return protocol.substring("HTTP/".length());
|
||||||
|
|
|
@ -16,13 +16,14 @@ final class Vertx4NetAttributesGetter
|
||||||
implements NetClientAttributesGetter<HttpClientRequest, HttpClientResponse> {
|
implements NetClientAttributesGetter<HttpClientRequest, HttpClientResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolName(HttpClientRequest request, @Nullable HttpClientResponse response) {
|
public String getNetworkProtocolName(
|
||||||
|
HttpClientRequest request, @Nullable HttpClientResponse response) {
|
||||||
return "http";
|
return "http";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getProtocolVersion(
|
public String getNetworkProtocolVersion(
|
||||||
HttpClientRequest request, @Nullable HttpClientResponse response) {
|
HttpClientRequest request, @Nullable HttpClientResponse response) {
|
||||||
HttpVersion version = request.version();
|
HttpVersion version = request.version();
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
|
|
|
@ -182,7 +182,7 @@ final class TestInstrumenters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum NetServerGetter implements NetServerAttributesGetter<String> {
|
private enum NetServerGetter implements NetServerAttributesGetter<String, Void> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
Loading…
Reference in New Issue