From ece226386ff8b31ee9b1cf88444efbdb84e63750 Mon Sep 17 00:00:00 2001 From: sarthak Date: Mon, 8 Nov 2021 10:22:18 +0530 Subject: [PATCH] trace url bug fix (#281) * added condition on abs url * nit * nit * refactored Co-authored-by: Sarthak Singhal --- .../http/HttpSemanticConventionUtils.java | 18 ++++++++++++------ 1 file changed, 12 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 e594692a8..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,8 +184,10 @@ public static boolean isAbsoluteUrl(String urlStr) { */ public static Optional getHttpUrlForOTelFormat( Map attributeValueMap) { - if (attributeValueMap.containsKey(HTTP_URL.getValue())) { - return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); + Optional httpUrlForOTelFormat = Optional.empty(); + if (attributeValueMap.containsKey(HTTP_URL.getValue()) + && isAbsoluteUrl(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())) { @@ -195,15 +197,19 @@ public static Optional getHttpUrlForOTelFormat( 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); + httpUrlForOTelFormat = getHttpUrlForOtelFormatServerSpan(attributeValueMap); } - return Optional.empty(); + + if (httpUrlForOTelFormat.isEmpty() && attributeValueMap.containsKey(HTTP_URL.getValue())) { + return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue()); + } + return httpUrlForOTelFormat; } private static Optional getHttpUrlForOtelFormatClientSpan(