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 62d051c commit a015c11
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 a015c11

Please sign in to comment.