@@ -352,16 +352,44 @@ TEST(ProbabilitySampler, OversizedValueKeepsParentTraceState)
352352 uint8_t span_id_buffer[trace_api::SpanId::kSize ] = {1 };
353353 trace_api::SpanId span_id{span_id_buffer};
354354
355- // Appending the th sub-key would exceed the 256 character value limit, so
356- // the span is sampled but the trace state is left untouched.
355+ // The oversized ot value is re-emitted unchanged because it has no th to erase.
357356 std::string ot_value = " a:" + std::string (253 , ' b' );
358357 auto trace_state = trace_api::TraceState::FromHeader (" ot=" + ot_value);
359358 trace_api::SpanContext context (trace_id, span_id, trace_api::TraceFlags{0 }, false , trace_state);
360359
361360 auto sampling_result = SampleWithContext (s1, context, TraceIdWithRandomness (0xffffffffffffff ));
362361
363362 ASSERT_EQ (Decision::RECORD_AND_SAMPLE , sampling_result.decision );
364- ASSERT_EQ (nullptr , sampling_result.trace_state );
363+ ASSERT_NE (nullptr , sampling_result.trace_state );
364+
365+ std::string result_ot;
366+ ASSERT_TRUE (sampling_result.trace_state ->Get (" ot" , result_ot));
367+ ASSERT_EQ (ot_value, result_ot);
368+ }
369+
370+ TEST (ProbabilitySampler, OversizedValueErasesStaleThreshold)
371+ {
372+ // ratio 0.1's 17-char th overflows the 256-char limit, so the stale th is erased.
373+ ProbabilitySampler s1 (0.1 );
374+
375+ uint8_t trace_id_buffer[trace_api::TraceId::kSize ] = {1 };
376+ trace_api::TraceId trace_id{trace_id_buffer};
377+ uint8_t span_id_buffer[trace_api::SpanId::kSize ] = {1 };
378+ trace_api::SpanId span_id{span_id_buffer};
379+
380+ std::string rest = " x:" + std::string (245 , ' b' );
381+ auto trace_state = trace_api::TraceState::FromHeader (" ot=th:8;" + rest);
382+ trace_api::SpanContext context (trace_id, span_id, trace_api::TraceFlags{0 }, false , trace_state);
383+
384+ auto sampling_result = SampleWithContext (s1, context, TraceIdWithRandomness (0xffffffffffffff ));
385+
386+ ASSERT_EQ (Decision::RECORD_AND_SAMPLE , sampling_result.decision );
387+ ASSERT_NE (nullptr , sampling_result.trace_state );
388+
389+ std::string result_ot;
390+ ASSERT_TRUE (sampling_result.trace_state ->Get (" ot" , result_ot));
391+ ASSERT_EQ (rest, result_ot);
392+ ASSERT_EQ (std::string::npos, result_ot.find (" th:" ));
365393}
366394
367395TEST (ProbabilitySampler, IgnoresParentSampledFlag)
0 commit comments