Skip to content

Commit ece2263

Browse files
sarthak77Sarthak Singhal
andauthored
trace url bug fix (#281)
* added condition on abs url * nit * nit * refactored Co-authored-by: Sarthak Singhal <[email protected]>
1 parent 0b21b01 commit ece2263

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

semantic-convention-utils/src/main/java/org/hypertrace/semantic/convention/utils/http/HttpSemanticConventionUtils.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ public static boolean isAbsoluteUrl(String urlStr) {
184184
*/
185185
public static Optional<String> getHttpUrlForOTelFormat(
186186
Map<String, AttributeValue> attributeValueMap) {
187-
if (attributeValueMap.containsKey(HTTP_URL.getValue())) {
188-
return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue());
187+
Optional<String> httpUrlForOTelFormat = Optional.empty();
188+
if (attributeValueMap.containsKey(HTTP_URL.getValue())
189+
&& isAbsoluteUrl(attributeValueMap.get(HTTP_URL.getValue()).getValue())) {
190+
httpUrlForOTelFormat = Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue());
189191
} else if (attributeValueMap.containsKey(HTTP_SCHEME.getValue())
190192
&& attributeValueMap.containsKey(HTTP_HOST.getValue())
191193
&& attributeValueMap.containsKey(HTTP_TARGET.getValue())) {
@@ -195,15 +197,19 @@ public static Optional<String> getHttpUrlForOTelFormat(
195197
attributeValueMap.get(HTTP_SCHEME.getValue()).getValue(),
196198
attributeValueMap.get(HTTP_HOST.getValue()).getValue(),
197199
attributeValueMap.get(HTTP_TARGET.getValue()).getValue());
198-
return Optional.of(url);
200+
httpUrlForOTelFormat = Optional.of(url);
199201
} else if (SpanSemanticConventionUtils.isClientSpanForOtelFormat(attributeValueMap)
200202
|| SpanSemanticConventionUtils.isClientSpanForOCFormat(attributeValueMap)) {
201-
return getHttpUrlForOtelFormatClientSpan(attributeValueMap);
203+
httpUrlForOTelFormat = getHttpUrlForOtelFormatClientSpan(attributeValueMap);
202204
} else if (SpanSemanticConventionUtils.isServerSpanForOtelFormat(attributeValueMap)
203205
|| SpanSemanticConventionUtils.isServerSpanForOCFormat(attributeValueMap)) {
204-
return getHttpUrlForOtelFormatServerSpan(attributeValueMap);
206+
httpUrlForOTelFormat = getHttpUrlForOtelFormatServerSpan(attributeValueMap);
205207
}
206-
return Optional.empty();
208+
209+
if (httpUrlForOTelFormat.isEmpty() && attributeValueMap.containsKey(HTTP_URL.getValue())) {
210+
return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue());
211+
}
212+
return httpUrlForOTelFormat;
207213
}
208214

209215
private static Optional<String> getHttpUrlForOtelFormatClientSpan(

0 commit comments

Comments
 (0)