From 591cdf5c79ec44a7e37b22d1610e5623bc3d2d93 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sat, 9 Nov 2024 23:31:45 -0800 Subject: [PATCH] Move get attribute inside condition where used (#12604) --- .../InternalNetworkAttributesExtractor.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/network/internal/InternalNetworkAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/network/internal/InternalNetworkAttributesExtractor.java index 7d0cb9eea0..3752c02527 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/network/internal/InternalNetworkAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/network/internal/InternalNetworkAttributesExtractor.java @@ -33,18 +33,23 @@ public final class InternalNetworkAttributesExtractor { } public void onEnd(AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) { - String protocolName = lowercase(getter.getNetworkProtocolName(request, response)); - String protocolVersion = lowercase(getter.getNetworkProtocolVersion(request, response)); - if (captureProtocolAttributes) { - String transport = lowercase(getter.getNetworkTransport(request, response)); - internalSet(attributes, NetworkAttributes.NETWORK_TRANSPORT, transport); + internalSet( + attributes, + NetworkAttributes.NETWORK_TRANSPORT, + lowercase(getter.getNetworkTransport(request, response))); internalSet( attributes, NetworkAttributes.NETWORK_TYPE, lowercase(getter.getNetworkType(request, response))); - internalSet(attributes, NetworkAttributes.NETWORK_PROTOCOL_NAME, protocolName); - internalSet(attributes, NetworkAttributes.NETWORK_PROTOCOL_VERSION, protocolVersion); + internalSet( + attributes, + NetworkAttributes.NETWORK_PROTOCOL_NAME, + lowercase(getter.getNetworkProtocolName(request, response))); + internalSet( + attributes, + NetworkAttributes.NETWORK_PROTOCOL_VERSION, + lowercase(getter.getNetworkProtocolVersion(request, response))); } if (captureLocalSocketAttributes) {