MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / validateProfileChunk

Function validateProfileChunk

packages/browser/src/profiling/utils.ts:259–299  ·  view source on GitHub ↗
(chunk: ProfileChunk)

Source from the content-addressed store, hash-verified

257 * - Required metadata fields
258 */
259export function validateProfileChunk(chunk: ProfileChunk): { valid: true } | { reason: string } {
260 try {
261 // Required metadata
262 if (!chunk || typeof chunk !== 'object') {
263 return { reason: 'chunk is not an object' };
264 }
265
266 // profiler_id and chunk_id must be 32 lowercase hex chars
267 const isHex32 = (val: unknown): boolean => typeof val === 'string' && /^[a-f0-9]{32}$/.test(val);
268 if (!isHex32(chunk.profiler_id)) {
269 return { reason: 'missing or invalid profiler_id' };
270 }
271 if (!isHex32(chunk.chunk_id)) {
272 return { reason: 'missing or invalid chunk_id' };
273 }
274
275 if (!chunk.client_sdk) {
276 return { reason: 'missing client_sdk metadata' };
277 }
278
279 // Profile data must have frames, stacks, samples
280 const profile = chunk.profile as { frames?: unknown[]; stacks?: unknown[]; samples?: unknown[] } | undefined;
281 if (!profile) {
282 return { reason: 'missing profile data' };
283 }
284
285 if (!Array.isArray(profile.frames) || !profile.frames.length) {
286 return { reason: 'profile has no frames' };
287 }
288 if (!Array.isArray(profile.stacks) || !profile.stacks.length) {
289 return { reason: 'profile has no stacks' };
290 }
291 if (!Array.isArray(profile.samples) || !profile.samples.length) {
292 return { reason: 'profile has no samples' };
293 }
294
295 return { valid: true };
296 } catch (e) {
297 return { reason: `unknown validation error: ${e}` };
298 }
299}
300
301/**
302 * Convert from JSSelfProfile format to ContinuousThreadCpuProfile format.

Callers 1

_collectCurrentChunkMethod · 0.90

Calls 1

isHex32Function · 0.85

Tested by

no test coverage detected