Add net.host.port to the http.server.active_requests metric
MODIFY
instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java
instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java
@@ -40,7 +40,7 @@ final class TemporaryMetricsView {
Set<AttributeKey> view = new HashSet<>(durationAlwaysInclude);
view.add(SemanticAttributes.NET_PEER_NAME);
view.add(SemanticAttributes.NET_PEER_PORT);
- view.add(AttributeKey.stringKey("net.peer.sock.addr"));
+ view.add(SemanticAttributes.NET_SOCK_PEER_ADDR);
return view;
}
@@ -66,7 +66,7 @@ final class TemporaryMetricsView {
view.add(SemanticAttributes.HTTP_SCHEME);
view.add(SemanticAttributes.HTTP_FLAVOR);
view.add(SemanticAttributes.NET_HOST_NAME);
- // TODO: net host port?
+ view.add(SemanticAttributes.NET_HOST_PORT);
return view;
}

MODIFY
instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java
instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java
package io.opentelemetry.instrumentation.api.instrumenter.http;
-import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
@@ -49,9 +48,9 @@ class HttpClientMetricsTest {
.put("http.status_code", 200)
.put("http.response_content_length", 200)
.put("net.sock.family", "inet")
- .put("net.peer.sock.addr", "1.2.3.4")
- .put("net.peer.sock.name", "somehost20")
- .put("net.peer.sock.port", 8080)
+ .put("net.sock.peer.addr", "1.2.3.4")
+ .put("net.sock.peer.name", "somehost20")
+ .put("net.sock.peer.port", 8080)
.build();
Context parent =
@@ -92,7 +91,8 @@ class HttpClientMetricsTest {
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
- equalTo(stringKey("net.peer.sock.addr"), "1.2.3.4"))
+ equalTo(
+ SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
@@ -114,7 +114,8 @@ class HttpClientMetricsTest {
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
- equalTo(stringKey("net.peer.sock.addr"), "1.2.3.4"))
+ equalTo(
+ SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
@@ -136,7 +137,8 @@ class HttpClientMetricsTest {
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
- equalTo(stringKey("net.peer.sock.addr"), "1.2.3.4"))
+ equalTo(
+ SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"))
.hasExemplarsSatisfying(
exemplar ->
exemplar

MODIFY
instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java
instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java
@@ -43,10 +43,10 @@ class HttpServerMetricsTest {
.put("net.host.name", "localhost")
.put("net.host.port", 1234)
.put("net.sock.family", "inet")
- .put("net.peer.sock.addr", "1.2.3.4")
- .put("net.peer.sock.port", 8080)
- .put("net.host.sock.addr", "4.3.2.1")
- .put("net.host.sock.port", 9090)
+ .put("net.sock.peer.addr", "1.2.3.4")
+ .put("net.sock.peer.port", 8080)
+ .put("net.sock.host.addr", "4.3.2.1")
+ .put("net.sock.host.port", 9090)
.build();
Attributes responseAttributes =
@@ -90,7 +90,8 @@ class HttpServerMetricsTest {
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.HTTP_FLAVOR, HTTP_2_0),
- equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"))
+ equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
+ equalTo(SemanticAttributes.NET_HOST_PORT, 1234L))
.hasExemplarsSatisfying(
exemplar ->
exemplar
@@ -115,7 +116,8 @@ class HttpServerMetricsTest {
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.HTTP_FLAVOR, HTTP_2_0),
- equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"))
+ equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
+ equalTo(SemanticAttributes.NET_HOST_PORT, 1234L))
.hasExemplarsSatisfying(
exemplar ->
exemplar
@@ -139,7 +141,8 @@ class HttpServerMetricsTest {
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.HTTP_FLAVOR, HTTP_2_0),
- equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"))
+ equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
+ equalTo(SemanticAttributes.NET_HOST_PORT, 1234L))
.hasExemplarsSatisfying(
exemplar ->
exemplar

MODIFY
instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java
instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java
package io.opentelemetry.instrumentation.api.instrumenter.http;
-import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyActiveRequestsView;
import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView;
import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyServerDurationAndSizeView;
@@ -39,10 +38,10 @@ class TemporaryMetricsViewTest {
.put(SemanticAttributes.NET_TRANSPORT, IP_TCP)
.put(SemanticAttributes.NET_PEER_NAME, "somehost2")
.put(SemanticAttributes.NET_PEER_PORT, 443)
- .put("net.sock.family", "inet")
- .put("net.peer.sock.addr", "1.2.3.4")
- .put("net.peer.sock.name", "somehost20")
- .put("net.peer.sock.port", 8080)
+ .put(SemanticAttributes.NET_SOCK_FAMILY, "inet")
+ .put(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4")
+ .put(SemanticAttributes.NET_SOCK_PEER_NAME, "somehost20")
+ .put(SemanticAttributes.NET_SOCK_PEER_PORT, 8080)
.build();
assertThat(applyClientDurationAndSizeView(startAttributes, endAttributes))
@@ -52,7 +51,7 @@ class TemporaryMetricsViewTest {
entry(SemanticAttributes.HTTP_FLAVOR, HTTP_1_1),
entry(SemanticAttributes.NET_PEER_NAME, "somehost2"),
entry(SemanticAttributes.NET_PEER_PORT, 443L),
- entry(stringKey("net.peer.sock.addr"), "1.2.3.4"));
+ entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"));
}
@Test
@@ -69,11 +68,11 @@ class TemporaryMetricsViewTest {
.put(SemanticAttributes.NET_TRANSPORT, IP_TCP)
.put(SemanticAttributes.NET_HOST_NAME, "somehost")
.put(SemanticAttributes.NET_HOST_PORT, 443)
- .put("net.sock.family", "inet")
- .put("net.peer.sock.addr", "1.2.3.4")
- .put("net.peer.sock.port", 8080)
- .put("net.host.sock.addr", "4.3.2.1")
- .put("net.host.sock.port", 9090)
+ .put(SemanticAttributes.NET_SOCK_FAMILY, "inet")
+ .put(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4")
+ .put(SemanticAttributes.NET_SOCK_PEER_PORT, 8080)
+ .put(SemanticAttributes.NET_SOCK_HOST_ADDR, "4.3.2.1")
+ .put(SemanticAttributes.NET_SOCK_HOST_PORT, 9090)
.build();
Attributes endAttributes =
@@ -109,11 +108,11 @@ class TemporaryMetricsViewTest {
.put(SemanticAttributes.NET_TRANSPORT, IP_TCP)
.put(SemanticAttributes.NET_HOST_NAME, "somehost")
.put(SemanticAttributes.NET_HOST_PORT, 443)
- .put("net.sock.family", "inet")
- .put("net.peer.sock.addr", "1.2.3.4")
- .put("net.peer.sock.port", 8080)
- .put("net.host.sock.addr", "4.3.2.1")
- .put("net.host.sock.port", 9090)
+ .put(SemanticAttributes.NET_SOCK_FAMILY, "inet")
+ .put(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4")
+ .put(SemanticAttributes.NET_SOCK_PEER_PORT, 8080)
+ .put(SemanticAttributes.NET_SOCK_HOST_ADDR, "4.3.2.1")
+ .put(SemanticAttributes.NET_SOCK_HOST_PORT, 9090)
.build();
assertThat(applyActiveRequestsView(attributes))
@@ -121,6 +120,7 @@ class TemporaryMetricsViewTest {
entry(SemanticAttributes.HTTP_METHOD, "GET"),
entry(SemanticAttributes.HTTP_SCHEME, "https"),
entry(SemanticAttributes.HTTP_FLAVOR, HTTP_1_1),
- entry(SemanticAttributes.NET_HOST_NAME, "somehost"));
+ entry(SemanticAttributes.NET_HOST_NAME, "somehost"),
+ entry(SemanticAttributes.NET_HOST_PORT, 443L));
}
}

Add net.host.port to the http.server.active_requests metric (#7757)