@@ -205,16 +205,20 @@ public void updateTraceSamplingPriority(int samplingPriority, int samplingMechan
205
205
206
206
@ Override
207
207
public void updatePropagatedTraceSource (final int product ) {
208
- // if is nort marked for the product
209
- if (!ProductTraceSource .isProductMarked (productTraceSource .get (), product )) {
210
- // This should invalidate any cached w3c and datadog header
211
- clearCachedHeader (DATADOG );
212
- clearCachedHeader (W3C );
213
- productTraceSource .updateAndGet (
214
- value ->
215
- ProductTraceSource .updateProduct (
216
- value , product )); // Set the bit for the given product
217
- }
208
+ productTraceSource .updateAndGet (
209
+ currentValue -> {
210
+ // If the product is already marked, return the same value (no change)
211
+ if (ProductTraceSource .isProductMarked (currentValue , product )) {
212
+ return currentValue ;
213
+ }
214
+
215
+ // Invalidate cached headers (atomic context ensures correctness)
216
+ clearCachedHeader (DATADOG );
217
+ clearCachedHeader (W3C );
218
+
219
+ // Set the bit for the given product
220
+ return ProductTraceSource .updateProduct (currentValue , product );
221
+ });
218
222
}
219
223
220
224
@ Override
@@ -357,12 +361,13 @@ int getXDatadogTagsSize() {
357
361
size = PTagsCodec .calcXDatadogTagsSize (getTagPairs ());
358
362
size = PTagsCodec .calcXDatadogTagsSize (size , DECISION_MAKER_TAG , decisionMakerTagValue );
359
363
size = PTagsCodec .calcXDatadogTagsSize (size , TRACE_ID_TAG , traceIdHighOrderBitsHexTagValue );
360
- if (productTraceSource .get () != 0 ) {
364
+ int currentProductTraceSource = productTraceSource .get ();
365
+ if (currentProductTraceSource != 0 ) {
361
366
size =
362
367
PTagsCodec .calcXDatadogTagsSize (
363
368
size ,
364
369
TRACE_SOURCE_TAG ,
365
- TagValue .from (ProductTraceSource .getBitfieldHex (productTraceSource . get () )));
370
+ TagValue .from (ProductTraceSource .getBitfieldHex (currentProductTraceSource )));
366
371
}
367
372
xDatadogTagsSize = size ;
368
373
}
0 commit comments