Skip to content

Commit

Permalink
fix(core): Fix terminated context addition in span builder
Browse files Browse the repository at this point in the history
  • Loading branch information
PerfectSlayer committed Nov 6, 2023
1 parent 8dd68f2 commit 1ae9781
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1191,13 +1191,7 @@ public CoreSpanBuilder ignoreActiveSpan() {
}

private DDSpan buildSpan() {
if (parent instanceof TagContext) {
List<AgentSpanLink> 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);
Expand All @@ -1206,6 +1200,19 @@ private DDSpan buildSpan() {
return span;
}

private void addTerminatedContextAsLinks() {
if (this.parent instanceof TagContext) {
List<AgentSpanLink> 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();
Expand Down

0 comments on commit 1ae9781

Please sign in to comment.