Skip to content

Commit 0de7550

Browse files
authored
fix: handle the cases of resolving destination for http backend (#177)
* fix: using path for setting destination for http backend * fix: address spotless and corrected test * fixes formatting
1 parent cd7885f commit 0de7550

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/resolver/backend/HttpBackendResolver.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ public Optional<BackendInfo> resolve(Event event, StructuredTraceGraph structure
6666
if (httpOperation != null) {
6767
enrichedAttributes.put(BACKEND_OPERATION_ATTR, AttributeValueCreator.create(httpOperation));
6868
}
69-
Optional<String> httpDestination = HttpSemanticConventionUtils.getHttpTarget(event);
70-
httpDestination.ifPresent(
71-
destination ->
72-
enrichedAttributes.put(
73-
BACKEND_DESTINATION_ATTR, AttributeValueCreator.create(destination)));
69+
70+
if (StringUtils.isNotEmpty(path)) {
71+
enrichedAttributes.put(BACKEND_DESTINATION_ATTR, AttributeValueCreator.create(path));
72+
}
7473
return Optional.of(new BackendInfo(entityBuilder.build(), enrichedAttributes));
7574
}
7675
return Optional.empty();

hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/resolver/backend/BackendResolverTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ public void checkBackendEntityGeneratedFromHttpEventType1() {
166166

167167
Map<String, AttributeValue> attributes = backendInfo.getAttributes();
168168
assertEquals(
169-
Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("/path/12314/?q=ddds#123")),
169+
Map.of(
170+
"BACKEND_DESTINATION",
171+
AttributeValueCreator.create("/product/5d644175551847d7408760b1")),
170172
attributes);
171173
}
172174

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import java.util.Map;
1515
import java.util.Optional;
1616
import org.hypertrace.core.datamodel.AttributeValue;
17-
import org.hypertrace.core.datamodel.Event;
18-
import org.hypertrace.core.datamodel.shared.SpanAttributeUtils;
1917
import org.hypertrace.core.semantic.convention.constants.http.OTelHttpSemanticConventions;
2018
import org.hypertrace.core.semantic.convention.constants.span.OTelSpanSemanticConventions;
2119
import org.hypertrace.core.span.constants.RawSpanConstants;
@@ -56,12 +54,6 @@ public static List<String> getAttributeKeysForHttpTarget() {
5654
return Lists.newArrayList(Sets.newHashSet(OTEL_HTTP_TARGET));
5755
}
5856

59-
public static Optional<String> getHttpTarget(Event event) {
60-
return Optional.ofNullable(
61-
SpanAttributeUtils.getFirstAvailableStringAttribute(
62-
event, getAttributeKeysForHttpTarget()));
63-
}
64-
6557
/**
6658
* OTel mandates one of the following set to be present for http server span - http.scheme,
6759
* http.host, http.target - http.scheme, http.server_name, net.host.port, http.target -

0 commit comments

Comments
 (0)