From 625a7e75b6cac0e70dce9180790f6981f014c7c6 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Sun, 11 Jul 2021 17:20:16 +0530 Subject: [PATCH 1/7] Mark span as APIBoundary if service name differs from parent service name --- .../ApiBoundaryTypeAttributeEnricher.java | 11 ++++++++++- .../AbstractAttributeEnricherTest.java | 1 + .../ApiBoundaryTypeAttributeEnricherTest.java | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java index d4132b539..03d905abc 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java @@ -84,10 +84,12 @@ public void enrichEvent(StructuredTrace trace, Event event) { Determines if this is entry span is an entry to api 1. If the event is an ENTRY span, and 2. If the direct parent span is either an EXIT Span or Null, then this is the entry point. + 3. If the direct parent span service name different from current span service name. */ Event parentEvent = graph.getParentEvent(event); - if (!EnrichedSpanUtils.isEntrySpan(parentEvent)) { + if (!EnrichedSpanUtils.isEntrySpan(parentEvent) + || areBothSpansFromDifferentService(event, parentEvent)) { addEnrichedAttribute( event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(ENTRY_BOUNDARY_TYPE)); @@ -119,6 +121,13 @@ public void enrichEvent(StructuredTrace trace, Event event) { } } + private boolean areBothSpansFromDifferentService(Event event, Event parentEvent) { + if (event.getServiceName() == null || parentEvent.getServiceName() == null) { + return false; + } + return !StringUtils.equals(event.getServiceName(), parentEvent.getServiceName()); + } + /** * Extracts the host header from the span and adds it as an enriched attributed to the span. Note: * This could potentially be either pulled into a separate enricher later or this enricher class diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/AbstractAttributeEnricherTest.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/AbstractAttributeEnricherTest.java index b5f114072..21d4cb854 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/AbstractAttributeEnricherTest.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/AbstractAttributeEnricherTest.java @@ -69,6 +69,7 @@ Event createMockEvent() { lenient() .when(e.getMetrics()) .thenReturn(Metrics.newBuilder().setMetricMap(new HashMap<>()).build()); + when(e.getServiceName()).thenReturn("service"); return e; } diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricherTest.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricherTest.java index f81272693..127bba232 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricherTest.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricherTest.java @@ -118,6 +118,24 @@ public void test_enrichEvent_doubleEntryExitSpan_markTheOuterOneAsApiBoundary() Constants.getEnrichedSpanConstant(EXIT)); } + @Test + public void test_enrichEvent_doubleEntrySpan_differentServiceName() { + // OuterEntry -> inner Entry -> inner Exit -> outer Exit + mockDoubleEntryStructuredGraph(); + target.enrichEvent(trace, outerEntrySpan); + Assertions.assertEquals( + EnrichedSpanUtils.getApiBoundaryType(outerEntrySpan), + Constants.getEnrichedSpanConstant(ENTRY)); + target.enrichEvent(trace, innerEntrySpan); + Assertions.assertNull(EnrichedSpanUtils.getApiBoundaryType(innerEntrySpan)); + mockDoubleEntryStructuredGraph(); + when(innerEntrySpan.getServiceName()).thenReturn("service2"); + target.enrichEvent(trace, innerEntrySpan); + Assertions.assertEquals( + EnrichedSpanUtils.getApiBoundaryType(innerEntrySpan), + Constants.getEnrichedSpanConstant(ENTRY)); + } + @Test public void test_enrichEvent_loopToItsOwnService_findTwoAPIEntries() { // Entry to API 1 -> Exit From API 1 & Re-entry -> Entry to API 1 -> Exit to API 2 From 57016e7c68bb5ed5b852e1e96a34fe9198fa320c Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Sun, 11 Jul 2021 17:26:31 +0530 Subject: [PATCH 2/7] Updated documentation --- .../enrichers/ApiBoundaryTypeAttributeEnricher.java | 6 +++--- .../enrichers/ApiBoundaryTypeAttributeEnricherTest.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java index 03d905abc..b07d0af93 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java @@ -82,9 +82,9 @@ public void enrichEvent(StructuredTrace trace, Event event) { if (isEntrySpan) { /* Determines if this is entry span is an entry to api - 1. If the event is an ENTRY span, and - 2. If the direct parent span is either an EXIT Span or Null, then this is the entry point. - 3. If the direct parent span service name different from current span service name. + 1. If the event is an ENTRY span, and if the direct parent span is either an EXIT Span or Null. + OR + 2. If the event is an ENTRY span, and the direct parent span service name different from current span service name. */ Event parentEvent = graph.getParentEvent(event); diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricherTest.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricherTest.java index 127bba232..2f3be1baf 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricherTest.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/test/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricherTest.java @@ -124,16 +124,16 @@ public void test_enrichEvent_doubleEntrySpan_differentServiceName() { mockDoubleEntryStructuredGraph(); target.enrichEvent(trace, outerEntrySpan); Assertions.assertEquals( - EnrichedSpanUtils.getApiBoundaryType(outerEntrySpan), - Constants.getEnrichedSpanConstant(ENTRY)); + EnrichedSpanUtils.getApiBoundaryType(outerEntrySpan), + Constants.getEnrichedSpanConstant(ENTRY)); target.enrichEvent(trace, innerEntrySpan); Assertions.assertNull(EnrichedSpanUtils.getApiBoundaryType(innerEntrySpan)); mockDoubleEntryStructuredGraph(); when(innerEntrySpan.getServiceName()).thenReturn("service2"); target.enrichEvent(trace, innerEntrySpan); Assertions.assertEquals( - EnrichedSpanUtils.getApiBoundaryType(innerEntrySpan), - Constants.getEnrichedSpanConstant(ENTRY)); + EnrichedSpanUtils.getApiBoundaryType(innerEntrySpan), + Constants.getEnrichedSpanConstant(ENTRY)); } @Test From c0eed4a437c5cddcd979f00a094af9cbc6fdd164 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Sun, 11 Jul 2021 17:29:45 +0530 Subject: [PATCH 3/7] Updated doc --- .../enrichers/ApiBoundaryTypeAttributeEnricher.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java index b07d0af93..c33aa5526 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java @@ -82,9 +82,8 @@ public void enrichEvent(StructuredTrace trace, Event event) { if (isEntrySpan) { /* Determines if this is entry span is an entry to api - 1. If the event is an ENTRY span, and if the direct parent span is either an EXIT Span or Null. - OR - 2. If the event is an ENTRY span, and the direct parent span service name different from current span service name. + 1. If the event is an ENTRY span, and + 2. If the direct parent span is either an EXIT Span or Null, or direct parent span service name differs from current span service name. */ Event parentEvent = graph.getParentEvent(event); From ebcb730fc65941369975c1c23d9881d31b992de6 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Thu, 15 Jul 2021 13:03:52 +0530 Subject: [PATCH 4/7] Add edge between entry services --- .../trace/util/ApiTraceGraph.java | 26 +++++++++++++++++++ .../trace/util/GraphBuilderUtil.java | 10 +++++++ .../ApiBoundaryTypeAttributeEnricher.java | 10 ++----- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java index e1630c1a8..72df1fdd7 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java @@ -325,6 +325,32 @@ private void buildApiNodeEdges(StructuredTraceGraph graph) { } } } + // Sometimes an exit span might be missing for services like Istio, Kong. + // Only Entry spans will be populated for these services, + // an edge must be created between these services as well. + Optional entryBoundaryEvent = apiNode.getEntryApiBoundaryEvent(); + if (entryBoundaryEvent.isPresent()) { + List children = graph.getChildrenEvents(entryBoundaryEvent.get()); + if (children != null) { + for (Event child : children) { + // if the child of an entry boundary event is an entry api boundary type, + // which can happen if exit span missing and both belongs to different services. + if (EnrichedSpanUtils.isEntryApiBoundary(child) + && GraphBuilderUtil.areBothSpansFromDifferentService( + child, entryBoundaryEvent.get())) { + ApiNode destinationApiNode = entryApiBoundaryEventIdToApiNode.get(child); + LOGGER.debug( + "Edge between entry boundaries {} to {} ", + entryBoundaryEvent.get().getServiceName(), + child.getServiceName()); + Optional edgeBetweenApiNodes = + createEdgeBetweenApiNodes( + apiNode, destinationApiNode, entryBoundaryEvent.get(), child); + edgeBetweenApiNodes.ifPresent(apiNodeEventEdgeList::add); + } + } + } + } } } diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/GraphBuilderUtil.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/GraphBuilderUtil.java index 188977f10..1557355d5 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/GraphBuilderUtil.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/GraphBuilderUtil.java @@ -1,5 +1,7 @@ package org.hypertrace.traceenricher.trace.util; +import org.apache.commons.lang3.StringUtils; +import org.hypertrace.core.datamodel.Event; import org.hypertrace.core.datamodel.StructuredTrace; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,4 +58,12 @@ static boolean isTraceEntitiesChanged(StructuredTrace cachedTrace, StructuredTra } return false; } + + /** Check whether these spans belongs to different services. */ + public static boolean areBothSpansFromDifferentService(Event event, Event parentEvent) { + if (event.getServiceName() == null || parentEvent.getServiceName() == null) { + return false; + } + return !StringUtils.equals(event.getServiceName(), parentEvent.getServiceName()); + } } diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java index c33aa5526..f6632f835 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java @@ -24,6 +24,7 @@ import org.hypertrace.traceenricher.enrichedspan.constants.v1.Http; import org.hypertrace.traceenricher.enrichedspan.constants.v1.Protocol; import org.hypertrace.traceenricher.enrichment.AbstractTraceEnricher; +import org.hypertrace.traceenricher.trace.util.GraphBuilderUtil; /** * This is to determine if the span is the entry / exit point for a particular API. We can't use the @@ -88,7 +89,7 @@ public void enrichEvent(StructuredTrace trace, Event event) { Event parentEvent = graph.getParentEvent(event); if (!EnrichedSpanUtils.isEntrySpan(parentEvent) - || areBothSpansFromDifferentService(event, parentEvent)) { + || GraphBuilderUtil.areBothSpansFromDifferentService(event, parentEvent)) { addEnrichedAttribute( event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(ENTRY_BOUNDARY_TYPE)); @@ -120,13 +121,6 @@ public void enrichEvent(StructuredTrace trace, Event event) { } } - private boolean areBothSpansFromDifferentService(Event event, Event parentEvent) { - if (event.getServiceName() == null || parentEvent.getServiceName() == null) { - return false; - } - return !StringUtils.equals(event.getServiceName(), parentEvent.getServiceName()); - } - /** * Extracts the host header from the span and adds it as an enriched attributed to the span. Note: * This could potentially be either pulled into a separate enricher later or this enricher class From 060f5ebe7bcafdeb706c61dc40d86c9e345daa78 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Thu, 15 Jul 2021 13:32:32 +0530 Subject: [PATCH 5/7] Updated doc --- .../trace/util/ApiTraceGraph.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java index 72df1fdd7..c18a7bd88 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java @@ -272,12 +272,11 @@ private ApiNode buildApiNode(StructuredTraceGraph graph, Event rootEvent) private void buildApiNodeEdges(StructuredTraceGraph graph) { // 1. get all the exit boundary events from an api node - // 2. exit boundary events are the only ones which can call a different api node - // 3. find all the children of exit boundary events, which will be entry boundary nodes of + // 2. find all the children of exit boundary events, which will be entry boundary nodes of // different api nodes - // 4. find all the api nodes based on children of exit boundary events from + // 3. find all the api nodes based on children of exit boundary events from // `entryBoundaryToApiNode` - // 5. connect the exit boundary and entry boundary of different api node with an edge + // 4. connect the exit boundary and entry boundary of different api node with an edge for (ApiNode apiNode : apiNodeList) { // exit boundary events of api node List exitBoundaryEvents = apiNode.getExitApiBoundaryEvents(); @@ -328,6 +327,11 @@ private void buildApiNodeEdges(StructuredTraceGraph graph) { // Sometimes an exit span might be missing for services like Istio, Kong. // Only Entry spans will be populated for these services, // an edge must be created between these services as well. + // 1. get entry boundary event from an api node. + // 2. find all the children of entry boundary event, which will be entry boundary nodes of + // different api nodes + // 3. Check both parent span and child belong to different service as well. + // 4. connect the entry boundary of different api nodes with an edge. Optional entryBoundaryEvent = apiNode.getEntryApiBoundaryEvent(); if (entryBoundaryEvent.isPresent()) { List children = graph.getChildrenEvents(entryBoundaryEvent.get()); @@ -340,9 +344,12 @@ private void buildApiNodeEdges(StructuredTraceGraph graph) { child, entryBoundaryEvent.get())) { ApiNode destinationApiNode = entryApiBoundaryEventIdToApiNode.get(child); LOGGER.debug( - "Edge between entry boundaries {} to {} ", + "Edge between entry boundaries servicename: {} span: {} to servicename: {} span: {} of trace {}", entryBoundaryEvent.get().getServiceName(), - child.getServiceName()); + HexUtils.getHex(entryBoundaryEvent.get().getEventId()), + child.getServiceName(), + HexUtils.getHex(child.getEventId()), + HexUtils.getHex(trace.getTraceId())); Optional edgeBetweenApiNodes = createEdgeBetweenApiNodes( apiNode, destinationApiNode, entryBoundaryEvent.get(), child); From 034ffff0618e7e57e604630f03a60bf2c9097e96 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Thu, 15 Jul 2021 13:46:17 +0530 Subject: [PATCH 6/7] Fix logging --- .../traceenricher/trace/util/ApiTraceGraph.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java index c18a7bd88..2c97160b1 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java @@ -343,13 +343,15 @@ private void buildApiNodeEdges(StructuredTraceGraph graph) { && GraphBuilderUtil.areBothSpansFromDifferentService( child, entryBoundaryEvent.get())) { ApiNode destinationApiNode = entryApiBoundaryEventIdToApiNode.get(child); - LOGGER.debug( - "Edge between entry boundaries servicename: {} span: {} to servicename: {} span: {} of trace {}", - entryBoundaryEvent.get().getServiceName(), - HexUtils.getHex(entryBoundaryEvent.get().getEventId()), - child.getServiceName(), - HexUtils.getHex(child.getEventId()), - HexUtils.getHex(trace.getTraceId())); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "Edge between entry boundaries servicename: {} span: {} to servicename: {} span: {} of trace {}", + entryBoundaryEvent.get().getServiceName(), + HexUtils.getHex(entryBoundaryEvent.get().getEventId()), + child.getServiceName(), + HexUtils.getHex(child.getEventId()), + HexUtils.getHex(trace.getTraceId())); + } Optional edgeBetweenApiNodes = createEdgeBetweenApiNodes( apiNode, destinationApiNode, entryBoundaryEvent.get(), child); From 28b588002b1da5b26ec709902c2cdaff80c9ca74 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Thu, 15 Jul 2021 14:42:46 +0530 Subject: [PATCH 7/7] Moved utility to EnrichedSpanUtils --- .../constants/utils/EnrichedSpanUtils.java | 9 +++++++++ .../traceenricher/trace/util/ApiTraceGraph.java | 2 +- .../traceenricher/trace/util/GraphBuilderUtil.java | 10 ---------- .../enrichers/ApiBoundaryTypeAttributeEnricher.java | 3 +-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/hypertrace-trace-enricher/enriched-span-constants/src/main/java/org/hypertrace/traceenricher/enrichedspan/constants/utils/EnrichedSpanUtils.java b/hypertrace-trace-enricher/enriched-span-constants/src/main/java/org/hypertrace/traceenricher/enrichedspan/constants/utils/EnrichedSpanUtils.java index dbcb1d824..99bb9e7f8 100644 --- a/hypertrace-trace-enricher/enriched-span-constants/src/main/java/org/hypertrace/traceenricher/enrichedspan/constants/utils/EnrichedSpanUtils.java +++ b/hypertrace-trace-enricher/enriched-span-constants/src/main/java/org/hypertrace/traceenricher/enrichedspan/constants/utils/EnrichedSpanUtils.java @@ -8,6 +8,7 @@ import java.util.Map; import java.util.Optional; import org.apache.avro.reflect.Nullable; +import org.apache.commons.codec.binary.StringUtils; import org.hypertrace.core.datamodel.AttributeValue; import org.hypertrace.core.datamodel.Event; import org.hypertrace.core.datamodel.shared.SpanAttributeUtils; @@ -368,4 +369,12 @@ public static List getSpaceIds(Event event) { .map(AttributeValue::getValueList) .orElseGet(Collections::emptyList); } + + /** Check whether these spans belongs to different services. */ + public static boolean areBothSpansFromDifferentService(Event event, Event parentEvent) { + if (event.getServiceName() == null || parentEvent.getServiceName() == null) { + return false; + } + return !StringUtils.equals(event.getServiceName(), parentEvent.getServiceName()); + } } diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java index 2c97160b1..2e790c442 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/ApiTraceGraph.java @@ -340,7 +340,7 @@ private void buildApiNodeEdges(StructuredTraceGraph graph) { // if the child of an entry boundary event is an entry api boundary type, // which can happen if exit span missing and both belongs to different services. if (EnrichedSpanUtils.isEntryApiBoundary(child) - && GraphBuilderUtil.areBothSpansFromDifferentService( + && EnrichedSpanUtils.areBothSpansFromDifferentService( child, entryBoundaryEvent.get())) { ApiNode destinationApiNode = entryApiBoundaryEventIdToApiNode.get(child); if (LOGGER.isDebugEnabled()) { diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/GraphBuilderUtil.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/GraphBuilderUtil.java index 1557355d5..188977f10 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/GraphBuilderUtil.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-api/src/main/java/org/hypertrace/traceenricher/trace/util/GraphBuilderUtil.java @@ -1,7 +1,5 @@ package org.hypertrace.traceenricher.trace.util; -import org.apache.commons.lang3.StringUtils; -import org.hypertrace.core.datamodel.Event; import org.hypertrace.core.datamodel.StructuredTrace; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,12 +56,4 @@ static boolean isTraceEntitiesChanged(StructuredTrace cachedTrace, StructuredTra } return false; } - - /** Check whether these spans belongs to different services. */ - public static boolean areBothSpansFromDifferentService(Event event, Event parentEvent) { - if (event.getServiceName() == null || parentEvent.getServiceName() == null) { - return false; - } - return !StringUtils.equals(event.getServiceName(), parentEvent.getServiceName()); - } } diff --git a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java index f6632f835..cf4fdbda0 100644 --- a/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java +++ b/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/ApiBoundaryTypeAttributeEnricher.java @@ -24,7 +24,6 @@ import org.hypertrace.traceenricher.enrichedspan.constants.v1.Http; import org.hypertrace.traceenricher.enrichedspan.constants.v1.Protocol; import org.hypertrace.traceenricher.enrichment.AbstractTraceEnricher; -import org.hypertrace.traceenricher.trace.util.GraphBuilderUtil; /** * This is to determine if the span is the entry / exit point for a particular API. We can't use the @@ -89,7 +88,7 @@ public void enrichEvent(StructuredTrace trace, Event event) { Event parentEvent = graph.getParentEvent(event); if (!EnrichedSpanUtils.isEntrySpan(parentEvent) - || GraphBuilderUtil.areBothSpansFromDifferentService(event, parentEvent)) { + || EnrichedSpanUtils.areBothSpansFromDifferentService(event, parentEvent)) { addEnrichedAttribute( event, API_BOUNDARY_TYPE_ATTR_NAME, AttributeValueCreator.create(ENTRY_BOUNDARY_TYPE));