From 0785dc412f7bc58cf5a704eefc3816874626979e Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Thu, 23 Feb 2023 14:24:12 +0530 Subject: [PATCH 01/17] Updating Sockpeer service. --- .../instrumenter/net/PeerServiceAttributesExtractor.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index dc49ee641fc8..5f7075bd0694 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -62,6 +62,13 @@ public void onEnd( if (peerService != null) { attributes.put(SemanticAttributes.PEER_SERVICE, peerService); } + else + { + String sockPeerName = attributesGetter.sockPeerName(request, response); + String sockPeerService = mapToPeerService(sockPeerName); + if (sockPeerService != null) { + attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); + } } @Nullable From 1965b6f0f3c6fe02025150c9024f32bdb265e89f Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 13 Mar 2023 17:21:55 +0530 Subject: [PATCH 02/17] added test cases --- .../PeerServiceAttributesExtractorTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java index 97d755f16a24..115eef4deb8d 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java @@ -10,6 +10,8 @@ import static org.assertj.core.api.Assertions.entry; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.opentelemetry.api.common.Attributes; @@ -94,4 +96,58 @@ void shouldSetPeerNameIfItMatches() { assertThat(endAttributes.build()) .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); } + + + @Test + void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() { + // given + Map peerServiceMapping = new HashMap<>(); + peerServiceMapping.put("example.com", "myService"); + peerServiceMapping.put("1.2.3.4", "someOtherService"); + + PeerServiceAttributesExtractor underTest = + new PeerServiceAttributesExtractor<>(netAttributesExtractor, peerServiceMapping); + + when(netAttributesExtractor.sockPeerName(any(), any())).thenReturn("example.com"); + + Context context = Context.root(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + underTest.onStart(startAttributes, context, "request"); + AttributesBuilder endAttributes = Attributes.builder(); + underTest.onEnd(endAttributes, context, "request", "response", null); + + // then + assertThat(startAttributes.build()).isEmpty(); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); + } + + @Test + void shouldSetNoSockPeerNameIfPeerNameMatches() { + // given + Map peerServiceMapping = new HashMap<>(); + peerServiceMapping.put("example.com", "myService"); + peerServiceMapping.put("unmatched.com", "someOtherService"); + + PeerServiceAttributesExtractor underTest = + new PeerServiceAttributesExtractor<>(netAttributesExtractor, peerServiceMapping); + + when(netAttributesExtractor.peerName(any(), any())).thenReturn("example.com"); + + Context context = Context.root(); + + // when + AttributesBuilder startAttributes = Attributes.builder(); + underTest.onStart(startAttributes, context, "request"); + AttributesBuilder endAttributes = Attributes.builder(); + underTest.onEnd(endAttributes, context, "request", "response", null); + + // then + assertThat(startAttributes.build()).isEmpty(); + assertThat(endAttributes.build()) + .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); + verify(netAttributesExtractor, never()).sockPeerName(any(), any()); + } } From f1dd0fcf84e5ee799d6a4c0f68a260f74345406c Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 20 Mar 2023 09:22:17 +0530 Subject: [PATCH 03/17] Syntax error --- .../instrumenter/net/PeerServiceAttributesExtractor.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index 5f7075bd0694..43ea01f20741 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -61,15 +61,13 @@ public void onEnd( String peerService = mapToPeerService(peerName); if (peerService != null) { attributes.put(SemanticAttributes.PEER_SERVICE, peerService); - } - else - { + } else { String sockPeerName = attributesGetter.sockPeerName(request, response); String sockPeerService = mapToPeerService(sockPeerName); if (sockPeerService != null) { attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); } - } + } @Nullable private String mapToPeerService(String endpoint) { From 1846f0fc834f4c8cb7b47da5a87ebde3a5e973f2 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 20 Mar 2023 09:45:32 +0530 Subject: [PATCH 04/17] syntax error --- .../api/instrumenter/net/PeerServiceAttributesExtractor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index 43ea01f20741..62dd062a8cfe 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -62,6 +62,7 @@ public void onEnd( if (peerService != null) { attributes.put(SemanticAttributes.PEER_SERVICE, peerService); } else { + // try map sockPeerName only if there was no match for peerName String sockPeerName = attributesGetter.sockPeerName(request, response); String sockPeerService = mapToPeerService(sockPeerName); if (sockPeerService != null) { From bca68997367a0cd29a2b5b6613a198a6662966b0 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 20 Mar 2023 10:35:22 +0530 Subject: [PATCH 05/17] SocketPeer --- .../api/instrumenter/net/PeerServiceAttributesExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index 62dd062a8cfe..7e1831ffe760 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -69,7 +69,7 @@ public void onEnd( attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); } } - + } @Nullable private String mapToPeerService(String endpoint) { if (endpoint == null) { From caebf279180d16f2a50e79262368c9a04ce7d11e Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 20 Mar 2023 11:07:47 +0530 Subject: [PATCH 06/17] Syntax error --- .../net/PeerServiceAttributesExtractor.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index 7e1831ffe760..5ca20a8a03bb 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -69,12 +69,11 @@ public void onEnd( attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); } } - } - @Nullable - private String mapToPeerService(String endpoint) { - if (endpoint == null) { - return null; + @Nullable + private String mapToPeerService(String endpoint) { + if (endpoint == null) { + return null; + } + return peerServiceMapping.get(endpoint); } - return peerServiceMapping.get(endpoint); } -} From 8704d36d9a67d743fd18035f6be94e19601e303c Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 20 Mar 2023 12:41:59 +0530 Subject: [PATCH 07/17] syntax error --- .../net/PeerServiceAttributesExtractor.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index 5ca20a8a03bb..e4f69176d204 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -63,17 +63,17 @@ public void onEnd( attributes.put(SemanticAttributes.PEER_SERVICE, peerService); } else { // try map sockPeerName only if there was no match for peerName - String sockPeerName = attributesGetter.sockPeerName(request, response); - String sockPeerService = mapToPeerService(sockPeerName); - if (sockPeerService != null) { - attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); - } + String sockPeerName = attributesGetter.sockPeerName(request, response); + String sockPeerService = mapToPeerService(sockPeerName); + if (sockPeerService != null) { + attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); } - @Nullable - private String mapToPeerService(String endpoint) { - if (endpoint == null) { - return null; - } - return peerServiceMapping.get(endpoint); + } + @Nullable + private String mapToPeerService(String endpoint) { + if (endpoint == null) { + return null; } + return peerServiceMapping.get(endpoint); } +} From 1d44c92b74f570fb5db98e2abff5b15f4cf14c7b Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:15:35 +0530 Subject: [PATCH 08/17] spotless --- .../instrumenter/net/PeerServiceAttributesExtractor.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index e4f69176d204..7e1831ffe760 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -63,10 +63,11 @@ public void onEnd( attributes.put(SemanticAttributes.PEER_SERVICE, peerService); } else { // try map sockPeerName only if there was no match for peerName - String sockPeerName = attributesGetter.sockPeerName(request, response); - String sockPeerService = mapToPeerService(sockPeerName); - if (sockPeerService != null) { - attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); + String sockPeerName = attributesGetter.sockPeerName(request, response); + String sockPeerService = mapToPeerService(sockPeerName); + if (sockPeerService != null) { + attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); + } } } @Nullable From 30611dd03fb702ad0f413231b62803c6b8b7cbb1 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Tue, 21 Mar 2023 14:53:57 +0530 Subject: [PATCH 09/17] format --- .../api/instrumenter/net/PeerServiceAttributesExtractorTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java index 115eef4deb8d..a6b72719fa07 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java @@ -96,7 +96,6 @@ void shouldSetPeerNameIfItMatches() { assertThat(endAttributes.build()) .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); } - @Test void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() { From 0e469233d2f0435c675674db68f34698b549215a Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:10:34 +0530 Subject: [PATCH 10/17] test --- .../api/instrumenter/net/PeerServiceAttributesExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index 7e1831ffe760..62dd062a8cfe 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -69,7 +69,7 @@ public void onEnd( attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); } } - } + @Nullable private String mapToPeerService(String endpoint) { if (endpoint == null) { From ce23719308fe5f35abaef813f4deeccaa26cf469 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:39:36 +0530 Subject: [PATCH 11/17] Update instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java Co-authored-by: Mateusz Rzeszutek --- .../net/PeerServiceAttributesExtractor.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index 62dd062a8cfe..324682a52bd2 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -59,15 +59,12 @@ public void onEnd( String peerName = attributesGetter.getPeerName(request); String peerService = mapToPeerService(peerName); + if (peerService == null) { + String sockPeerName = attributesGetter.sockPeerName(request, response); + peerService = mapToPeerService(sockPeerName); + } if (peerService != null) { attributes.put(SemanticAttributes.PEER_SERVICE, peerService); - } else { - // try map sockPeerName only if there was no match for peerName - String sockPeerName = attributesGetter.sockPeerName(request, response); - String sockPeerService = mapToPeerService(sockPeerName); - if (sockPeerService != null) { - attributes.put(SemanticAttributes.PEER_SERVICE, sockPeerService); - } } @Nullable From ec41ae75509e7dbf3f5ce14e0fd6b5e1425eb184 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:30:33 +0530 Subject: [PATCH 12/17] code review: closing bracket --- .../api/instrumenter/net/PeerServiceAttributesExtractor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index 324682a52bd2..a188def403e5 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -66,6 +66,7 @@ public void onEnd( if (peerService != null) { attributes.put(SemanticAttributes.PEER_SERVICE, peerService); } + } @Nullable private String mapToPeerService(String endpoint) { From 8dcbe10924d6117e148edf4100a400cbe1371428 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Thu, 27 Apr 2023 14:14:38 +0530 Subject: [PATCH 13/17] Update instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java Co-authored-by: Mateusz Rzeszutek --- .../api/instrumenter/net/PeerServiceAttributesExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java index a188def403e5..aa2414db1e17 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractor.java @@ -60,7 +60,7 @@ public void onEnd( String peerName = attributesGetter.getPeerName(request); String peerService = mapToPeerService(peerName); if (peerService == null) { - String sockPeerName = attributesGetter.sockPeerName(request, response); + String sockPeerName = attributesGetter.getSockPeerName(request, response); peerService = mapToPeerService(sockPeerName); } if (peerService != null) { From 6b0dc34df2ce9359c336ae20c0a61b65e4def98b Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Thu, 27 Apr 2023 14:14:46 +0530 Subject: [PATCH 14/17] Update instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java Co-authored-by: Mateusz Rzeszutek --- .../instrumenter/net/PeerServiceAttributesExtractorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java index a6b72719fa07..6d0c3dbd3632 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java @@ -107,7 +107,7 @@ void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() { PeerServiceAttributesExtractor underTest = new PeerServiceAttributesExtractor<>(netAttributesExtractor, peerServiceMapping); - when(netAttributesExtractor.sockPeerName(any(), any())).thenReturn("example.com"); + when(netAttributesExtractor.getSockPeerName(any(), any())).thenReturn("example.com"); Context context = Context.root(); From 607db5f6ed88914169987fe70cced2d0fa7bc5d3 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Thu, 27 Apr 2023 14:14:59 +0530 Subject: [PATCH 15/17] Update instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java Co-authored-by: Mateusz Rzeszutek --- .../instrumenter/net/PeerServiceAttributesExtractorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java index 6d0c3dbd3632..26f87ecfbd9b 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java @@ -147,6 +147,6 @@ void shouldSetNoSockPeerNameIfPeerNameMatches() { assertThat(startAttributes.build()).isEmpty(); assertThat(endAttributes.build()) .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); - verify(netAttributesExtractor, never()).sockPeerName(any(), any()); + verify(netAttributesExtractor, never()).getSockPeerName(any(), any()); } } From fa940a37185d143b1c410385427a567bdf786d1e Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Fri, 28 Apr 2023 11:25:47 +0530 Subject: [PATCH 16/17] Update PeerServiceAttributesExtractorTest.java --- .../PeerServiceAttributesExtractorTest.java | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java index 26f87ecfbd9b..094c6a44c948 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java @@ -95,6 +95,7 @@ void shouldSetPeerNameIfItMatches() { assertThat(startAttributes.build()).isEmpty(); assertThat(endAttributes.build()) .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); + verify(netAttributesExtractor, never()).getSockPeerName(any(), any()); } @Test @@ -122,31 +123,4 @@ void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() { assertThat(endAttributes.build()) .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); } - - @Test - void shouldSetNoSockPeerNameIfPeerNameMatches() { - // given - Map peerServiceMapping = new HashMap<>(); - peerServiceMapping.put("example.com", "myService"); - peerServiceMapping.put("unmatched.com", "someOtherService"); - - PeerServiceAttributesExtractor underTest = - new PeerServiceAttributesExtractor<>(netAttributesExtractor, peerServiceMapping); - - when(netAttributesExtractor.peerName(any(), any())).thenReturn("example.com"); - - Context context = Context.root(); - - // when - AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, context, "request"); - AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, context, "request", "response", null); - - // then - assertThat(startAttributes.build()).isEmpty(); - assertThat(endAttributes.build()) - .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); - verify(netAttributesExtractor, never()).getSockPeerName(any(), any()); - } } From 43203a906d73be10dfec4e2dbfdd8b3ec1618928 Mon Sep 17 00:00:00 2001 From: rahuldimri <107100022+rahuldimri@users.noreply.github.com> Date: Fri, 28 Apr 2023 11:47:58 +0530 Subject: [PATCH 17/17] formatting changes --- .../instrumenter/net/PeerServiceAttributesExtractorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java index 094c6a44c948..4d0206070038 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/PeerServiceAttributesExtractorTest.java @@ -97,7 +97,7 @@ void shouldSetPeerNameIfItMatches() { .containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService")); verify(netAttributesExtractor, never()).getSockPeerName(any(), any()); } - + @Test void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() { // given