Skip to content

Commit 537b852

Browse files
committed
bundle size improvment (review comment)
1 parent 765f89d commit 537b852

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

packages/browser/src/profiling/lifecycleMode/traceLifecycleProfiler.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,13 @@ export class BrowserTraceLifecycleProfiler {
309309
const chunk = createProfileChunkPayload(profile, this._client!, this._profilerId);
310310

311311
// Validate chunk before sending
312-
const { valid, reason } = validateProfileChunk(chunk);
313-
if (!valid) {
312+
const validationReturn = validateProfileChunk(chunk);
313+
if ('reason' in validationReturn) {
314314
DEBUG_BUILD &&
315-
debug.log('[Profiling] Discarding invalid profile chunk (this is probably a bug in the SDK):', reason);
315+
debug.log(
316+
'[Profiling] Discarding invalid profile chunk (this is probably a bug in the SDK):',
317+
validationReturn.reason,
318+
);
316319
return;
317320
}
318321

packages/browser/src/profiling/utils.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,45 +256,45 @@ export function createProfileChunkPayload(
256256
* - Presence of samples, stacks, frames
257257
* - Required metadata fields
258258
*/
259-
export function validateProfileChunk(chunk: ProfileChunk): { valid: boolean; reason?: string } {
259+
export function validateProfileChunk(chunk: ProfileChunk): { valid: true } | { reason: string } {
260260
try {
261261
// Required metadata
262262
if (!chunk || typeof chunk !== 'object') {
263-
return { valid: false, reason: 'chunk is not an object' };
263+
return { reason: 'chunk is not an object' };
264264
}
265265

266266
// profiler_id and chunk_id must be 32 lowercase hex chars
267267
const isHex32 = (val: unknown): boolean => typeof val === 'string' && /^[a-f0-9]{32}$/.test(val);
268268
if (!isHex32(chunk.profiler_id)) {
269-
return { valid: false, reason: 'missing or invalid profiler_id' };
269+
return { reason: 'missing or invalid profiler_id' };
270270
}
271271
if (!isHex32(chunk.chunk_id)) {
272-
return { valid: false, reason: 'missing or invalid chunk_id' };
272+
return { reason: 'missing or invalid chunk_id' };
273273
}
274274

275275
if (!chunk.client_sdk) {
276-
return { valid: false, reason: 'missing client_sdk metadata' };
276+
return { reason: 'missing client_sdk metadata' };
277277
}
278278

279279
// Profile data must have frames, stacks, samples
280280
const profile = chunk.profile as { frames?: unknown[]; stacks?: unknown[]; samples?: unknown[] } | undefined;
281281
if (!profile) {
282-
return { valid: false, reason: 'missing profile data' };
282+
return { reason: 'missing profile data' };
283283
}
284284

285285
if (!Array.isArray(profile.frames) || !profile.frames.length) {
286-
return { valid: false, reason: 'profile has no frames' };
286+
return { reason: 'profile has no frames' };
287287
}
288288
if (!Array.isArray(profile.stacks) || !profile.stacks.length) {
289-
return { valid: false, reason: 'profile has no stacks' };
289+
return { reason: 'profile has no stacks' };
290290
}
291291
if (!Array.isArray(profile.samples) || !profile.samples.length) {
292-
return { valid: false, reason: 'profile has no samples' };
292+
return { reason: 'profile has no samples' };
293293
}
294294

295295
return { valid: true };
296296
} catch (e) {
297-
return { valid: false, reason: `unknown validation error: ${e}` };
297+
return { reason: `unknown validation error: ${e}` };
298298
}
299299
}
300300

0 commit comments

Comments
 (0)