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

Function uuid4

packages/core/src/utils/misc.ts:36–57  ·  view source on GitHub ↗
(crypto = getCrypto())

Source from the content-addressed store, hash-verified

34 * @returns string Generated UUID4.
35 */
36export function uuid4(crypto = getCrypto()): string {
37 try {
38 if (crypto?.randomUUID) {
39 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
40 return withRandomSafeContext(() => crypto.randomUUID!()).replace(/-/g, '');
41 }
42 } catch {
43 // some runtimes can crash invoking crypto
44 // https://github.com/getsentry/sentry-javascript/issues/8935
45 }
46
47 if (!emptyUuid) {
48 // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
49 // Concatenating the following numbers as strings results in '10000000100040008000100000000000'
50 emptyUuid = ([1e7] as unknown as string) + 1e3 + 4e3 + 8e3 + 1e11;
51 }
52
53 return emptyUuid.replace(/[018]/g, c =>
54 // eslint-disable-next-line no-bitwise
55 ((c as unknown as number) ^ ((getRandomByte() & 15) >> ((c as unknown as number) / 4))).toString(16),
56 );
57}
58
59function getFirstException(event: Event): Exception | undefined {
60 return event.exception?.values?.[0];

Callers 15

utils.test.tsFile · 0.90
_initializeChunkMethod · 0.90
maybeProfileSpanFunction · 0.90
scope.test.tsFile · 0.90
misc.test.tsFile · 0.90
captureExceptionFunction · 0.90
captureMessageFunction · 0.90
captureEventFunction · 0.90
captureCheckInMethod · 0.90

Calls 5

withRandomSafeContextFunction · 0.90
getCryptoFunction · 0.85
getRandomByteFunction · 0.85
replaceMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected