Skip to content

Commit

Permalink
fix: set private flow span kind to internal (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
manikmagar authored Feb 13, 2025
1 parent b7213c2 commit 90670e6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.mule.runtime.api.notification.EnrichedServerNotification;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -75,6 +74,8 @@ public TraceComponent getSourceStartTraceComponent(EnrichedServerNotification no
TraceComponent startTraceComponent = getStartTraceComponent(notification).withSpanKind(SpanKind.SERVER);
ComponentIdentifier sourceIdentifier = getSourceIdentifier(notification);
if (sourceIdentifier == null) {
// Private flows should be treated as internal spans
startTraceComponent.withSpanKind(SpanKind.INTERNAL);
if (notification.getEvent().getVariables().containsKey(TransactionStore.TRACE_CONTEXT_MAP_KEY)) {
// When flows are called using flow-ref, the variables may contain the parent
// span information
Expand Down Expand Up @@ -116,7 +117,7 @@ public TraceComponent getSourceStartTraceComponent(EnrichedServerNotification no
@Override
public TraceComponent getSourceEndTraceComponent(EnrichedServerNotification notification,
TraceContextHandler traceContextHandler) {
TraceComponent traceComponent = getEndTraceComponent(notification).withSpanKind(SpanKind.SERVER);
TraceComponent traceComponent = getEndTraceComponent(notification);
if (notification.getException() != null) {
traceComponent.withStatsCode(StatusCode.ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void testRootSpanStatus_OnError() throws Exception {
await().untilAsserted(() -> assertThat(spanQueue)
.hasSize(3));
assertThat(spanQueue).anySatisfy(span -> assertThat(span).extracting("spanName", "spanKind", "spanStatus")
.containsExactlyInAnyOrder("mule-core-error-flow", "SERVER", "ERROR"));
.containsExactlyInAnyOrder("mule-core-error-flow", "INTERNAL", "ERROR"));
}

@Test
Expand All @@ -38,11 +38,11 @@ public void testRootSpanStatus_FlowRef_OnError() throws Exception {
.hasSize(7));
assertThat(spanQueue).anySatisfy(span -> assertThat(span).as("flow span with exception raised")
.extracting("spanName", "spanKind", "spanStatus")
.containsExactlyInAnyOrder("mule-core-error-flow", "SERVER", "ERROR"));
.containsExactlyInAnyOrder("mule-core-error-flow", "INTERNAL", "ERROR"));
assertThat(spanQueue)
.anySatisfy(span -> assertThat(span).as("Parent flow with on-error-continue to suppress exception")
.extracting("spanName", "spanKind", "spanStatus")
.containsExactlyInAnyOrder("mule-core-call-error-flow", "SERVER", "UNSET"));
.containsExactlyInAnyOrder("mule-core-call-error-flow", "INTERNAL", "UNSET"));
}

@Test
Expand Down Expand Up @@ -271,7 +271,7 @@ public void testFlowErrorPropagationSpans() throws Exception {
assertThat(spanQueue)
.extracting("spanName")
.contains("mule-core-flow-1", "mule-core-flow-2", "mule-core-flow-3");
assertThat(getSpan("SERVER", "mule-core-flow-3").getAttributes())
assertThat(getSpan("INTERNAL", "mule-core-flow-3").getAttributes())
.containsEntry("error.type", "org.mule.runtime.core.internal.exception.MessagingException");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void getAPIKitOrders() throws Exception {
assertThat(span)
.as("Span for http:listener apikit flow")
.extracting("spanName", "spanKind", "spanStatus")
.containsOnly("get:\\orders\\(orderId):order-exp-config", "SERVER", "UNSET");
.containsOnly("get:\\orders\\(orderId):order-exp-config", "INTERNAL", "UNSET");
}));
await().untilAsserted(() -> assertThat(DelegatedLoggingSpanTestExporter.spanQueue)
.anySatisfy(span -> {
Expand Down Expand Up @@ -104,7 +104,7 @@ public void postAPIKitOrders() throws Exception {
assertThat(span)
.as("Span for http:listener apikit flow")
.extracting("spanName", "spanKind", "spanStatus")
.containsOnly("post:\\orders:application\\json:order-exp-config", "SERVER", "UNSET");
.containsOnly("post:\\orders:application\\json:order-exp-config", "INTERNAL", "UNSET");
}));
await().untilAsserted(() -> assertThat(DelegatedLoggingSpanTestExporter.spanQueue)
.anySatisfy(span -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void initDB() throws Exception {
.isNotEmpty()
.anySatisfy(span -> assertThat(span)
.extracting("spanName", "spanKind")
.containsOnly("init-db", "SERVER"));
.containsOnly("init-db", "INTERNAL"));
});
DelegatedLoggingSpanTestExporter.spanQueue.clear();
dbInitialized = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public void testFlowRefParentTraces() throws Exception {
Span sourceServer = getSpan("SERVER", "GET /test/remote/flow-ref");

Span flowRefTargetServer = getSpan("INTERNAL", "flow-ref:mule-opentelemetry-app-flow-ref-target");
Span targetServer = getSpan("SERVER", "mule-opentelemetry-app-flow-ref-target");
Span targetServer = getSpan("INTERNAL", "mule-opentelemetry-app-flow-ref-target");
assertParentSpan(flowRefTargetServer, "Flow ref of target 1 should have source as parent", sourceServer);
assertParentSpan(targetServer, "Parent flow must be a span of flow-ref of first target", flowRefTargetServer);

Span flowRefTargetServer2 = getSpan("INTERNAL", "flow-ref:mule-opentelemetry-app-flow-ref-target-2");
Span targetServer2 = getSpan("SERVER", "mule-opentelemetry-app-flow-ref-target-2");
Span targetServer2 = getSpan("INTERNAL", "mule-opentelemetry-app-flow-ref-target-2");
assertParentSpan(flowRefTargetServer2, "Flow ref of target 2 should have target 1 as parent", targetServer);
assertParentSpan(targetServer2, "Parent flow must be a span of flow-ref of second target",
flowRefTargetServer2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void testFlowRefParentTracesWithoutAllSpans() throws Exception {

DelegatedLoggingSpanTestExporter.Span flowRefTargetServer = getSpan("INTERNAL",
"flow-ref:mule-opentelemetry-app-flow-ref-target");
DelegatedLoggingSpanTestExporter.Span targetServer = getSpan("SERVER",
DelegatedLoggingSpanTestExporter.Span targetServer = getSpan("INTERNAL",
"mule-opentelemetry-app-flow-ref-target");
assertParentSpan(flowRefTargetServer, "Flow ref of target 1 should have source as parent", sourceServer);
assertParentSpan(targetServer, "Parent flow must be a span of flow-ref of first target", flowRefTargetServer);

DelegatedLoggingSpanTestExporter.Span flowRefTargetServer2 = getSpan("INTERNAL",
"flow-ref:mule-opentelemetry-app-flow-ref-target-2");
DelegatedLoggingSpanTestExporter.Span targetServer2 = getSpan("SERVER",
DelegatedLoggingSpanTestExporter.Span targetServer2 = getSpan("INTERNAL",
"mule-opentelemetry-app-flow-ref-target-2");
assertParentSpan(flowRefTargetServer2, "Flow ref of target 2 should have target 1 as parent", targetServer);
assertParentSpan(targetServer2, "Parent flow must be a span of flow-ref of second target",
Expand Down

0 comments on commit 90670e6

Please sign in to comment.