Skip to content

Commit abb89b6

Browse files
shivamku-BSclaude
andcommitted
fix(o11y): drop the string truncation, keep only what the batching needs [SDK-7399]
The 128KB per-event cap and 8KB string truncation were written for an earlier, wrong theory (that oversized payloads were the cause). Batching is what fixes the timeout, so the truncation fixed nothing and would have changed behaviour for customers who work fine today: any command arg or log string over 8KB would have started arriving truncated. Removed. Nothing under 512KB is altered any more. Kept: the 512KB batch split, which is required -- a batch of many events can otherwise cross the ~1MB per-cy.task ceiling measured on a remote terminal (768KB passes, 1MB fails). Added: a single event larger than 512KB is dropped with a log line instead of being sent. That is not a fidelity regression -- before batching such an event was dispatched on its own and would have failed the command anyway, taking the spec with it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent f64d61d commit abb89b6

1 file changed

Lines changed: 10 additions & 33 deletions

File tree

bin/testObservability/cypress/index.js

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,10 @@ const getCircularReplacer = () => {
3232
* the Node o11y handler expects a structured event payload, not an error stub. Skipping keeps
3333
* graceful degradation total: no crash, and no malformed event reaches the collector.
3434
*
35-
* [SDK-7399] An oversized cy.task payload fails the command, and because the flush runs
36-
* inside a mocha hook that failure skips every remaining test in the spec. Measured on a
37-
* remote Windows terminal: a single 64KB payload succeeds, 1MB and 8MB fail; event COUNT
38-
* is not the problem (1000 small events succeed). Command args are the realistic source
39-
* of bulk, so cap individual strings first and only drop the event if it is still too
40-
* large. Preventing the oversized dispatch is what keeps the customer's suite intact —
41-
* containment alone cannot, since the failure surfaces after the enqueue call returns.
4235
*/
43-
const MAX_TASK_PAYLOAD_CHARS = 128 * 1024;
44-
const MAX_STRING_CHARS = 8 * 1024;
45-
const TRUNCATION_MARKER = '…[browserstack: truncated]';
46-
47-
const getTruncatingReplacer = () => {
48-
const seen = new WeakSet();
49-
return (key, value) => {
50-
if (typeof value === 'string' && value.length > MAX_STRING_CHARS) {
51-
return value.slice(0, MAX_STRING_CHARS) + TRUNCATION_MARKER;
52-
}
53-
if (typeof value === 'object' && value !== null) {
54-
if (seen.has(value)) return '[Circular]';
55-
seen.add(value);
56-
}
57-
return value;
58-
};
59-
};
60-
61-
/* Returns a JSON-safe plain object small enough to ship, or `null` to skip the event. */
6236
const sanitizeForTask = (data) => {
6337
try {
64-
let json = JSON.stringify(data, getCircularReplacer());
65-
if (json === undefined) return null;
66-
if (json.length > MAX_TASK_PAYLOAD_CHARS) {
67-
json = JSON.stringify(data, getTruncatingReplacer());
68-
if (json === undefined || json.length > MAX_TASK_PAYLOAD_CHARS) return null;
69-
}
70-
return JSON.parse(json);
38+
return JSON.parse(JSON.stringify(data, getCircularReplacer()));
7139
} catch (e) {
7240
return null;
7341
}
@@ -427,6 +395,15 @@ const flushEventsQueue = () => {
427395
return;
428396
}
429397
const size = JSON.stringify(payload).length;
398+
if (size > MAX_BATCH_CHARS) {
399+
/* A single event this large cannot be sent under the ~1MB per-cy.task ceiling
400+
* measured on a remote terminal (768KB passes, 1MB fails). Dropping it is not a
401+
* fidelity regression: before batching it was dispatched alone and would have
402+
* failed the command anyway. Nothing smaller is altered or truncated. */
403+
warnFlushFailure(`event too large to send for '${event.task}' (${size} chars)`,
404+
new Error('event skipped'));
405+
return;
406+
}
430407
if (batchChars + size > MAX_BATCH_CHARS) sendBatch();
431408
batch.push({ task: event.task, data: payload });
432409
batchChars += size;

0 commit comments

Comments
 (0)