Skip to content

Commit

Permalink
trace url bug fix (#281)
Browse files Browse the repository at this point in the history
* added condition on abs url

* nit

* nit

* refactored

Co-authored-by: Sarthak Singhal <sarthaksinghal@Sarthaks-MacBook-Pro.local>
  • Loading branch information
sarthak77 and Sarthak Singhal authored Nov 8, 2021
1 parent 0b21b01 commit ece2263
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ public static boolean isAbsoluteUrl(String urlStr) {
*/
public static Optional<String> getHttpUrlForOTelFormat(
Map<String, AttributeValue> attributeValueMap) {
if (attributeValueMap.containsKey(HTTP_URL.getValue())) {
return Optional.of(attributeValueMap.get(HTTP_URL.getValue()).getValue());
Optional<String> 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())) {
Expand All @@ -195,15 +197,19 @@ public static Optional<String> 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<String> getHttpUrlForOtelFormatClientSpan(
Expand Down

0 comments on commit ece2263

Please sign in to comment.