From 64614d73e06ea0d83e15b9804eabb81af3528d27 Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Sat, 12 Sep 2026 18:08:02 -0700 Subject: [PATCH] perf: reuse diagnostic bundle byte count (#20292) Co-authored-by: Orca Worker --- src/main/observability/bundle.test.ts | 19 +++++++++++++++++++ src/main/observability/bundle.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/observability/bundle.test.ts b/src/main/observability/bundle.test.ts index 3c6644a7d43..58593c36848 100644 --- a/src/main/observability/bundle.test.ts +++ b/src/main/observability/bundle.test.ts @@ -58,6 +58,25 @@ describe('bundle — submission ID', () => { }) describe('bundle — collection', () => { + it.each([ + { kind: 'empty', names: [] }, + { kind: 'ASCII', names: ['plain'] }, + { kind: 'Unicode', names: ['漢字🙂', '\ud800'] }, + { kind: 'capped', names: Array.from({ length: 600 }, () => '漢字🙂'.repeat(1000)) } + ])('reports the exact UTF-8 payload size for $kind records', ({ names }) => { + writeFileSync(traceFile, makeNDJSON(names.map((name) => makeSpan({ name })))) + const bundle = collectBundle({ + traceFilePath: traceFile, + maxFiles: 1, + appVersion: '1', + platform: 'win32', + arch: 'x64', + osRelease: 'test', + orcaChannel: 'dev' + }) + expect(bundle.bytes).toBe(Buffer.byteLength(bundle.payload)) + }) + it('emits a header line with bundle_submission_id, app_version, platform', () => { writeFileSync(traceFile, makeNDJSON([makeSpan()])) const bundle = collectBundle({ diff --git a/src/main/observability/bundle.ts b/src/main/observability/bundle.ts index 750f41fead9..5e841a4d37e 100644 --- a/src/main/observability/bundle.ts +++ b/src/main/observability/bundle.ts @@ -167,7 +167,7 @@ export function collectBundle(opts: CollectBundleOptions): CollectedBundle { return { bundleSubmissionId, payload, - bytes: Buffer.byteLength(payload), + bytes: currentBytes, spanCount } }