diff --git a/dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java b/dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java index dae7c75cfce..684b3794ba0 100644 --- a/dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java +++ b/dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java @@ -1191,13 +1191,7 @@ public CoreSpanBuilder ignoreActiveSpan() { } private DDSpan buildSpan() { - if (parent instanceof TagContext) { - List terminatedContextLinks = - ((TagContext) parent).getTerminatedContextLinks(); - if (!terminatedContextLinks.isEmpty()) { - links.addAll(terminatedContextLinks); - } - } + addTerminatedContextAsLinks(); DDSpan span = DDSpan.create(instrumentationName, timestampMicro, buildSpanContext(), links); if (span.isLocalRootSpan()) { EndpointTracker tracker = tracer.onRootSpanStarted(span); @@ -1206,6 +1200,19 @@ private DDSpan buildSpan() { return span; } + private void addTerminatedContextAsLinks() { + if (this.parent instanceof TagContext) { + List terminatedContextLinks = + ((TagContext) this.parent).getTerminatedContextLinks(); + if (!terminatedContextLinks.isEmpty()) { + if (this.links == null) { + this.links = new ArrayList<>(); + } + this.links.addAll(terminatedContextLinks); + } + } + } + @Override public AgentSpan start() { return buildSpan();