|
| 1 | +--TEST-- |
| 2 | +Live debugger log probe capture timeout with large data structure |
| 3 | +--SKIPIF-- |
| 4 | +<?php include __DIR__ . '/../includes/skipif_no_dev_env.inc'; ?> |
| 5 | +--ENV-- |
| 6 | +DD_AGENT_HOST=request-replayer |
| 7 | +DD_TRACE_AGENT_PORT=80 |
| 8 | +DD_TRACE_GENERATE_ROOT_SPAN=0 |
| 9 | +DD_DYNAMIC_INSTRUMENTATION_ENABLED=1 |
| 10 | +DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS=0.1 |
| 11 | +DD_DYNAMIC_INSTRUMENTATION_CAPTURE_TIMEOUT_MS=1 |
| 12 | +--INI-- |
| 13 | +datadog.trace.agent_test_session_token=live-debugger/log_probe_capture_timeout |
| 14 | +--FILE-- |
| 15 | +<?php |
| 16 | + |
| 17 | +require __DIR__ . "/live_debugger.inc"; |
| 18 | + |
| 19 | +reset_request_replayer(); |
| 20 | + |
| 21 | +function large_capture($huge_array) {} |
| 22 | + |
| 23 | +await_probe_installation(function() { |
| 24 | + build_log_probe([ |
| 25 | + "where" => ["methodName" => "large_capture"], |
| 26 | + "captureSnapshot" => true, |
| 27 | + "segments" => [["str" => "capture timeout test"]], |
| 28 | + ]); |
| 29 | + \DDTrace\start_span(); |
| 30 | +}); |
| 31 | + |
| 32 | +// 3-level array: 10 outer x 100 mid x 100 inner strings (100-char each) |
| 33 | +// ~100,000 capture operations: reliably exceeds the 1ms CPU-time timeout |
| 34 | +$data = []; |
| 35 | +for ($i = 0; $i < 99; $i++) { |
| 36 | + $data[] = array_fill(0, 10, array_fill(0, 100, str_repeat('x', 100))); |
| 37 | +} |
| 38 | +$last = array_fill(0, 99, str_repeat('x', 100)); |
| 39 | +$last[] = 'LAST_SENTINEL'; |
| 40 | +$data[] = $last; |
| 41 | + |
| 42 | +large_capture($data); |
| 43 | + |
| 44 | +$dlr = new DebuggerLogReplayer; |
| 45 | +$log = $dlr->waitForDebuggerDataAndReplay(); |
| 46 | +$captures = json_decode($log["body"], true)[0]["debugger"]["snapshot"]["captures"]; |
| 47 | +$captures_json = json_encode($captures); |
| 48 | + |
| 49 | +// Snapshot was delivered with some captured data |
| 50 | +var_dump(!empty($captures)); |
| 51 | + |
| 52 | +// Timeout reason must appear somewhere in the captured data |
| 53 | +var_dump(strpos($captures_json, '"timeout"') !== false); |
| 54 | + |
| 55 | +// The last element must NOT have been captured before the timeout fired |
| 56 | +var_dump(strpos($captures_json, 'LAST_SENTINEL') === false); |
| 57 | + |
| 58 | +?> |
| 59 | +--CLEAN-- |
| 60 | +<?php |
| 61 | +require __DIR__ . "/live_debugger.inc"; |
| 62 | +reset_request_replayer(); |
| 63 | +?> |
| 64 | +--EXPECT-- |
| 65 | +bool(true) |
| 66 | +bool(true) |
| 67 | +bool(true) |
0 commit comments