Skip to content

Commit 7250486

Browse files
committed
chore: drop line truncation, update payload size test
1 parent 11c6ca8 commit 7250486

2 files changed

Lines changed: 5 additions & 30 deletions

File tree

lib/ExceptionCapture.php

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
class ExceptionCapture
66
{
7-
// Keep source context bounded so large local variables / generated code snippets do not push
8-
// $exception payloads past the transport size limit.
9-
private const MAX_CONTEXT_LINE_LENGTH = 200;
10-
117
private static bool $includeSourceContext = true;
128
private static int $contextLines = 5;
139
private static int $maxFrames = 20;
@@ -289,40 +285,19 @@ private static function addContextLines(array &$frame, string $filePath, int $li
289285
return;
290286
}
291287

292-
$frame['context_line'] = self::truncateContextLine($lines[$idx]);
288+
$frame['context_line'] = $lines[$idx];
293289

294290
$preStart = max(0, $idx - self::$contextLines);
295291
if ($preStart < $idx) {
296-
$frame['pre_context'] = array_map(
297-
[self::class, 'truncateContextLine'],
298-
array_slice($lines, $preStart, $idx - $preStart)
299-
);
292+
$frame['pre_context'] = array_slice($lines, $preStart, $idx - $preStart);
300293
}
301294

302295
$postEnd = min($total, $idx + self::$contextLines + 1);
303296
if ($postEnd > $idx + 1) {
304-
$frame['post_context'] = array_map(
305-
[self::class, 'truncateContextLine'],
306-
array_slice($lines, $idx + 1, $postEnd - $idx - 1)
307-
);
297+
$frame['post_context'] = array_slice($lines, $idx + 1, $postEnd - $idx - 1);
308298
}
309299
} catch (\Throwable $e) {
310300
// Silently ignore file read errors
311301
}
312302
}
313-
314-
private static function truncateContextLine(string $line): string
315-
{
316-
if (strlen($line) <= self::MAX_CONTEXT_LINE_LENGTH) {
317-
return $line;
318-
}
319-
320-
if (self::MAX_CONTEXT_LINE_LENGTH <= 3) {
321-
return substr($line, 0, self::MAX_CONTEXT_LINE_LENGTH);
322-
}
323-
324-
// Truncation is intentionally fixed and internal-only: it protects payload size without
325-
// reintroducing another public tuning knob.
326-
return substr($line, 0, self::MAX_CONTEXT_LINE_LENGTH - 3) . '...';
327-
}
328303
}

test/ExceptionCaptureTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public function testCaptureExceptionReturnsFalseForInvalidInput(): void
445445
$this->client->captureException([]);
446446
}
447447

448-
public function testCaptureExceptionPayloadStaysBelowLibCurlLimitForLargeSourceContext(): void
448+
public function testCaptureExceptionPayloadStaysBelowCurrentTransportLimit(): void
449449
{
450450
$scriptPath = tempnam(sys_get_temp_dir(), 'posthog-exception-');
451451
$this->assertNotFalse($scriptPath);
@@ -496,7 +496,7 @@ function recurseForPayloadLimit(int \$n): void
496496
]);
497497

498498
$this->assertNotFalse($payload);
499-
$this->assertLessThan(32 * 1024, strlen($payload));
499+
$this->assertLessThan(1024 * 1024, strlen($payload));
500500
} finally {
501501
unlink($scriptPath);
502502
}

0 commit comments

Comments
 (0)