From 025664741c573815bf262d8e7b8603a549952275 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Tue, 7 Feb 2023 18:13:54 +0100 Subject: [PATCH] Add net.host.port to the http.server.active_requests metric --- .../http/TemporaryMetricsView.java | 4 +-- .../http/HttpClientMetricsTest.java | 16 +++++---- .../http/HttpServerMetricsTest.java | 17 ++++++---- .../http/TemporaryMetricsViewTest.java | 34 +++++++++---------- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java index 6b3e88928ca0..85fbf30bfba5 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java @@ -40,7 +40,7 @@ private static Set buildDurationClientView() { Set 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 @@ private static Set 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; } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java index 03f39b9f07c2..9c1f91a9a67b 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsTest.java @@ -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; @@ -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 = @@ -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 @@ -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 @@ -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 diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java index 647a37846ef6..94fea351a447 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java @@ -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 = @@ -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 @@ -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 @@ -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 diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java index aefb28301e8e..da46ed81cbdb 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java @@ -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; @@ -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)) @@ -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 @@ -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 = @@ -109,11 +108,11 @@ 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)) @@ -121,6 +120,7 @@ void shouldApplyActiveRequestsView() { 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)); } }