Skip to content

Commit

Permalink
Add net.host.port to the http.server.active_requests metric (#7757)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Feb 8, 2023
1 parent b72e28a commit c3e8770
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static Set<AttributeKey> buildDurationClientView() {
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;
}

Expand All @@ -66,7 +66,7 @@ private static Set<AttributeKey> buildActiveRequestsView() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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;

Expand Down Expand Up @@ -49,9 +48,9 @@ void collectsMetrics() {
.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 =
Expand Down Expand Up @@ -92,7 +91,8 @@ void collectsMetrics() {
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
Expand All @@ -114,7 +114,8 @@ void collectsMetrics() {
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
Expand All @@ -136,7 +137,8 @@ void collectsMetrics() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ void collectsMetrics() {
.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 =
Expand Down Expand Up @@ -90,7 +90,8 @@ void collectsMetrics() {
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
Expand All @@ -115,7 +116,8 @@ void collectsMetrics() {
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
Expand All @@ -139,7 +141,8 @@ void collectsMetrics() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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;
Expand Down Expand Up @@ -39,10 +38,10 @@ void shouldApplyClientDurationAndSizeView() {
.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))
Expand All @@ -52,7 +51,7 @@ void shouldApplyClientDurationAndSizeView() {
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
Expand All @@ -69,11 +68,11 @@ void shouldApplyServerDurationAndSizeView() {
.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 =
Expand Down Expand Up @@ -109,18 +108,19 @@ void shouldApplyActiveRequestsView() {
.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))
.containsOnly(
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));
}
}

0 comments on commit c3e8770

Please sign in to comment.