From c09ff429222adaceee6e726f83a1187b23e25cf5 Mon Sep 17 00:00:00 2001 From: Sarthak Singhal Date: Fri, 5 Nov 2021 10:46:25 +0530 Subject: [PATCH 1/4] added condition on abs url --- .../convention/utils/http/HttpSemanticConventionUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java b/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java index e594692a8..f0535750a 100644 --- a/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java +++ b/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java @@ -184,7 +184,8 @@ public static boolean isAbsoluteUrl(String urlStr) { */ public static Optional getHttpUrlForOTelFormat( Map attributeValueMap) { - if (attributeValueMap.containsKey(HTTP_URL.getValue())) { + if (attributeValueMap.containsKey(HTTP_URL.getValue()) + && isAbsoluteUrl(attributeValueMap.get(HTTP_URL.getValue()).getValue())) { return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); } else if (attributeValueMap.containsKey(HTTP_SCHEME.getValue()) && attributeValueMap.containsKey(HTTP_HOST.getValue()) From 84e7ab4df1ce71aaaf8eee2745709a5ce3952ca8 Mon Sep 17 00:00:00 2001 From: Sarthak Singhal Date: Fri, 5 Nov 2021 10:56:25 +0530 Subject: [PATCH 2/4] nit --- .../convention/utils/http/HttpSemanticConventionUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java b/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java index f0535750a..4d6aca247 100644 --- a/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java +++ b/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java @@ -197,6 +197,8 @@ && isAbsoluteUrl(attributeValueMap.get(HTTP_URL.getValue()).getValue())) { attributeValueMap.get(HTTP_HOST.getValue()).getValue(), attributeValueMap.get(HTTP_TARGET.getValue()).getValue()); return Optional.of(url); + } else if (attributeValueMap.containsKey(HTTP_URL.getValue())) { + return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); } else if (SpanSemanticConventionUtils.isClientSpanForOtelFormat(attributeValueMap) || SpanSemanticConventionUtils.isClientSpanForOCFormat(attributeValueMap)) { return getHttpUrlForOtelFormatClientSpan(attributeValueMap); From 89610d18cacfea5f35b9e49baa1883161f9468a5 Mon Sep 17 00:00:00 2001 From: Sarthak Singhal Date: Fri, 5 Nov 2021 11:07:28 +0530 Subject: [PATCH 3/4] nit --- .../convention/utils/http/HttpSemanticConventionUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java b/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java index 4d6aca247..8ac03ce56 100644 --- a/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java +++ b/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java @@ -197,14 +197,14 @@ && isAbsoluteUrl(attributeValueMap.get(HTTP_URL.getValue()).getValue())) { attributeValueMap.get(HTTP_HOST.getValue()).getValue(), attributeValueMap.get(HTTP_TARGET.getValue()).getValue()); return Optional.of(url); - } else if (attributeValueMap.containsKey(HTTP_URL.getValue())) { - return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); } else if (SpanSemanticConventionUtils.isClientSpanForOtelFormat(attributeValueMap) || SpanSemanticConventionUtils.isClientSpanForOCFormat(attributeValueMap)) { return getHttpUrlForOtelFormatClientSpan(attributeValueMap); } else if (SpanSemanticConventionUtils.isServerSpanForOtelFormat(attributeValueMap) || SpanSemanticConventionUtils.isServerSpanForOCFormat(attributeValueMap)) { return getHttpUrlForOtelFormatServerSpan(attributeValueMap); + } else if (attributeValueMap.containsKey(HTTP_URL.getValue())) { + return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); } return Optional.empty(); } From 92e0b7e45337c6fda42cf7443559055ebc3ca784 Mon Sep 17 00:00:00 2001 From: Sarthak Singhal Date: Mon, 8 Nov 2021 10:08:51 +0530 Subject: [PATCH 4/4] refactored --- .../utils/http/HttpSemanticConventionUtils.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java b/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java index 8ac03ce56..18493e92f 100644 --- a/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java +++ b/semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java @@ -184,9 +184,10 @@ public static boolean isAbsoluteUrl(String urlStr) { */ public static Optional getHttpUrlForOTelFormat( Map attributeValueMap) { + Optional httpUrlForOTelFormat = Optional.empty(); if (attributeValueMap.containsKey(HTTP_URL.getValue()) && isAbsoluteUrl(attributeValueMap.get(HTTP_URL.getValue()).getValue())) { - return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); + httpUrlForOTelFormat = Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); } else if (attributeValueMap.containsKey(HTTP_SCHEME.getValue()) && attributeValueMap.containsKey(HTTP_HOST.getValue()) && attributeValueMap.containsKey(HTTP_TARGET.getValue())) { @@ -196,17 +197,19 @@ && isAbsoluteUrl(attributeValueMap.get(HTTP_URL.getValue()).getValue())) { attributeValueMap.get(HTTP_SCHEME.getValue()).getValue(), attributeValueMap.get(HTTP_HOST.getValue()).getValue(), attributeValueMap.get(HTTP_TARGET.getValue()).getValue()); - return Optional.of(url); + httpUrlForOTelFormat = Optional.of(url); } else if (SpanSemanticConventionUtils.isClientSpanForOtelFormat(attributeValueMap) || SpanSemanticConventionUtils.isClientSpanForOCFormat(attributeValueMap)) { - return getHttpUrlForOtelFormatClientSpan(attributeValueMap); + httpUrlForOTelFormat = getHttpUrlForOtelFormatClientSpan(attributeValueMap); } else if (SpanSemanticConventionUtils.isServerSpanForOtelFormat(attributeValueMap) || SpanSemanticConventionUtils.isServerSpanForOCFormat(attributeValueMap)) { - return getHttpUrlForOtelFormatServerSpan(attributeValueMap); - } else if (attributeValueMap.containsKey(HTTP_URL.getValue())) { + httpUrlForOTelFormat = getHttpUrlForOtelFormatServerSpan(attributeValueMap); + } + + if (httpUrlForOTelFormat.isEmpty() && attributeValueMap.containsKey(HTTP_URL.getValue())) { return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); } - return Optional.empty(); + return httpUrlForOTelFormat; } private static Optional getHttpUrlForOtelFormatClientSpan(