@@ -1514,28 +1514,31 @@ private DDSpanContext buildSpanContext() {
15141514 String parentServiceName = null ;
15151515 boolean isRemote = false ;
15161516
1517- if (parentContext != null
1518- && parentContext .isRemote ()
1519- && Config .get ().getTracePropagationBehaviorExtract ()
1520- == TracePropagationBehaviorExtract .RESTART ) {
1521- SpanLink link ;
1522- if (parentContext instanceof ExtractedContext ) {
1523- ExtractedContext pc = (ExtractedContext ) parentContext ;
1524- link =
1525- DDSpanLink .from (
1526- pc ,
1527- SpanAttributes .builder ()
1528- .put ("reason" , "propagation_behavior_extract" )
1529- .put ("context_headers" , pc .getPropagationStyle ().toString ())
1530- .build ());
1531- } else {
1532- link = SpanLink .from (parentContext );
1517+ TracePropagationBehaviorExtract behaviorExtract =
1518+ Config .get ().getTracePropagationBehaviorExtract ();
1519+ if (parentContext != null && parentContext .isRemote ()) {
1520+ if (behaviorExtract == TracePropagationBehaviorExtract .IGNORE ) {
1521+ // reset links that may have come terminated span links
1522+ links = new ArrayList <>();
1523+ parentContext = null ;
1524+ } else if (behaviorExtract == TracePropagationBehaviorExtract .RESTART ) {
1525+ links = new ArrayList <>();
1526+ SpanLink link =
1527+ (parentContext instanceof ExtractedContext )
1528+ ? DDSpanLink .from (
1529+ (ExtractedContext ) parentContext ,
1530+ SpanAttributes .builder ()
1531+ .put ("reason" , "propagation_behavior_extract" )
1532+ .put (
1533+ "context_headers" ,
1534+ ((ExtractedContext ) parentContext ).getPropagationStyle ().toString ())
1535+ .build ())
1536+ : SpanLink .from (parentContext );
1537+ links .add (link );
1538+ parentContext = null ;
15331539 }
1534- // reset links that may have come terminated span links
1535- links = new ArrayList <>();
1536- links .add (link );
1537- parentContext = null ;
15381540 }
1541+
15391542 // Propagate internal trace.
15401543 // Note: if we are not in the context of distributed tracing and we are starting the first
15411544 // root span, parentContext will be null at this point.
0 commit comments