Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions tests/ext/background-sender/agent_sampling-standalone-asm_01.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,36 @@ datadog.trace.agent_test_session_token=background-sender/agent_samplingc
include __DIR__ . '/../includes/request_replayer.inc';

$rr = new RequestReplayer();
$rr->maxIteration = 2000;

$picked = 0;
$notPicked = 0;
$maxIterations = 10;
$maxIterations = 5;
for ($i = 0; $i < $maxIterations; $i++)
{
//Do call and get sampling
\DDTrace\start_span();
\DDTrace\close_span();
$root = json_decode($rr->waitForDataAndReplay()["body"], true);
// Flush the span synchronously before reading from the request replayer
dd_trace_internal_fn("synchronous_flush");
$root = json_decode($rr->waitForDataAndReplay()["body"], true);
$spans = $root["chunks"][0]["spans"] ?? $root[0];
$sampling = $spans[0]["metrics"]["_sampling_priority_v1"];
dd_trace_internal_fn("synchronous_flush");

if($sampling == 1 && $picked == 1) //Start again, probably different minute
{
$notPicked = 0;
continue;
} else if ($sampling == 1) { //First picked
if ($sampling == 1) { // First pick this minute (or minute rollover)
$picked = 1;
} else if ($sampling == 0) {
$notPicked++;
} else if($picked == 0 && $sampling == 0) {
//If this happen means something is odd already
break;
$notPicked = 0;
continue;
}

// Ignore zeros until we've seen the first 1
if ($picked == 0) {
continue;
}

// After first 1, count zeros
if ($sampling == 0) {
$notPicked++;
}
if ($picked == 1 && $notPicked == 2) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ datadog.trace.agent_test_session_token=background-sender/agent_samplingb
include __DIR__ . '/../includes/request_replayer.inc';

$rr = new RequestReplayer();
$rr->maxIteration = 2000;

$get_sampling = function() use ($rr) {
$root = json_decode($rr->waitForDataAndReplay()["body"], true);
Expand All @@ -27,21 +26,23 @@ $get_sampling = function() use ($rr) {

\DDTrace\start_span();
\DDTrace\close_span();
dd_trace_internal_fn("synchronous_flush");
echo "First call it is used as heartbeat: {$get_sampling()}\n";

dd_trace_internal_fn("synchronous_flush");

\DDTrace\start_span();
DDTrace\Testing\emit_asm_event();
\DDTrace\close_span();
echo "This call has the same sample rate: {$get_sampling()}\n";

// reset it for other tests
dd_trace_internal_fn("synchronous_flush");
echo "This call has the same sample rate: {$get_sampling()}\n";



\DDTrace\start_span();
DDTrace\Testing\emit_asm_event();
\DDTrace\close_span();
dd_trace_internal_fn("synchronous_flush");
echo "This call also has the same sample rate: {$get_sampling()}\n";

?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ datadog.trace.agent_test_session_token=background-sender/agent_samplinga
include __DIR__ . '/../includes/request_replayer.inc';

$rr = new RequestReplayer();
$rr->maxIteration = 2000;

$get_sampling = function() use ($rr) {
$root = json_decode($rr->waitForDataAndReplay()["body"], true);
Expand All @@ -32,19 +31,22 @@ $get_sampling = function() use ($rr) {

\DDTrace\start_span();
\DDTrace\close_span();
dd_trace_internal_fn("synchronous_flush");

echo "First call it is used as heartbeat: {$get_sampling()}\n";

dd_trace_internal_fn("synchronous_flush");

\DDTrace\start_span();
\DDTrace\close_span();
echo "This call has the same sample rate: {$get_sampling()}\n";

// reset it for other tests
dd_trace_internal_fn("synchronous_flush");
echo "This call has the same sample rate: {$get_sampling()}\n";



\DDTrace\start_span();
\DDTrace\close_span();
dd_trace_internal_fn("synchronous_flush");
echo "This call also has the same sample rate: {$get_sampling()}\n";
?>
--EXPECTF--
Expand Down
Loading