Use new semconv constants (#9504)

This commit is contained in:
Trask Stalnaker 2023-09-20 04:53:40 -07:00 committed by GitHub
parent d90485d2b8
commit ae25d481ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 485 additions and 638 deletions

View File

@ -13,7 +13,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
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.InternalNetworkAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
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;
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
@ -109,7 +108,7 @@ public final class HttpClientAttributesExtractor<REQUEST, RESPONSE>
String fullUrl = stripSensitiveData(getter.getUrlFull(request)); String fullUrl = stripSensitiveData(getter.getUrlFull(request));
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, UrlAttributes.URL_FULL, fullUrl); internalSet(attributes, SemanticAttributes.URL_FULL, fullUrl);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
internalSet(attributes, SemanticAttributes.HTTP_URL, fullUrl); internalSet(attributes, SemanticAttributes.HTTP_URL, fullUrl);

View File

@ -14,7 +14,6 @@ import static io.opentelemetry.instrumentation.api.internal.HttpConstants._OTHER
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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashSet; import java.util.HashSet;
@ -53,10 +52,10 @@ abstract class HttpCommonAttributesExtractor<
String method = getter.getHttpRequestMethod(request); String method = getter.getHttpRequestMethod(request);
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
if (method == null || knownMethods.contains(method)) { if (method == null || knownMethods.contains(method)) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
} else { } else {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
} }
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
@ -83,7 +82,7 @@ abstract class HttpCommonAttributesExtractor<
Long requestBodySize = requestBodySize(request); Long requestBodySize = requestBodySize(request);
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_BODY_SIZE, requestBodySize); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_BODY_SIZE, requestBodySize);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, requestBodySize); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, requestBodySize);
@ -93,7 +92,7 @@ abstract class HttpCommonAttributesExtractor<
Integer statusCode = getter.getHttpResponseStatusCode(request, response, error); Integer statusCode = getter.getHttpResponseStatusCode(request, response, error);
if (statusCode != null && statusCode > 0) { if (statusCode != null && statusCode > 0) {
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, HttpAttributes.HTTP_RESPONSE_STATUS_CODE, (long) statusCode); internalSet(attributes, SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, (long) statusCode);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
internalSet(attributes, SemanticAttributes.HTTP_STATUS_CODE, (long) statusCode); internalSet(attributes, SemanticAttributes.HTTP_STATUS_CODE, (long) statusCode);
@ -102,7 +101,7 @@ abstract class HttpCommonAttributesExtractor<
Long responseBodySize = responseBodySize(request, response); Long responseBodySize = responseBodySize(request, response);
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, HttpAttributes.HTTP_RESPONSE_BODY_SIZE, responseBodySize); internalSet(attributes, SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, responseBodySize);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
internalSet(attributes, SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, responseBodySize); internalSet(attributes, SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, responseBodySize);

View File

@ -7,7 +7,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
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.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -18,13 +17,13 @@ final class HttpMessageBodySizeUtil {
private static final AttributeKey<Long> HTTP_REQUEST_BODY_SIZE = private static final AttributeKey<Long> HTTP_REQUEST_BODY_SIZE =
SemconvStability.emitOldHttpSemconv() SemconvStability.emitOldHttpSemconv()
? SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH ? SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH
: HttpAttributes.HTTP_REQUEST_BODY_SIZE; : SemanticAttributes.HTTP_REQUEST_BODY_SIZE;
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
private static final AttributeKey<Long> HTTP_RESPONSE_BODY_SIZE = private static final AttributeKey<Long> HTTP_RESPONSE_BODY_SIZE =
SemconvStability.emitOldHttpSemconv() SemconvStability.emitOldHttpSemconv()
? SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH ? SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH
: HttpAttributes.HTTP_RESPONSE_BODY_SIZE; : SemanticAttributes.HTTP_RESPONSE_BODY_SIZE;
@Nullable @Nullable
static Long getHttpRequestBodySize(Attributes... attributesList) { static Long getHttpRequestBodySize(Attributes... attributesList) {

View File

@ -13,9 +13,6 @@ import io.opentelemetry.api.metrics.LongUpDownCounterBuilder;
import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder; import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder;
import io.opentelemetry.extension.incubator.metrics.ExtendedLongHistogramBuilder; import io.opentelemetry.extension.incubator.metrics.ExtendedLongHistogramBuilder;
import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder; import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
final class HttpMetricsAdvice { final class HttpMetricsAdvice {
@ -29,13 +26,13 @@ final class HttpMetricsAdvice {
advice -> advice ->
advice.setAttributes( advice.setAttributes(
asList( asList(
HttpAttributes.HTTP_REQUEST_METHOD, SemanticAttributes.HTTP_REQUEST_METHOD,
HttpAttributes.HTTP_RESPONSE_STATUS_CODE, SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
NetworkAttributes.NETWORK_PROTOCOL_NAME, SemanticAttributes.NETWORK_PROTOCOL_NAME,
NetworkAttributes.NETWORK_PROTOCOL_VERSION, SemanticAttributes.NETWORK_PROTOCOL_VERSION,
NetworkAttributes.SERVER_ADDRESS, SemanticAttributes.SERVER_ADDRESS,
NetworkAttributes.SERVER_PORT, SemanticAttributes.SERVER_PORT,
NetworkAttributes.SERVER_SOCKET_ADDRESS))); SemanticAttributes.SERVER_SOCKET_ADDRESS)));
} }
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
@ -68,13 +65,13 @@ final class HttpMetricsAdvice {
advice.setAttributes( advice.setAttributes(
asList( asList(
// stable attributes // stable attributes
HttpAttributes.HTTP_REQUEST_METHOD, SemanticAttributes.HTTP_REQUEST_METHOD,
HttpAttributes.HTTP_RESPONSE_STATUS_CODE, SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
NetworkAttributes.NETWORK_PROTOCOL_NAME, SemanticAttributes.NETWORK_PROTOCOL_NAME,
NetworkAttributes.NETWORK_PROTOCOL_VERSION, SemanticAttributes.NETWORK_PROTOCOL_VERSION,
NetworkAttributes.SERVER_ADDRESS, SemanticAttributes.SERVER_ADDRESS,
NetworkAttributes.SERVER_PORT, SemanticAttributes.SERVER_PORT,
NetworkAttributes.SERVER_SOCKET_ADDRESS, SemanticAttributes.SERVER_SOCKET_ADDRESS,
// old attributes // old attributes
SemanticAttributes.HTTP_METHOD, SemanticAttributes.HTTP_METHOD,
SemanticAttributes.HTTP_STATUS_CODE, SemanticAttributes.HTTP_STATUS_CODE,
@ -95,11 +92,11 @@ final class HttpMetricsAdvice {
advice.setAttributes( advice.setAttributes(
asList( asList(
SemanticAttributes.HTTP_ROUTE, SemanticAttributes.HTTP_ROUTE,
HttpAttributes.HTTP_REQUEST_METHOD, SemanticAttributes.HTTP_REQUEST_METHOD,
HttpAttributes.HTTP_RESPONSE_STATUS_CODE, SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
NetworkAttributes.NETWORK_PROTOCOL_NAME, SemanticAttributes.NETWORK_PROTOCOL_NAME,
NetworkAttributes.NETWORK_PROTOCOL_VERSION, SemanticAttributes.NETWORK_PROTOCOL_VERSION,
UrlAttributes.URL_SCHEME))); SemanticAttributes.URL_SCHEME)));
} }
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
@ -134,11 +131,11 @@ final class HttpMetricsAdvice {
asList( asList(
// stable attributes // stable attributes
SemanticAttributes.HTTP_ROUTE, SemanticAttributes.HTTP_ROUTE,
HttpAttributes.HTTP_REQUEST_METHOD, SemanticAttributes.HTTP_REQUEST_METHOD,
HttpAttributes.HTTP_RESPONSE_STATUS_CODE, SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
NetworkAttributes.NETWORK_PROTOCOL_NAME, SemanticAttributes.NETWORK_PROTOCOL_NAME,
NetworkAttributes.NETWORK_PROTOCOL_VERSION, SemanticAttributes.NETWORK_PROTOCOL_VERSION,
UrlAttributes.URL_SCHEME, SemanticAttributes.URL_SCHEME,
// old attributes // old attributes
SemanticAttributes.HTTP_SCHEME, SemanticAttributes.HTTP_SCHEME,
SemanticAttributes.HTTP_ROUTE, SemanticAttributes.HTTP_ROUTE,
@ -166,8 +163,8 @@ final class HttpMetricsAdvice {
SemanticAttributes.NET_HOST_NAME, SemanticAttributes.NET_HOST_NAME,
SemanticAttributes.NET_HOST_PORT, SemanticAttributes.NET_HOST_PORT,
// https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md#metric-httpserveractive_requests // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md#metric-httpserveractive_requests
HttpAttributes.HTTP_REQUEST_METHOD, SemanticAttributes.HTTP_REQUEST_METHOD,
UrlAttributes.URL_SCHEME))); SemanticAttributes.URL_SCHEME)));
} }
private HttpMetricsAdvice() {} private HttpMetricsAdvice() {}

View File

@ -1,36 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter.http.internal;
import static io.opentelemetry.api.common.AttributeKey.longKey;
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 HttpAttributes {
// FIXME: remove this class and replace its usages with SemanticAttributes once schema 1.21 is
// released
public static final AttributeKey<String> HTTP_REQUEST_METHOD = stringKey("http.request.method");
public static final AttributeKey<String> HTTP_REQUEST_METHOD_ORIGINAL =
stringKey("http.request.method_original");
public static final AttributeKey<Long> HTTP_REQUEST_BODY_SIZE = longKey("http.request.body.size");
public static final AttributeKey<Long> HTTP_RESPONSE_BODY_SIZE =
longKey("http.response.body.size");
public static final AttributeKey<Long> HTTP_RESPONSE_STATUS_CODE =
longKey("http.response.status_code");
private HttpAttributes() {}
}

View File

@ -39,9 +39,9 @@ public final class InternalClientAttributesExtractor<REQUEST, RESPONSE> {
AddressAndPort clientAddressAndPort = extractClientAddressAndPort(request); AddressAndPort clientAddressAndPort = extractClientAddressAndPort(request);
if (emitStableUrlAttributes) { if (emitStableUrlAttributes) {
internalSet(attributes, NetworkAttributes.CLIENT_ADDRESS, clientAddressAndPort.address); internalSet(attributes, SemanticAttributes.CLIENT_ADDRESS, clientAddressAndPort.address);
if (clientAddressAndPort.port != null && clientAddressAndPort.port > 0) { if (clientAddressAndPort.port != null && clientAddressAndPort.port > 0) {
internalSet(attributes, NetworkAttributes.CLIENT_PORT, (long) clientAddressAndPort.port); internalSet(attributes, SemanticAttributes.CLIENT_PORT, (long) clientAddressAndPort.port);
} }
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {
@ -57,7 +57,7 @@ public final class InternalClientAttributesExtractor<REQUEST, RESPONSE> {
if (clientSocketAddress != null && !clientSocketAddress.equals(clientAddressAndPort.address)) { if (clientSocketAddress != null && !clientSocketAddress.equals(clientAddressAndPort.address)) {
if (emitStableUrlAttributes) { if (emitStableUrlAttributes) {
internalSet(attributes, NetworkAttributes.CLIENT_SOCKET_ADDRESS, clientSocketAddress); internalSet(attributes, SemanticAttributes.CLIENT_SOCKET_ADDRESS, clientSocketAddress);
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, clientSocketAddress); internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, clientSocketAddress);
@ -66,7 +66,7 @@ public final class InternalClientAttributesExtractor<REQUEST, RESPONSE> {
if (clientSocketPort != null && clientSocketPort > 0) { if (clientSocketPort != null && clientSocketPort > 0) {
if (emitStableUrlAttributes) { if (emitStableUrlAttributes) {
if (!clientSocketPort.equals(clientAddressAndPort.port)) { if (!clientSocketPort.equals(clientAddressAndPort.port)) {
internalSet(attributes, NetworkAttributes.CLIENT_SOCKET_PORT, (long) clientSocketPort); internalSet(attributes, SemanticAttributes.CLIENT_SOCKET_PORT, (long) clientSocketPort);
} }
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {

View File

@ -44,14 +44,14 @@ public final class InternalNetworkAttributesExtractor<REQUEST, RESPONSE> {
String transport = lowercase(getter.getNetworkTransport(request, response)); String transport = lowercase(getter.getNetworkTransport(request, response));
if (networkTransportFilter.shouldAddNetworkTransport( if (networkTransportFilter.shouldAddNetworkTransport(
protocolName, protocolVersion, transport)) { protocolName, protocolVersion, transport)) {
internalSet(attributes, NetworkAttributes.NETWORK_TRANSPORT, transport); internalSet(attributes, SemanticAttributes.NETWORK_TRANSPORT, transport);
} }
internalSet( internalSet(
attributes, attributes,
NetworkAttributes.NETWORK_TYPE, SemanticAttributes.NETWORK_TYPE,
lowercase(getter.getNetworkType(request, response))); lowercase(getter.getNetworkType(request, response)));
internalSet(attributes, NetworkAttributes.NETWORK_PROTOCOL_NAME, protocolName); internalSet(attributes, SemanticAttributes.NETWORK_PROTOCOL_NAME, protocolName);
internalSet(attributes, NetworkAttributes.NETWORK_PROTOCOL_VERSION, protocolVersion); internalSet(attributes, SemanticAttributes.NETWORK_PROTOCOL_VERSION, protocolVersion);
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {
// net.transport and net.sock.family are not 1:1 convertible with network.transport and // net.transport and net.sock.family are not 1:1 convertible with network.transport and

View File

@ -49,7 +49,7 @@ public final class InternalServerAttributesExtractor<REQUEST, RESPONSE> {
AddressAndPort serverAddressAndPort = extractServerAddressAndPort(request); AddressAndPort serverAddressAndPort = extractServerAddressAndPort(request);
if (emitStableUrlAttributes) { if (emitStableUrlAttributes) {
internalSet(attributes, NetworkAttributes.SERVER_ADDRESS, serverAddressAndPort.address); internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, serverAddressAndPort.address);
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {
internalSet(attributes, oldSemconvMode.address, serverAddressAndPort.address); internalSet(attributes, oldSemconvMode.address, serverAddressAndPort.address);
@ -59,7 +59,7 @@ public final class InternalServerAttributesExtractor<REQUEST, RESPONSE> {
&& serverAddressAndPort.port > 0 && serverAddressAndPort.port > 0
&& captureServerPortCondition.test(serverAddressAndPort.port, request)) { && captureServerPortCondition.test(serverAddressAndPort.port, request)) {
if (emitStableUrlAttributes) { if (emitStableUrlAttributes) {
internalSet(attributes, NetworkAttributes.SERVER_PORT, (long) serverAddressAndPort.port); internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) serverAddressAndPort.port);
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {
internalSet(attributes, oldSemconvMode.port, (long) serverAddressAndPort.port); internalSet(attributes, oldSemconvMode.port, (long) serverAddressAndPort.port);
@ -73,7 +73,7 @@ public final class InternalServerAttributesExtractor<REQUEST, RESPONSE> {
String serverSocketAddress = getter.getServerSocketAddress(request, response); String serverSocketAddress = getter.getServerSocketAddress(request, response);
if (serverSocketAddress != null && !serverSocketAddress.equals(serverAddressAndPort.address)) { if (serverSocketAddress != null && !serverSocketAddress.equals(serverAddressAndPort.address)) {
if (emitStableUrlAttributes && captureServerSocketAttributes) { if (emitStableUrlAttributes && captureServerSocketAttributes) {
internalSet(attributes, NetworkAttributes.SERVER_SOCKET_ADDRESS, serverSocketAddress); internalSet(attributes, SemanticAttributes.SERVER_SOCKET_ADDRESS, serverSocketAddress);
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {
internalSet(attributes, oldSemconvMode.socketAddress, serverSocketAddress); internalSet(attributes, oldSemconvMode.socketAddress, serverSocketAddress);
@ -85,7 +85,7 @@ public final class InternalServerAttributesExtractor<REQUEST, RESPONSE> {
&& serverSocketPort > 0 && serverSocketPort > 0
&& !serverSocketPort.equals(serverAddressAndPort.port)) { && !serverSocketPort.equals(serverAddressAndPort.port)) {
if (emitStableUrlAttributes && captureServerSocketAttributes) { if (emitStableUrlAttributes && captureServerSocketAttributes) {
internalSet(attributes, NetworkAttributes.SERVER_SOCKET_PORT, (long) serverSocketPort); internalSet(attributes, SemanticAttributes.SERVER_SOCKET_PORT, (long) serverSocketPort);
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {
internalSet(attributes, oldSemconvMode.socketPort, (long) serverSocketPort); internalSet(attributes, oldSemconvMode.socketPort, (long) serverSocketPort);
@ -95,7 +95,7 @@ public final class InternalServerAttributesExtractor<REQUEST, RESPONSE> {
String serverSocketDomain = getter.getServerSocketDomain(request, response); String serverSocketDomain = getter.getServerSocketDomain(request, response);
if (serverSocketDomain != null && !serverSocketDomain.equals(serverAddressAndPort.address)) { if (serverSocketDomain != null && !serverSocketDomain.equals(serverAddressAndPort.address)) {
if (emitStableUrlAttributes && captureServerSocketAttributes) { if (emitStableUrlAttributes && captureServerSocketAttributes) {
internalSet(attributes, NetworkAttributes.SERVER_SOCKET_DOMAIN, serverSocketDomain); internalSet(attributes, SemanticAttributes.SERVER_SOCKET_DOMAIN, serverSocketDomain);
} }
if (emitOldHttpAttributes && oldSemconvMode.socketDomain != null) { if (emitOldHttpAttributes && oldSemconvMode.socketDomain != null) {
internalSet(attributes, oldSemconvMode.socketDomain, serverSocketDomain); internalSet(attributes, oldSemconvMode.socketDomain, serverSocketDomain);

View File

@ -1,53 +0,0 @@
/*
* 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.longKey;
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");
public static final AttributeKey<String> SERVER_ADDRESS = stringKey("server.address");
public static final AttributeKey<Long> SERVER_PORT = longKey("server.port");
public static final AttributeKey<String> SERVER_SOCKET_DOMAIN = stringKey("server.socket.domain");
public static final AttributeKey<String> SERVER_SOCKET_ADDRESS =
stringKey("server.socket.address");
public static final AttributeKey<Long> SERVER_SOCKET_PORT = longKey("server.socket.port");
public static final AttributeKey<String> CLIENT_ADDRESS = stringKey("client.address");
public static final AttributeKey<Long> CLIENT_PORT = longKey("client.port");
public static final AttributeKey<String> CLIENT_SOCKET_ADDRESS =
stringKey("client.socket.address");
public static final AttributeKey<Long> CLIENT_SOCKET_PORT = longKey("client.socket.port");
private NetworkAttributes() {}
}

View File

@ -8,7 +8,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.DoubleHistogramBuilder; import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder; import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,12 +30,12 @@ final class RpcMetricsAdvice {
attributes.add(SemanticAttributes.RPC_METHOD); attributes.add(SemanticAttributes.RPC_METHOD);
attributes.add(SemanticAttributes.RPC_GRPC_STATUS_CODE); attributes.add(SemanticAttributes.RPC_GRPC_STATUS_CODE);
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes.add(NetworkAttributes.NETWORK_TYPE); attributes.add(SemanticAttributes.NETWORK_TYPE);
attributes.add(NetworkAttributes.NETWORK_TRANSPORT); attributes.add(SemanticAttributes.NETWORK_TRANSPORT);
attributes.add(NetworkAttributes.SERVER_ADDRESS); attributes.add(SemanticAttributes.SERVER_ADDRESS);
attributes.add(NetworkAttributes.SERVER_PORT); attributes.add(SemanticAttributes.SERVER_PORT);
attributes.add(NetworkAttributes.SERVER_SOCKET_ADDRESS); attributes.add(SemanticAttributes.SERVER_SOCKET_ADDRESS);
attributes.add(NetworkAttributes.SERVER_SOCKET_PORT); attributes.add(SemanticAttributes.SERVER_SOCKET_PORT);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
attributes.add(SemanticAttributes.NET_PEER_NAME); attributes.add(SemanticAttributes.NET_PEER_NAME);
@ -63,12 +62,12 @@ final class RpcMetricsAdvice {
attributes.add(SemanticAttributes.RPC_METHOD); attributes.add(SemanticAttributes.RPC_METHOD);
attributes.add(SemanticAttributes.RPC_GRPC_STATUS_CODE); attributes.add(SemanticAttributes.RPC_GRPC_STATUS_CODE);
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes.add(NetworkAttributes.NETWORK_TYPE); attributes.add(SemanticAttributes.NETWORK_TYPE);
attributes.add(NetworkAttributes.NETWORK_TRANSPORT); attributes.add(SemanticAttributes.NETWORK_TRANSPORT);
attributes.add(NetworkAttributes.SERVER_ADDRESS); attributes.add(SemanticAttributes.SERVER_ADDRESS);
attributes.add(NetworkAttributes.SERVER_PORT); attributes.add(SemanticAttributes.SERVER_PORT);
attributes.add(NetworkAttributes.SERVER_SOCKET_ADDRESS); attributes.add(SemanticAttributes.SERVER_SOCKET_ADDRESS);
attributes.add(NetworkAttributes.SERVER_SOCKET_PORT); attributes.add(SemanticAttributes.SERVER_SOCKET_PORT);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
attributes.add(SemanticAttributes.NET_HOST_NAME); attributes.add(SemanticAttributes.NET_HOST_NAME);

View File

@ -42,9 +42,9 @@ public final class InternalUrlAttributesExtractor<REQUEST> {
String urlQuery = getter.getUrlQuery(request); String urlQuery = getter.getUrlQuery(request);
if (emitStableUrlAttributes) { if (emitStableUrlAttributes) {
internalSet(attributes, UrlAttributes.URL_SCHEME, urlScheme); internalSet(attributes, SemanticAttributes.URL_SCHEME, urlScheme);
internalSet(attributes, UrlAttributes.URL_PATH, urlPath); internalSet(attributes, SemanticAttributes.URL_PATH, urlPath);
internalSet(attributes, UrlAttributes.URL_QUERY, urlQuery); internalSet(attributes, SemanticAttributes.URL_QUERY, urlQuery);
} }
if (emitOldHttpAttributes) { if (emitOldHttpAttributes) {
internalSet(attributes, SemanticAttributes.HTTP_SCHEME, urlScheme); internalSet(attributes, SemanticAttributes.HTTP_SCHEME, urlScheme);

View File

@ -1,30 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter.url.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 UrlAttributes {
// FIXME: remove this class and replace its usages with SemanticAttributes once schema 1.21 is
// released
public static final AttributeKey<String> URL_FULL = stringKey("url.full");
public static final AttributeKey<String> URL_SCHEME = stringKey("url.scheme");
public static final AttributeKey<String> URL_PATH = stringKey("url.path");
public static final AttributeKey<String> URL_QUERY = stringKey("url.query");
private UrlAttributes() {}
}

View File

@ -13,7 +13,7 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -56,9 +56,9 @@ class UrlAttributesExtractorTest {
extractor.onStart(startAttributes, Context.root(), request); extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(UrlAttributes.URL_SCHEME, "https"), entry(SemanticAttributes.URL_SCHEME, "https"),
entry(UrlAttributes.URL_PATH, "/test"), entry(SemanticAttributes.URL_PATH, "/test"),
entry(UrlAttributes.URL_QUERY, "q=Java")); entry(SemanticAttributes.URL_QUERY, "q=Java"));
AttributesBuilder endAttributes = Attributes.builder(); AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null); extractor.onEnd(endAttributes, Context.root(), request, null, null);

View File

@ -16,9 +16,6 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -138,37 +135,37 @@ class HttpClientAttributesExtractorBothSemconvTest {
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(SemanticAttributes.HTTP_METHOD, "POST"), entry(SemanticAttributes.HTTP_METHOD, "POST"),
entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"), entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
entry(SemanticAttributes.HTTP_URL, "http://github.com"), entry(SemanticAttributes.HTTP_URL, "http://github.com"),
entry(UrlAttributes.URL_FULL, "http://github.com"), entry(SemanticAttributes.URL_FULL, "http://github.com"),
entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"), entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"),
entry( entry(
AttributeKey.stringArrayKey("http.request.header.custom_request_header"), AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
asList("123", "456")), asList("123", "456")),
entry(SemanticAttributes.NET_PEER_NAME, "github.com"), entry(SemanticAttributes.NET_PEER_NAME, "github.com"),
entry(SemanticAttributes.NET_PEER_PORT, 123L), entry(SemanticAttributes.NET_PEER_PORT, 123L),
entry(NetworkAttributes.SERVER_ADDRESS, "github.com"), entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
entry(NetworkAttributes.SERVER_PORT, 123L)); entry(SemanticAttributes.SERVER_PORT, 123L));
AttributesBuilder endAttributes = Attributes.builder(); AttributesBuilder endAttributes = Attributes.builder();
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(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L), entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
entry(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 10L), entry(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 10L),
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L), entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
entry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L), entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L),
entry(HttpAttributes.HTTP_RESPONSE_BODY_SIZE, 20L), entry(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 20L),
entry(SemanticAttributes.HTTP_RESEND_COUNT, 2L), entry(SemanticAttributes.HTTP_RESEND_COUNT, 2L),
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(SemanticAttributes.NET_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"), entry(SemanticAttributes.NETWORK_TRANSPORT, "udp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
} }
} }

View File

@ -16,9 +16,6 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -159,18 +156,18 @@ 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(NetworkAttributes.SERVER_ADDRESS, "github.com"), entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
entry(SemanticAttributes.HTTP_METHOD, "POST"), entry(SemanticAttributes.HTTP_METHOD, "POST"),
entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"), entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
entry(SemanticAttributes.HTTP_SCHEME, "http"), entry(SemanticAttributes.HTTP_SCHEME, "http"),
entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"), entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"),
entry(UrlAttributes.URL_SCHEME, "http"), entry(SemanticAttributes.URL_SCHEME, "http"),
entry(UrlAttributes.URL_PATH, "/repositories/1"), entry(SemanticAttributes.URL_PATH, "/repositories/1"),
entry(UrlAttributes.URL_QUERY, "details=true"), entry(SemanticAttributes.URL_QUERY, "details=true"),
entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"), entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"),
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"), entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"),
entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"), entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"),
entry(NetworkAttributes.CLIENT_ADDRESS, "1.1.1.1"), entry(SemanticAttributes.CLIENT_ADDRESS, "1.1.1.1"),
entry( entry(
AttributeKey.stringArrayKey("http.request.header.custom_request_header"), AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
asList("123", "456"))); asList("123", "456")));
@ -181,17 +178,17 @@ class HttpServerAttributesExtractorBothSemconvTest {
.containsOnly( .containsOnly(
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"), entry(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
entry(NetworkAttributes.NETWORK_TRANSPORT, "udp"), entry(SemanticAttributes.NETWORK_TRANSPORT, "udp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), entry(SemanticAttributes.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(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 10L),
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L), entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
entry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L), entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L),
entry(HttpAttributes.HTTP_RESPONSE_BODY_SIZE, 20L), entry(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 20L),
entry( entry(
AttributeKey.stringArrayKey("http.response.header.custom_response_header"), AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
asList("654", "321"))); asList("654", "321")));

View File

@ -13,7 +13,6 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -126,24 +125,24 @@ class NetClientAttributesExtractorBothSemconvTest {
.containsOnly( .containsOnly(
entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"), entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"),
entry(SemanticAttributes.NET_PEER_PORT, 42L), entry(SemanticAttributes.NET_PEER_PORT, 42L),
entry(NetworkAttributes.SERVER_ADDRESS, "opentelemetry.io"), entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
entry(NetworkAttributes.SERVER_PORT, 42L)); entry(SemanticAttributes.SERVER_PORT, 42L));
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv6"), entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"), entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"), entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"),
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L), entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L),
entry(NetworkAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"), entry(SemanticAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"),
entry(NetworkAttributes.SERVER_SOCKET_ADDRESS, "1:2:3:4::"), entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1:2:3:4::"),
entry(NetworkAttributes.SERVER_SOCKET_PORT, 123L)); entry(SemanticAttributes.SERVER_SOCKET_PORT, 123L));
} }
} }

View File

@ -13,7 +13,6 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -134,24 +133,24 @@ class NetServerAttributesExtractorBothSemconvTest {
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP), entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
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(NetworkAttributes.SERVER_ADDRESS, "opentelemetry.io"), entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
entry(NetworkAttributes.SERVER_PORT, 80L), entry(SemanticAttributes.SERVER_PORT, 80L),
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6")); entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"));
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
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),
entry(NetworkAttributes.SERVER_SOCKET_ADDRESS, "4:3:2:1::"), entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "4:3:2:1::"),
entry(NetworkAttributes.SERVER_SOCKET_PORT, 8080L), entry(SemanticAttributes.SERVER_SOCKET_PORT, 8080L),
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"), entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L), entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L),
entry(NetworkAttributes.CLIENT_SOCKET_ADDRESS, "1:2:3:4::"), entry(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1:2:3:4::"),
entry(NetworkAttributes.CLIENT_SOCKET_PORT, 42L), entry(SemanticAttributes.CLIENT_SOCKET_PORT, 42L),
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv6"), entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1")); entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"));
} }

View File

@ -18,9 +18,6 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
@ -148,30 +145,30 @@ class HttpClientAttributesExtractorStableSemconvTest {
extractor.onStart(startAttributes, Context.root(), request); extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"), entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
entry(UrlAttributes.URL_FULL, "http://github.com"), entry(SemanticAttributes.URL_FULL, "http://github.com"),
entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"), entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"),
entry( entry(
AttributeKey.stringArrayKey("http.request.header.custom_request_header"), AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
asList("123", "456")), asList("123", "456")),
entry(NetworkAttributes.SERVER_ADDRESS, "github.com"), entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
entry(NetworkAttributes.SERVER_PORT, 123L)); entry(SemanticAttributes.SERVER_PORT, 123L));
AttributesBuilder endAttributes = Attributes.builder(); AttributesBuilder endAttributes = Attributes.builder();
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(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 10L), entry(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 10L),
entry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
entry(HttpAttributes.HTTP_RESPONSE_BODY_SIZE, 20L), entry(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 20L),
entry(SemanticAttributes.HTTP_RESEND_COUNT, 2L), entry(SemanticAttributes.HTTP_RESEND_COUNT, 2L),
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(NetworkAttributes.NETWORK_TRANSPORT, "udp"), entry(SemanticAttributes.NETWORK_TRANSPORT, "udp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
} }
@ParameterizedTest @ParameterizedTest
@ -195,9 +192,9 @@ class HttpClientAttributesExtractorStableSemconvTest {
if (extractedTransport != null) { if (extractedTransport != null) {
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(NetworkAttributes.NETWORK_TRANSPORT, extractedTransport); .containsEntry(SemanticAttributes.NETWORK_TRANSPORT, extractedTransport);
} else { } else {
assertThat(attributes.build()).doesNotContainKey(NetworkAttributes.NETWORK_TRANSPORT); assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NETWORK_TRANSPORT);
} }
} }
@ -231,8 +228,8 @@ class HttpClientAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, requestMethod) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
.doesNotContainKey(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL); .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
} }
@ParameterizedTest @ParameterizedTest
@ -249,8 +246,8 @@ class HttpClientAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
} }
@ParameterizedTest @ParameterizedTest
@ -267,8 +264,8 @@ class HttpClientAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
} }
@ParameterizedTest @ParameterizedTest
@ -287,8 +284,8 @@ class HttpClientAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, requestMethod) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
.doesNotContainKey(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL); .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
} }
@ParameterizedTest @ParameterizedTest
@ -307,7 +304,7 @@ class HttpClientAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
} }
} }

View File

@ -15,11 +15,9 @@ import io.opentelemetry.api.trace.TraceFlags;
import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.SemanticAttributes;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -36,25 +34,25 @@ class HttpClientExperimentalMetricsStableSemconvTest {
Attributes requestAttributes = Attributes requestAttributes =
Attributes.builder() Attributes.builder()
.put(HttpAttributes.HTTP_REQUEST_METHOD, "GET") .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
.put(UrlAttributes.URL_FULL, "https://localhost:1234/") .put(SemanticAttributes.URL_FULL, "https://localhost:1234/")
.put(UrlAttributes.URL_SCHEME, "https") .put(SemanticAttributes.URL_SCHEME, "https")
.put(UrlAttributes.URL_PATH, "/") .put(SemanticAttributes.URL_PATH, "/")
.put(UrlAttributes.URL_QUERY, "q=a") .put(SemanticAttributes.URL_QUERY, "q=a")
.put(NetworkAttributes.SERVER_ADDRESS, "localhost") .put(SemanticAttributes.SERVER_ADDRESS, "localhost")
.put(NetworkAttributes.SERVER_PORT, 1234) .put(SemanticAttributes.SERVER_PORT, 1234)
.build(); .build();
Attributes responseAttributes = Attributes responseAttributes =
Attributes.builder() Attributes.builder()
.put(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200) .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
.put(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 100) .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
.put(HttpAttributes.HTTP_RESPONSE_BODY_SIZE, 200) .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
.put(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http") .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
.put(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0") .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
.put(NetworkAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4") .put(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4")
.put(NetworkAttributes.SERVER_SOCKET_DOMAIN, "somehost20") .put(SemanticAttributes.SERVER_SOCKET_DOMAIN, "somehost20")
.put(NetworkAttributes.SERVER_SOCKET_PORT, 8080) .put(SemanticAttributes.SERVER_SOCKET_PORT, 8080)
.build(); .build();
Context parent = Context parent =
@ -90,16 +88,18 @@ class HttpClientExperimentalMetricsStableSemconvTest {
point point
.hasSum(100 /* bytes */) .hasSum(100 /* bytes */)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
equalTo(NetworkAttributes.SERVER_ADDRESS, "localhost"),
equalTo(NetworkAttributes.SERVER_PORT, 1234),
equalTo( equalTo(
NetworkAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4")) SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
equalTo(SemanticAttributes.SERVER_PORT, 1234),
equalTo(
SemanticAttributes.SERVER_SOCKET_ADDRESS,
"1.2.3.4"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar
@ -116,16 +116,18 @@ class HttpClientExperimentalMetricsStableSemconvTest {
point point
.hasSum(200 /* bytes */) .hasSum(200 /* bytes */)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
equalTo(NetworkAttributes.SERVER_ADDRESS, "localhost"),
equalTo(NetworkAttributes.SERVER_PORT, 1234),
equalTo( equalTo(
NetworkAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4")) SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
equalTo(SemanticAttributes.SERVER_PORT, 1234),
equalTo(
SemanticAttributes.SERVER_SOCKET_ADDRESS,
"1.2.3.4"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar

View File

@ -15,11 +15,9 @@ import io.opentelemetry.api.trace.TraceFlags;
import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.SemanticAttributes;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -38,25 +36,25 @@ class HttpClientMetricsStableSemconvTest {
Attributes requestAttributes = Attributes requestAttributes =
Attributes.builder() Attributes.builder()
.put(HttpAttributes.HTTP_REQUEST_METHOD, "GET") .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
.put(UrlAttributes.URL_FULL, "https://localhost:1234/") .put(SemanticAttributes.URL_FULL, "https://localhost:1234/")
.put(UrlAttributes.URL_SCHEME, "https") .put(SemanticAttributes.URL_SCHEME, "https")
.put(UrlAttributes.URL_PATH, "/") .put(SemanticAttributes.URL_PATH, "/")
.put(UrlAttributes.URL_QUERY, "q=a") .put(SemanticAttributes.URL_QUERY, "q=a")
.put(NetworkAttributes.SERVER_ADDRESS, "localhost") .put(SemanticAttributes.SERVER_ADDRESS, "localhost")
.put(NetworkAttributes.SERVER_PORT, 1234) .put(SemanticAttributes.SERVER_PORT, 1234)
.build(); .build();
Attributes responseAttributes = Attributes responseAttributes =
Attributes.builder() Attributes.builder()
.put(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200) .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
.put(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 100) .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
.put(HttpAttributes.HTTP_RESPONSE_BODY_SIZE, 200) .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
.put(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http") .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
.put(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0") .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
.put(NetworkAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4") .put(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4")
.put(NetworkAttributes.SERVER_SOCKET_DOMAIN, "somehost20") .put(SemanticAttributes.SERVER_SOCKET_DOMAIN, "somehost20")
.put(NetworkAttributes.SERVER_SOCKET_PORT, 8080) .put(SemanticAttributes.SERVER_SOCKET_PORT, 8080)
.build(); .build();
Context parent = Context parent =
@ -92,16 +90,18 @@ class HttpClientMetricsStableSemconvTest {
point point
.hasSum(0.15 /* seconds */) .hasSum(0.15 /* seconds */)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
equalTo(NetworkAttributes.SERVER_ADDRESS, "localhost"),
equalTo(NetworkAttributes.SERVER_PORT, 1234),
equalTo( equalTo(
NetworkAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4")) SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
equalTo(SemanticAttributes.SERVER_PORT, 1234),
equalTo(
SemanticAttributes.SERVER_SOCKET_ADDRESS,
"1.2.3.4"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar

View File

@ -18,9 +18,6 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
@ -186,14 +183,14 @@ class HttpServerAttributesExtractorStableSemconvTest {
extractor.onStart(startAttributes, Context.root(), request); extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.SERVER_ADDRESS, "github.com"), entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
entry(HttpAttributes.HTTP_REQUEST_METHOD, "POST"), entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
entry(UrlAttributes.URL_SCHEME, "http"), entry(SemanticAttributes.URL_SCHEME, "http"),
entry(UrlAttributes.URL_PATH, "/repositories/1"), entry(SemanticAttributes.URL_PATH, "/repositories/1"),
entry(UrlAttributes.URL_QUERY, "details=true"), entry(SemanticAttributes.URL_QUERY, "details=true"),
entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"), entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"),
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"), entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"),
entry(NetworkAttributes.CLIENT_ADDRESS, "1.1.1.1"), entry(SemanticAttributes.CLIENT_ADDRESS, "1.1.1.1"),
entry( entry(
AttributeKey.stringArrayKey("http.request.header.custom_request_header"), AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
asList("123", "456"))); asList("123", "456")));
@ -202,14 +199,14 @@ 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(SemanticAttributes.NETWORK_TRANSPORT, "udp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), entry(SemanticAttributes.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(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 10L),
entry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 202L), entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
entry(HttpAttributes.HTTP_RESPONSE_BODY_SIZE, 20L), entry(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 20L),
entry( entry(
AttributeKey.stringArrayKey("http.response.header.custom_response_header"), AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
asList("654", "321"))); asList("654", "321")));
@ -236,9 +233,9 @@ class HttpServerAttributesExtractorStableSemconvTest {
if (extractedTransport != null) { if (extractedTransport != null) {
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(NetworkAttributes.NETWORK_TRANSPORT, extractedTransport); .containsEntry(SemanticAttributes.NETWORK_TRANSPORT, extractedTransport);
} else { } else {
assertThat(attributes.build()).doesNotContainKey(NetworkAttributes.NETWORK_TRANSPORT); assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.NETWORK_TRANSPORT);
} }
} }
@ -272,8 +269,8 @@ class HttpServerAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, requestMethod) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
.doesNotContainKey(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL); .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
} }
@ParameterizedTest @ParameterizedTest
@ -290,8 +287,8 @@ class HttpServerAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
} }
@ParameterizedTest @ParameterizedTest
@ -308,8 +305,8 @@ class HttpServerAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
} }
@ParameterizedTest @ParameterizedTest
@ -328,8 +325,8 @@ class HttpServerAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, requestMethod) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
.doesNotContainKey(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL); .doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
} }
@ParameterizedTest @ParameterizedTest
@ -348,7 +345,7 @@ class HttpServerAttributesExtractorStableSemconvTest {
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null); extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
assertThat(attributes.build()) assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER) .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
.containsEntry(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod); .containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
} }
} }

View File

@ -15,11 +15,9 @@ import io.opentelemetry.api.trace.TraceFlags;
import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.SemanticAttributes;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -36,27 +34,27 @@ class HttpServerExperimentalMetricsStableSemconvTest {
Attributes requestAttributes = Attributes requestAttributes =
Attributes.builder() Attributes.builder()
.put(HttpAttributes.HTTP_REQUEST_METHOD, "GET") .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
.put(UrlAttributes.URL_SCHEME, "https") .put(SemanticAttributes.URL_SCHEME, "https")
.put(UrlAttributes.URL_PATH, "/") .put(SemanticAttributes.URL_PATH, "/")
.put(UrlAttributes.URL_QUERY, "q=a") .put(SemanticAttributes.URL_QUERY, "q=a")
.put(NetworkAttributes.NETWORK_TRANSPORT, "tcp") .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
.put(NetworkAttributes.NETWORK_TYPE, "ipv4") .put(SemanticAttributes.NETWORK_TYPE, "ipv4")
.put(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http") .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
.put(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0") .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
.put(NetworkAttributes.SERVER_ADDRESS, "localhost") .put(SemanticAttributes.SERVER_ADDRESS, "localhost")
.put(NetworkAttributes.SERVER_PORT, 1234) .put(SemanticAttributes.SERVER_PORT, 1234)
.build(); .build();
Attributes responseAttributes = Attributes responseAttributes =
Attributes.builder() Attributes.builder()
.put(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200) .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
.put(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 100) .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
.put(HttpAttributes.HTTP_RESPONSE_BODY_SIZE, 200) .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
.put(NetworkAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4") .put(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4")
.put(NetworkAttributes.CLIENT_SOCKET_PORT, 8080) .put(SemanticAttributes.CLIENT_SOCKET_PORT, 8080)
.put(NetworkAttributes.SERVER_SOCKET_ADDRESS, "4.3.2.1") .put(SemanticAttributes.SERVER_SOCKET_ADDRESS, "4.3.2.1")
.put(NetworkAttributes.SERVER_SOCKET_PORT, 9090) .put(SemanticAttributes.SERVER_SOCKET_PORT, 9090)
.build(); .build();
SpanContext spanContext1 = SpanContext spanContext1 =
@ -90,8 +88,8 @@ class HttpServerExperimentalMetricsStableSemconvTest {
point point
.hasValue(1) .hasValue(1)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(UrlAttributes.URL_SCHEME, "https")) equalTo(SemanticAttributes.URL_SCHEME, "https"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar
@ -113,8 +111,8 @@ class HttpServerExperimentalMetricsStableSemconvTest {
point point
.hasValue(2) .hasValue(2)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(UrlAttributes.URL_SCHEME, "https")) equalTo(SemanticAttributes.URL_SCHEME, "https"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar
@ -135,8 +133,8 @@ class HttpServerExperimentalMetricsStableSemconvTest {
point point
.hasValue(1) .hasValue(1)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(UrlAttributes.URL_SCHEME, "https")) equalTo(SemanticAttributes.URL_SCHEME, "https"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar
@ -153,13 +151,14 @@ class HttpServerExperimentalMetricsStableSemconvTest {
point point
.hasSum(100 /* bytes */) .hasSum(100 /* bytes */)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
equalTo(UrlAttributes.URL_SCHEME, "https")) equalTo(
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
equalTo(SemanticAttributes.URL_SCHEME, "https"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar
@ -176,13 +175,14 @@ class HttpServerExperimentalMetricsStableSemconvTest {
point point
.hasSum(200 /* bytes */) .hasSum(200 /* bytes */)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
equalTo(UrlAttributes.URL_SCHEME, "https")) equalTo(
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
equalTo(SemanticAttributes.URL_SCHEME, "https"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar

View File

@ -15,9 +15,6 @@ import io.opentelemetry.api.trace.TraceFlags;
import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
@ -39,27 +36,27 @@ class HttpServerMetricsStableSemconvTest {
Attributes requestAttributes = Attributes requestAttributes =
Attributes.builder() Attributes.builder()
.put(HttpAttributes.HTTP_REQUEST_METHOD, "GET") .put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
.put(UrlAttributes.URL_SCHEME, "https") .put(SemanticAttributes.URL_SCHEME, "https")
.put(UrlAttributes.URL_PATH, "/") .put(SemanticAttributes.URL_PATH, "/")
.put(UrlAttributes.URL_QUERY, "q=a") .put(SemanticAttributes.URL_QUERY, "q=a")
.put(NetworkAttributes.NETWORK_TRANSPORT, "tcp") .put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
.put(NetworkAttributes.NETWORK_TYPE, "ipv4") .put(SemanticAttributes.NETWORK_TYPE, "ipv4")
.put(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http") .put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
.put(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0") .put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
.put(NetworkAttributes.SERVER_ADDRESS, "localhost") .put(SemanticAttributes.SERVER_ADDRESS, "localhost")
.put(NetworkAttributes.SERVER_PORT, 1234) .put(SemanticAttributes.SERVER_PORT, 1234)
.build(); .build();
Attributes responseAttributes = Attributes responseAttributes =
Attributes.builder() Attributes.builder()
.put(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200) .put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
.put(HttpAttributes.HTTP_REQUEST_BODY_SIZE, 100) .put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
.put(HttpAttributes.HTTP_RESPONSE_BODY_SIZE, 200) .put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
.put(NetworkAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4") .put(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4")
.put(NetworkAttributes.CLIENT_SOCKET_PORT, 8080) .put(SemanticAttributes.CLIENT_SOCKET_PORT, 8080)
.put(NetworkAttributes.SERVER_SOCKET_ADDRESS, "4.3.2.1") .put(SemanticAttributes.SERVER_SOCKET_ADDRESS, "4.3.2.1")
.put(NetworkAttributes.SERVER_SOCKET_PORT, 9090) .put(SemanticAttributes.SERVER_SOCKET_PORT, 9090)
.build(); .build();
SpanContext spanContext1 = SpanContext spanContext1 =
@ -96,13 +93,14 @@ class HttpServerMetricsStableSemconvTest {
point point
.hasSum(0.15 /* seconds */) .hasSum(0.15 /* seconds */)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(HttpAttributes.HTTP_REQUEST_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
equalTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
equalTo( equalTo(
NetworkAttributes.NETWORK_PROTOCOL_VERSION, "2.0"), SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
equalTo(UrlAttributes.URL_SCHEME, "https")) equalTo(
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
equalTo(SemanticAttributes.URL_SCHEME, "https"))
.hasExemplarsSatisfying( .hasExemplarsSatisfying(
exemplar -> exemplar ->
exemplar exemplar
@ -141,8 +139,8 @@ class HttpServerMetricsStableSemconvTest {
Attributes requestAttributes = Attributes requestAttributes =
Attributes.builder() Attributes.builder()
.put(NetworkAttributes.SERVER_ADDRESS, "host") .put(SemanticAttributes.SERVER_ADDRESS, "host")
.put(UrlAttributes.URL_SCHEME, "https") .put(SemanticAttributes.URL_SCHEME, "https")
.build(); .build();
Attributes responseAttributes = Attributes responseAttributes =
@ -168,7 +166,7 @@ class HttpServerMetricsStableSemconvTest {
point point
.hasSum(0.100 /* seconds */) .hasSum(0.100 /* seconds */)
.hasAttributesSatisfying( .hasAttributesSatisfying(
equalTo(UrlAttributes.URL_SCHEME, "https"), equalTo(SemanticAttributes.URL_SCHEME, "https"),
equalTo( equalTo(
SemanticAttributes.HTTP_ROUTE, "/test/{id}"))))); SemanticAttributes.HTTP_ROUTE, "/test/{id}")))));
} }

View File

@ -13,7 +13,7 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -123,17 +123,17 @@ class NetClientAttributesExtractorStableSemconvTest {
// then // then
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.SERVER_ADDRESS, "opentelemetry.io"), entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
entry(NetworkAttributes.SERVER_PORT, 42L)); entry(SemanticAttributes.SERVER_PORT, 42L));
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv6"), entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
entry(NetworkAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"), entry(SemanticAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"),
entry(NetworkAttributes.SERVER_SOCKET_ADDRESS, "1:2:3:4::"), entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1:2:3:4::"),
entry(NetworkAttributes.SERVER_SOCKET_PORT, 123L)); entry(SemanticAttributes.SERVER_SOCKET_PORT, 123L));
} }
} }

View File

@ -13,7 +13,7 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -130,18 +130,18 @@ class NetServerAttributesExtractorStableSemconvTest {
// then // then
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.SERVER_ADDRESS, "opentelemetry.io"), entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
entry(NetworkAttributes.SERVER_PORT, 80L)); entry(SemanticAttributes.SERVER_PORT, 80L));
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv6"), entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1"), entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
entry(NetworkAttributes.SERVER_SOCKET_ADDRESS, "4:3:2:1::"), entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "4:3:2:1::"),
entry(NetworkAttributes.SERVER_SOCKET_PORT, 8080L), entry(SemanticAttributes.SERVER_SOCKET_PORT, 8080L),
entry(NetworkAttributes.CLIENT_SOCKET_ADDRESS, "1:2:3:4::"), entry(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1:2:3:4::"),
entry(NetworkAttributes.CLIENT_SOCKET_PORT, 42L)); entry(SemanticAttributes.CLIENT_SOCKET_PORT, 42L));
} }
} }

View File

@ -12,7 +12,7 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -61,8 +61,8 @@ class ClientAttributesExtractorInetSocketAddressTest {
extractor.onEnd(endAttributes, Context.root(), address, null, null); extractor.onEnd(endAttributes, Context.root(), address, null, null);
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.CLIENT_SOCKET_ADDRESS, address.getAddress().getHostAddress()), entry(SemanticAttributes.CLIENT_SOCKET_ADDRESS, address.getAddress().getHostAddress()),
entry(NetworkAttributes.CLIENT_SOCKET_PORT, 456L)); entry(SemanticAttributes.CLIENT_SOCKET_PORT, 456L));
} }
@Test @Test

View File

@ -13,7 +13,7 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -66,15 +66,15 @@ class ClientAttributesExtractorTest {
extractor.onStart(startAttributes, Context.root(), request); extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.CLIENT_ADDRESS, "opentelemetry.io"), entry(SemanticAttributes.CLIENT_ADDRESS, "opentelemetry.io"),
entry(NetworkAttributes.CLIENT_PORT, 80L)); entry(SemanticAttributes.CLIENT_PORT, 80L));
AttributesBuilder endAttributes = Attributes.builder(); AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null); extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4"), entry(SemanticAttributes.CLIENT_SOCKET_ADDRESS, "1.2.3.4"),
entry(NetworkAttributes.CLIENT_SOCKET_PORT, 8080L)); entry(SemanticAttributes.CLIENT_SOCKET_PORT, 8080L));
} }
@Test @Test
@ -124,8 +124,8 @@ class ClientAttributesExtractorTest {
extractor.onStart(startAttributes, Context.root(), request); extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.CLIENT_ADDRESS, "opentelemetry.io"), entry(SemanticAttributes.CLIENT_ADDRESS, "opentelemetry.io"),
entry(NetworkAttributes.CLIENT_PORT, 80L)); entry(SemanticAttributes.CLIENT_PORT, 80L));
AttributesBuilder endAttributes = Attributes.builder(); AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null); extractor.onEnd(endAttributes, Context.root(), request, null, null);

View File

@ -13,7 +13,7 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -68,10 +68,10 @@ class NetworkAttributesExtractorTest {
extractor.onEnd(endAttributes, Context.root(), request, null, null); extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"), entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
entry(NetworkAttributes.NETWORK_TYPE, "ipv4"), entry(SemanticAttributes.NETWORK_TYPE, "ipv4"),
entry(NetworkAttributes.NETWORK_PROTOCOL_NAME, "http"), entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
entry(NetworkAttributes.NETWORK_PROTOCOL_VERSION, "1.1")); entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
} }
@Test @Test

View File

@ -12,7 +12,7 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -61,9 +61,9 @@ class ServerAttributesExtractorInetSocketAddressTest {
extractor.onEnd(endAttributes, Context.root(), address, null, null); extractor.onEnd(endAttributes, Context.root(), address, null, null);
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.SERVER_SOCKET_DOMAIN, "api.github.com"), entry(SemanticAttributes.SERVER_SOCKET_DOMAIN, "api.github.com"),
entry(NetworkAttributes.SERVER_SOCKET_ADDRESS, address.getAddress().getHostAddress()), entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, address.getAddress().getHostAddress()),
entry(NetworkAttributes.SERVER_SOCKET_PORT, 456L)); entry(SemanticAttributes.SERVER_SOCKET_PORT, 456L));
} }
@Test @Test

View File

@ -13,7 +13,7 @@ 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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -73,16 +73,16 @@ class ServerAttributesExtractorTest {
extractor.onStart(startAttributes, Context.root(), request); extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.SERVER_ADDRESS, "opentelemetry.io"), entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
entry(NetworkAttributes.SERVER_PORT, 80L)); entry(SemanticAttributes.SERVER_PORT, 80L));
AttributesBuilder endAttributes = Attributes.builder(); AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null); extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"), entry(SemanticAttributes.SERVER_SOCKET_DOMAIN, "proxy.opentelemetry.io"),
entry(NetworkAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4"), entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4"),
entry(NetworkAttributes.SERVER_SOCKET_PORT, 8080L)); entry(SemanticAttributes.SERVER_SOCKET_PORT, 8080L));
} }
@Test @Test
@ -113,12 +113,12 @@ class ServerAttributesExtractorTest {
AttributesBuilder startAttributes = Attributes.builder(); AttributesBuilder startAttributes = Attributes.builder();
extractor.onStart(startAttributes, Context.root(), request); extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly(entry(NetworkAttributes.SERVER_ADDRESS, "opentelemetry.io")); .containsOnly(entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"));
AttributesBuilder endAttributes = Attributes.builder(); AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null); extractor.onEnd(endAttributes, Context.root(), request, null, null);
assertThat(endAttributes.build()) assertThat(endAttributes.build())
.containsOnly(entry(NetworkAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4")); .containsOnly(entry(SemanticAttributes.SERVER_SOCKET_ADDRESS, "1.2.3.4"));
} }
@Test @Test
@ -137,8 +137,8 @@ class ServerAttributesExtractorTest {
extractor.onStart(startAttributes, Context.root(), request); extractor.onStart(startAttributes, Context.root(), request);
assertThat(startAttributes.build()) assertThat(startAttributes.build())
.containsOnly( .containsOnly(
entry(NetworkAttributes.SERVER_ADDRESS, "1.2.3.4"), entry(SemanticAttributes.SERVER_ADDRESS, "1.2.3.4"),
entry(NetworkAttributes.SERVER_PORT, 80L)); entry(SemanticAttributes.SERVER_PORT, 80L));
AttributesBuilder endAttributes = Attributes.builder(); AttributesBuilder endAttributes = Attributes.builder();
extractor.onEnd(endAttributes, Context.root(), request, null, null); extractor.onEnd(endAttributes, Context.root(), request, null, null);

View File

@ -5,12 +5,12 @@
package io.opentelemetry.instrumentation.awslambdaevents.v2_2.internal; package io.opentelemetry.instrumentation.awslambdaevents.v2_2.internal;
import static io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes.HTTP_RESPONSE_STATUS_CODE;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import static io.opentelemetry.instrumentation.api.internal.HttpConstants._OTHER; import static io.opentelemetry.instrumentation.api.internal.HttpConstants._OTHER;
import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.emptyIfNull; import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.emptyIfNull;
import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.lowercaseMap; import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.lowercaseMap;
import static io.opentelemetry.semconv.SemanticAttributes.FAAS_TRIGGER; import static io.opentelemetry.semconv.SemanticAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE; import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE;
import static io.opentelemetry.semconv.SemanticAttributes.USER_AGENT_ORIGINAL; import static io.opentelemetry.semconv.SemanticAttributes.USER_AGENT_ORIGINAL;
@ -19,8 +19,6 @@ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
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.awslambdacore.v1_0.AwsLambdaRequest; import io.opentelemetry.instrumentation.awslambdacore.v1_0.AwsLambdaRequest;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
@ -54,10 +52,10 @@ final class ApiGatewayProxyAttributesExtractor
String method = request.getHttpMethod(); String method = request.getHttpMethod();
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
if (method == null || knownMethods.contains(method)) { if (method == null || knownMethods.contains(method)) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
} else { } else {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
} }
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
@ -73,7 +71,7 @@ final class ApiGatewayProxyAttributesExtractor
String httpUrl = getHttpUrl(request, headers); String httpUrl = getHttpUrl(request, headers);
if (httpUrl != null) { if (httpUrl != null) {
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, UrlAttributes.URL_FULL, httpUrl); internalSet(attributes, SemanticAttributes.URL_FULL, httpUrl);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {

View File

@ -30,8 +30,6 @@ import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRoute; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRoute;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRouteSource; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRouteSource;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
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.javaagent.bootstrap.internal.CommonConfig; import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection; import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection;
@ -102,7 +100,7 @@ class HttpSpanDecorator extends BaseSpanDecorator {
String httpUrl = getHttpUrl(exchange, endpoint); String httpUrl = getHttpUrl(exchange, endpoint);
if (httpUrl != null) { if (httpUrl != null) {
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, UrlAttributes.URL_FULL, httpUrl); internalSet(attributes, SemanticAttributes.URL_FULL, httpUrl);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
@ -113,10 +111,10 @@ class HttpSpanDecorator extends BaseSpanDecorator {
String method = getHttpMethod(exchange, endpoint); String method = getHttpMethod(exchange, endpoint);
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
if (method == null || knownMethods.contains(method)) { if (method == null || knownMethods.contains(method)) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
} else { } else {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
} }
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
@ -185,7 +183,7 @@ class HttpSpanDecorator extends BaseSpanDecorator {
Object responseCode = exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE); Object responseCode = exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE);
if (responseCode instanceof Integer) { if (responseCode instanceof Integer) {
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes.put(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, (Integer) responseCode); attributes.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, (Integer) responseCode);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
attributes.put(SemanticAttributes.HTTP_STATUS_CODE, (Integer) responseCode); attributes.put(SemanticAttributes.HTTP_STATUS_CODE, (Integer) responseCode);

View File

@ -12,9 +12,6 @@ import io.opentelemetry.api.common.AttributeKey;
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.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
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.cache.Cache; import io.opentelemetry.instrumentation.api.internal.cache.Cache;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
@ -46,8 +43,8 @@ public class ElasticsearchClientAttributeExtractor
HttpHost host = response.getHost(); HttpHost host = response.getHost();
if (host != null) { if (host != null) {
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, NetworkAttributes.SERVER_ADDRESS, host.getHostName()); internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, host.getHostName());
internalSet(attributes, NetworkAttributes.SERVER_PORT, (long) host.getPort()); internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) host.getPort());
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
internalSet(attributes, SemanticAttributes.NET_PEER_NAME, host.getHostName()); internalSet(attributes, SemanticAttributes.NET_PEER_NAME, host.getHostName());
@ -63,7 +60,7 @@ public class ElasticsearchClientAttributeExtractor
String fullUrl = response.getHost().toURI() + uri; String fullUrl = response.getHost().toURI() + uri;
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, UrlAttributes.URL_FULL, fullUrl); internalSet(attributes, SemanticAttributes.URL_FULL, fullUrl);
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {
@ -95,10 +92,10 @@ public class ElasticsearchClientAttributeExtractor
String method = request.getMethod(); String method = request.getMethod();
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
if (method == null || knownMethods.contains(method)) { if (method == null || knownMethods.contains(method)) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
} else { } else {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
} }
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {

View File

@ -12,7 +12,6 @@ import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.Span;
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.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -54,11 +53,11 @@ public class HttpMethodAttributeExtractor<
// The getOutputStream() has transformed "GET" into "POST" // The getOutputStream() has transformed "GET" into "POST"
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
if (knownMethods.contains(method)) { if (knownMethods.contains(method)) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
attributes.remove(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL); attributes.remove(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
} else { } else {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method); internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
} }
} }
if (SemconvStability.emitOldHttpSemconv()) { if (SemconvStability.emitOldHttpSemconv()) {

View File

@ -18,7 +18,7 @@ import io.netty.handler.codec.http.HttpHeaders
import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpMethod
import io.netty.handler.codec.http.HttpVersion import io.netty.handler.codec.http.HttpVersion
import io.netty.handler.ssl.SslHandler import io.netty.handler.ssl.SslHandler
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.api.internal.SemconvStability
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestServer import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestServer
@ -100,11 +100,11 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }
@ -125,11 +125,11 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_SOCKET_DOMAIN" uri.host "$SemanticAttributes.SERVER_SOCKET_DOMAIN" uri.host
"$NetworkAttributes.SERVER_SOCKET_PORT" uri.port "$SemanticAttributes.SERVER_SOCKET_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }
@ -178,11 +178,11 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }
@ -200,11 +200,11 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_SOCKET_DOMAIN" uri.host "$SemanticAttributes.SERVER_SOCKET_DOMAIN" uri.host
"$NetworkAttributes.SERVER_SOCKET_PORT" uri.port "$SemanticAttributes.SERVER_SOCKET_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }

View File

@ -16,7 +16,7 @@ import io.netty.handler.codec.http.HttpClientCodec
import io.netty.handler.codec.http.HttpHeaders import io.netty.handler.codec.http.HttpHeaders
import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpMethod
import io.netty.handler.codec.http.HttpVersion import io.netty.handler.codec.http.HttpVersion
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.api.internal.SemconvStability
import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.InstrumentationSpecification
@ -116,11 +116,11 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }
@ -175,11 +175,11 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null }
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" { it == "127.0.0.1" || it == null } "$SemanticAttributes.SERVER_SOCKET_ADDRESS" { it == "127.0.0.1" || it == null }
} }
} }
} }

View File

@ -20,7 +20,7 @@ import io.netty.handler.codec.http.HttpVersion
import io.netty.handler.ssl.SslContext import io.netty.handler.ssl.SslContext
import io.netty.handler.ssl.SslContextBuilder import io.netty.handler.ssl.SslContextBuilder
import io.netty.handler.ssl.SslHandler import io.netty.handler.ssl.SslHandler
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.api.internal.SemconvStability
import io.opentelemetry.instrumentation.netty.v4_1.ClientHandler import io.opentelemetry.instrumentation.netty.v4_1.ClientHandler
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
@ -104,8 +104,8 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
} }
} }
} }
@ -123,11 +123,11 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }
@ -148,11 +148,11 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_SOCKET_DOMAIN" uri.host "$SemanticAttributes.SERVER_SOCKET_DOMAIN" uri.host
"$NetworkAttributes.SERVER_SOCKET_PORT" uri.port "$SemanticAttributes.SERVER_SOCKET_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }
@ -202,8 +202,8 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
} }
} }
} }
@ -221,11 +221,11 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }
@ -243,11 +243,11 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification {
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_SOCKET_DOMAIN" uri.host "$SemanticAttributes.SERVER_SOCKET_DOMAIN" uri.host
"$NetworkAttributes.SERVER_SOCKET_PORT" uri.port "$SemanticAttributes.SERVER_SOCKET_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }

View File

@ -16,7 +16,7 @@ import io.netty.handler.codec.http.HttpClientCodec
import io.netty.handler.codec.http.HttpHeaderNames import io.netty.handler.codec.http.HttpHeaderNames
import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpMethod
import io.netty.handler.codec.http.HttpVersion import io.netty.handler.codec.http.HttpVersion
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
import io.opentelemetry.instrumentation.api.internal.SemconvStability import io.opentelemetry.instrumentation.api.internal.SemconvStability
import io.opentelemetry.instrumentation.netty.v4_1.ClientHandler import io.opentelemetry.instrumentation.netty.v4_1.ClientHandler
import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.AgentTestTrait
@ -118,8 +118,8 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
} }
} }
} }
@ -137,11 +137,11 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.SERVER_SOCKET_ADDRESS" "127.0.0.1"
} }
} }
} }
@ -195,8 +195,8 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
} }
} }
} }
@ -216,11 +216,11 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.NETWORK_TRANSPORT" "tcp" "$SemanticAttributes.NETWORK_TRANSPORT" "tcp"
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == null } "$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null }
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.SERVER_SOCKET_ADDRESS" { it == "127.0.0.1" || it == null } "$SemanticAttributes.SERVER_SOCKET_ADDRESS" { it == "127.0.0.1" || it == null }
} }
} }
} }

View File

@ -7,9 +7,7 @@ import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.trace.Span import io.opentelemetry.api.trace.Span
import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.api.trace.SpanKind
import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.api.trace.StatusCode
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
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.test.AgentTestTrait import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.base.HttpServerTest import io.opentelemetry.instrumentation.test.base.HttpServerTest
@ -166,20 +164,20 @@ class UndertowServerTest extends HttpServerTest<Undertow> implements AgentTestTr
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP "$SemanticAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP
"$UrlAttributes.URL_SCHEME" uri.getScheme() "$SemanticAttributes.URL_SCHEME" uri.getScheme()
"$UrlAttributes.URL_PATH" uri.getPath() "$SemanticAttributes.URL_PATH" uri.getPath()
"$HttpAttributes.HTTP_REQUEST_METHOD" "GET" "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
"$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
"$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT
"$HttpAttributes.HTTP_RESPONSE_BODY_SIZE" Long "$SemanticAttributes.HTTP_RESPONSE_BODY_SIZE" Long
"$NetworkAttributes.NETWORK_PROTOCOL_NAME" "http" "$SemanticAttributes.NETWORK_PROTOCOL_NAME" "http"
"$NetworkAttributes.NETWORK_PROTOCOL_VERSION" "1.1" "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.CLIENT_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.CLIENT_SOCKET_ADDRESS" "127.0.0.1"
"$NetworkAttributes.CLIENT_SOCKET_PORT" Long "$SemanticAttributes.CLIENT_SOCKET_PORT" Long
} }
} }
} }
@ -238,20 +236,20 @@ class UndertowServerTest extends HttpServerTest<Undertow> implements AgentTestTr
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
attributes { attributes {
"$NetworkAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP "$SemanticAttributes.CLIENT_ADDRESS" TEST_CLIENT_IP
"$UrlAttributes.URL_SCHEME" uri.getScheme() "$SemanticAttributes.URL_SCHEME" uri.getScheme()
"$UrlAttributes.URL_PATH" uri.getPath() "$SemanticAttributes.URL_PATH" uri.getPath()
"$HttpAttributes.HTTP_REQUEST_METHOD" "GET" "$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
"$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200 "$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
"$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT "$SemanticAttributes.USER_AGENT_ORIGINAL" TEST_USER_AGENT
"$HttpAttributes.HTTP_RESPONSE_BODY_SIZE" Long "$SemanticAttributes.HTTP_RESPONSE_BODY_SIZE" Long
"$NetworkAttributes.NETWORK_PROTOCOL_NAME" "http" "$SemanticAttributes.NETWORK_PROTOCOL_NAME" "http"
"$NetworkAttributes.NETWORK_PROTOCOL_VERSION" "1.1" "$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
"$NetworkAttributes.NETWORK_TYPE" "ipv4" "$SemanticAttributes.NETWORK_TYPE" "ipv4"
"$NetworkAttributes.SERVER_ADDRESS" uri.host "$SemanticAttributes.SERVER_ADDRESS" uri.host
"$NetworkAttributes.SERVER_PORT" uri.port "$SemanticAttributes.SERVER_PORT" uri.port
"$NetworkAttributes.CLIENT_SOCKET_ADDRESS" "127.0.0.1" "$SemanticAttributes.CLIENT_SOCKET_ADDRESS" "127.0.0.1"
"$NetworkAttributes.CLIENT_SOCKET_PORT" Long "$SemanticAttributes.CLIENT_SOCKET_PORT" Long
} }
} }
} }

View File

@ -17,8 +17,6 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.test.utils.PortUtils; import io.opentelemetry.instrumentation.test.utils.PortUtils;
@ -137,7 +135,7 @@ public abstract class AbstractHttpClientTest<REQUEST> implements HttpClientTypeA
span -> span ->
assertClientSpan(span, uri, HttpConstants._OTHER, responseCode, null) assertClientSpan(span, uri, HttpConstants._OTHER, responseCode, null)
.hasNoParent() .hasNoParent()
.hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method))); .hasAttribute(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method)));
} }
@ParameterizedTest @ParameterizedTest
@ -999,12 +997,12 @@ public abstract class AbstractHttpClientTest<REQUEST> implements HttpClientTypeA
assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP); assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP);
} }
if (SemconvStability.emitStableHttpSemconv() if (SemconvStability.emitStableHttpSemconv()
&& attrs.get(NetworkAttributes.NETWORK_TRANSPORT) != null) { && attrs.get(SemanticAttributes.NETWORK_TRANSPORT) != null) {
assertThat(attrs).containsEntry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"); assertThat(attrs).containsEntry(SemanticAttributes.NETWORK_TRANSPORT, "tcp");
} }
if (SemconvStability.emitStableHttpSemconv() if (SemconvStability.emitStableHttpSemconv()
&& attrs.get(NetworkAttributes.NETWORK_TYPE) != null) { && attrs.get(SemanticAttributes.NETWORK_TYPE) != null) {
assertThat(attrs).containsEntry(NetworkAttributes.NETWORK_TYPE, "ipv4"); assertThat(attrs).containsEntry(SemanticAttributes.NETWORK_TYPE, "ipv4");
} }
AttributeKey<String> netProtocolKey = AttributeKey<String> netProtocolKey =
getAttributeKey(SemanticAttributes.NET_PROTOCOL_NAME); getAttributeKey(SemanticAttributes.NET_PROTOCOL_NAME);

View File

@ -27,9 +27,6 @@ import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.context.propagation.TextMapSetter; import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.GlobalTraceUtil; import io.opentelemetry.instrumentation.testing.GlobalTraceUtil;
@ -523,7 +520,7 @@ public abstract class AbstractHttpServerTest<SERVER> extends AbstractHttpServerU
HttpConstants._OTHER, HttpConstants._OTHER,
SUCCESS, SUCCESS,
options.responseCodeOnNonStandardHttpMethod) options.responseCodeOnNonStandardHttpMethod)
.hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method))); .hasAttribute(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method)));
} finally { } finally {
eventLoopGroup.shutdownGracefully().await(10, TimeUnit.SECONDS); eventLoopGroup.shutdownGracefully().await(10, TimeUnit.SECONDS);
} }
@ -746,12 +743,12 @@ public abstract class AbstractHttpServerTest<SERVER> extends AbstractHttpServerU
assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP); assertThat(attrs).containsEntry(SemanticAttributes.NET_TRANSPORT, IP_TCP);
} }
if (SemconvStability.emitStableHttpSemconv() if (SemconvStability.emitStableHttpSemconv()
&& attrs.get(NetworkAttributes.NETWORK_TRANSPORT) != null) { && attrs.get(SemanticAttributes.NETWORK_TRANSPORT) != null) {
assertThat(attrs).containsEntry(NetworkAttributes.NETWORK_TRANSPORT, "tcp"); assertThat(attrs).containsEntry(SemanticAttributes.NETWORK_TRANSPORT, "tcp");
} }
if (SemconvStability.emitStableHttpSemconv() if (SemconvStability.emitStableHttpSemconv()
&& attrs.get(NetworkAttributes.NETWORK_TYPE) != null) { && attrs.get(SemanticAttributes.NETWORK_TYPE) != null) {
assertThat(attrs).containsEntry(NetworkAttributes.NETWORK_TYPE, "ipv4"); assertThat(attrs).containsEntry(SemanticAttributes.NETWORK_TYPE, "ipv4");
} }
assertThat(attrs) assertThat(attrs)
@ -794,10 +791,10 @@ public abstract class AbstractHttpServerTest<SERVER> extends AbstractHttpServerU
value -> assertThat(value).isNull(), value -> assertThat(value).isNull(),
value -> assertThat(value).isEqualTo(TEST_CLIENT_IP))); value -> assertThat(value).isEqualTo(TEST_CLIENT_IP)));
if (SemconvStability.emitStableHttpSemconv() if (SemconvStability.emitStableHttpSemconv()
&& attrs.get(NetworkAttributes.CLIENT_PORT) != null) { && attrs.get(SemanticAttributes.CLIENT_PORT) != null) {
assertThat(attrs) assertThat(attrs)
.hasEntrySatisfying( .hasEntrySatisfying(
NetworkAttributes.CLIENT_PORT, port -> assertThat(port).isGreaterThan(0)); SemanticAttributes.CLIENT_PORT, port -> assertThat(port).isGreaterThan(0));
} }
assertThat(attrs).containsEntry(getAttributeKey(SemanticAttributes.HTTP_METHOD), method); assertThat(attrs).containsEntry(getAttributeKey(SemanticAttributes.HTTP_METHOD), method);
assertThat(attrs) assertThat(attrs)
@ -828,9 +825,10 @@ public abstract class AbstractHttpServerTest<SERVER> extends AbstractHttpServerU
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
assertThat(attrs) assertThat(attrs)
.containsEntry(UrlAttributes.URL_PATH, endpoint.resolvePath(address).getPath()); .containsEntry(
SemanticAttributes.URL_PATH, endpoint.resolvePath(address).getPath());
if (endpoint.getQuery() != null) { if (endpoint.getQuery() != null) {
assertThat(attrs).containsEntry(UrlAttributes.URL_QUERY, endpoint.getQuery()); assertThat(attrs).containsEntry(SemanticAttributes.URL_QUERY, endpoint.getQuery());
} }
} }
} }
@ -888,8 +886,8 @@ public abstract class AbstractHttpServerTest<SERVER> extends AbstractHttpServerU
} }
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
span.hasAttributesSatisfying( span.hasAttributesSatisfying(
equalTo(UrlAttributes.URL_PATH, endpoint.resolvePath(address).getPath())); equalTo(SemanticAttributes.URL_PATH, endpoint.resolvePath(address).getPath()));
span.hasAttributesSatisfying(equalTo(UrlAttributes.URL_QUERY, "id=" + requestId)); span.hasAttributesSatisfying(equalTo(SemanticAttributes.URL_QUERY, "id=" + requestId));
} }
return span; return span;

View File

@ -6,9 +6,6 @@
package io.opentelemetry.instrumentation.testing.junit.http; package io.opentelemetry.instrumentation.testing.junit.http;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
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.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
@ -20,39 +17,43 @@ public class SemconvStabilityUtil {
static { static {
addKey( addKey(
oldToNewMap, SemanticAttributes.NET_PROTOCOL_NAME, NetworkAttributes.NETWORK_PROTOCOL_NAME); oldToNewMap,
SemanticAttributes.NET_PROTOCOL_NAME,
SemanticAttributes.NETWORK_PROTOCOL_NAME);
addKey( addKey(
oldToNewMap, oldToNewMap,
SemanticAttributes.NET_PROTOCOL_VERSION, SemanticAttributes.NET_PROTOCOL_VERSION,
NetworkAttributes.NETWORK_PROTOCOL_VERSION); SemanticAttributes.NETWORK_PROTOCOL_VERSION);
addKey(oldToNewMap, SemanticAttributes.NET_PEER_NAME, NetworkAttributes.SERVER_ADDRESS); addKey(oldToNewMap, SemanticAttributes.NET_PEER_NAME, SemanticAttributes.SERVER_ADDRESS);
addKey(oldToNewMap, SemanticAttributes.NET_PEER_PORT, NetworkAttributes.SERVER_PORT); addKey(oldToNewMap, SemanticAttributes.NET_PEER_PORT, SemanticAttributes.SERVER_PORT);
addKey( addKey(
oldToNewMap, oldToNewMap,
SemanticAttributes.NET_SOCK_PEER_ADDR, SemanticAttributes.NET_SOCK_PEER_ADDR,
NetworkAttributes.CLIENT_SOCKET_ADDRESS); SemanticAttributes.CLIENT_SOCKET_ADDRESS);
addKey( addKey(
oldToNewMap, SemanticAttributes.NET_SOCK_PEER_PORT, NetworkAttributes.CLIENT_SOCKET_PORT); oldToNewMap, SemanticAttributes.NET_SOCK_PEER_PORT, SemanticAttributes.CLIENT_SOCKET_PORT);
addKey(oldToNewMap, SemanticAttributes.HTTP_URL, UrlAttributes.URL_FULL); addKey(oldToNewMap, SemanticAttributes.HTTP_URL, SemanticAttributes.URL_FULL);
addKey(oldToNewMap, SemanticAttributes.HTTP_METHOD, HttpAttributes.HTTP_REQUEST_METHOD); addKey(oldToNewMap, SemanticAttributes.HTTP_METHOD, SemanticAttributes.HTTP_REQUEST_METHOD);
addKey( addKey(
oldToNewMap, oldToNewMap,
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
HttpAttributes.HTTP_REQUEST_BODY_SIZE); SemanticAttributes.HTTP_REQUEST_BODY_SIZE);
addKey( addKey(
oldToNewMap, oldToNewMap,
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
HttpAttributes.HTTP_RESPONSE_BODY_SIZE); SemanticAttributes.HTTP_RESPONSE_BODY_SIZE);
addKey( addKey(
oldToNewMap, SemanticAttributes.HTTP_STATUS_CODE, HttpAttributes.HTTP_RESPONSE_STATUS_CODE); oldToNewMap,
addKey(oldToNewMap, SemanticAttributes.NET_HOST_NAME, NetworkAttributes.SERVER_ADDRESS); SemanticAttributes.HTTP_STATUS_CODE,
addKey(oldToNewMap, SemanticAttributes.NET_HOST_PORT, NetworkAttributes.SERVER_PORT); SemanticAttributes.HTTP_RESPONSE_STATUS_CODE);
addKey(oldToNewMap, SemanticAttributes.HTTP_CLIENT_IP, NetworkAttributes.CLIENT_ADDRESS); addKey(oldToNewMap, SemanticAttributes.NET_HOST_NAME, SemanticAttributes.SERVER_ADDRESS);
addKey(oldToNewMap, SemanticAttributes.HTTP_SCHEME, UrlAttributes.URL_SCHEME); addKey(oldToNewMap, SemanticAttributes.NET_HOST_PORT, SemanticAttributes.SERVER_PORT);
addKey(oldToNewMap, SemanticAttributes.HTTP_CLIENT_IP, SemanticAttributes.CLIENT_ADDRESS);
addKey(oldToNewMap, SemanticAttributes.HTTP_SCHEME, SemanticAttributes.URL_SCHEME);
addKey( addKey(
oldToNewMap, oldToNewMap,
SemanticAttributes.NET_SOCK_HOST_ADDR, SemanticAttributes.NET_SOCK_HOST_ADDR,
NetworkAttributes.SERVER_SOCKET_ADDRESS); SemanticAttributes.SERVER_SOCKET_ADDRESS);
} }
private SemconvStabilityUtil() {} private SemconvStabilityUtil() {}