diff --git a/modules/core/src/main/java/org/apache/synapse/aspects/flow/statistics/tracing/opentelemetry/management/handling/span/SpanHandler.java b/modules/core/src/main/java/org/apache/synapse/aspects/flow/statistics/tracing/opentelemetry/management/handling/span/SpanHandler.java index f99a993c0f..70880d6eac 100644 --- a/modules/core/src/main/java/org/apache/synapse/aspects/flow/statistics/tracing/opentelemetry/management/handling/span/SpanHandler.java +++ b/modules/core/src/main/java/org/apache/synapse/aspects/flow/statistics/tracing/opentelemetry/management/handling/span/SpanHandler.java @@ -214,8 +214,10 @@ private void startSpan(StatisticDataUnit statisticDataUnit, MessageContext synCt if (isOuterLevelSpan(statisticDataUnit, spanStore)) { // Extract span context from headers context = extract(headersMap); - } else { + } else if (parentSpan != null) { context = Context.current().with(parentSpan); + } else { + context = Context.current(); } span = tracer.spanBuilder(statisticDataUnit.getComponentName()).setParent(context).startSpan();