@@ -340,3 +340,45 @@ def test_w3c_off_x_instana_l_0(
340340 if "tracestate" in carrier_header .keys ():
341341 assert "tracestate" in downstream_carrier
342342 assert carrier_header ["tracestate" ] == downstream_carrier ["tracestate" ]
343+
344+ def test_suppression_when_child_level_is_lower (
345+ self ,
346+ _trace_id : int ,
347+ _span_id : int ,
348+ ):
349+ """
350+ Test that span_context.level is updated when the child level (extracted from carrier) is lower than the current span_context.level.
351+ """
352+ # Create a span context with level=1
353+ original_span_context = SpanContext (
354+ trace_id = _trace_id ,
355+ span_id = _span_id ,
356+ is_remote = False ,
357+ level = 1 ,
358+ )
359+
360+ # Create a carrier with level=0 (suppression)
361+ carrier_header = {"x-instana-l" : "0" }
362+
363+ # Inject the span context into the carrier
364+ self .hptc .inject (original_span_context , carrier_header )
365+
366+ # Extract the span context from the carrier to verify the level was updated
367+ extracted_context = self .hptc .extract (carrier_header )
368+
369+ # Verify that the level is 0 (suppressed)
370+ assert extracted_context .level == 0
371+ assert extracted_context .suppression
372+
373+ # Create a new carrier to test the propagation
374+ downstream_carrier = {}
375+
376+ # Inject the extracted context into the downstream carrier
377+ self .hptc .inject (extracted_context , downstream_carrier )
378+
379+ # Verify that the downstream carrier has the correct level
380+ assert downstream_carrier .get ("X-INSTANA-L" ) == "0"
381+
382+ # Verify that no trace or span IDs are injected when suppressed
383+ assert "X-INSTANA-T" not in downstream_carrier
384+ assert "X-INSTANA-S" not in downstream_carrier
0 commit comments