diff --git a/libs/browser/src/lib/services/browser-micro-sentry-client.spec.ts b/libs/browser/src/lib/services/browser-micro-sentry-client.spec.ts index 6ea2789..24f248b 100644 --- a/libs/browser/src/lib/services/browser-micro-sentry-client.spec.ts +++ b/libs/browser/src/lib/services/browser-micro-sentry-client.spec.ts @@ -286,6 +286,7 @@ describe('BrowserMicroSentryClient', () => { }, tags: { tag: 'value' }, timestamp: expect.any(Number), + event_id: expect.any(String), }); }); @@ -309,6 +310,7 @@ describe('BrowserMicroSentryClient', () => { }, tags: { tag: 'value' }, timestamp: expect.any(Number), + event_id: expect.any(String), }); }); }); diff --git a/libs/core/src/lib/helpers/uuid4.spec.ts b/libs/core/src/lib/helpers/uuid4.spec.ts new file mode 100644 index 0000000..bbc3f18 --- /dev/null +++ b/libs/core/src/lib/helpers/uuid4.spec.ts @@ -0,0 +1,16 @@ +import { uuid4 } from './uuid4'; + +describe('uuid4', () => { + it('should be 32 characters long', () => { + expect(uuid4().length).toBe(32); + }); + + it('should be lowercase', () => { + const result = uuid4(); + expect(result).toEqual(result.toLowerCase()); + }); + + it('should not contain dashes', () => { + expect(uuid4()).not.toContain('-'); + }); +}); diff --git a/libs/core/src/lib/helpers/uuid4.ts b/libs/core/src/lib/helpers/uuid4.ts new file mode 100644 index 0000000..47841c2 --- /dev/null +++ b/libs/core/src/lib/helpers/uuid4.ts @@ -0,0 +1,15 @@ +/** + * @description Hexadecimal string representing a uuid4 value. + * The length is exactly 32 characters. + * Dashes are not allowed. + * Has to be lowercase. + * @see https://develop.sentry.dev/sdk/event-payloads/#required-attributes + */ +export function uuid4(): string { + return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, (c) => { + const r = (Math.random() * 16) | 0; + const v = c === 'x' ? r : (r & 0x3) | 0x8; + + return v.toString(16); + }); +} diff --git a/libs/core/src/lib/models/models.ts b/libs/core/src/lib/models/models.ts index 653054a..563f258 100644 --- a/libs/core/src/lib/models/models.ts +++ b/libs/core/src/lib/models/models.ts @@ -37,6 +37,7 @@ export interface SentryRequestBody { version: string; }; timestamp: number; + event_id: string; request?: { url?: string; headers?: { diff --git a/libs/core/src/lib/service/micro-sentry-client.spec.ts b/libs/core/src/lib/service/micro-sentry-client.spec.ts index 5487c61..750ca14 100644 --- a/libs/core/src/lib/service/micro-sentry-client.spec.ts +++ b/libs/core/src/lib/service/micro-sentry-client.spec.ts @@ -66,6 +66,7 @@ describe('MiniSentryClient', () => { version: expect.any(String), }, timestamp: expect.any(Number), + event_id: expect.any(String), }); }); }); diff --git a/libs/core/src/lib/service/micro-sentry-client.ts b/libs/core/src/lib/service/micro-sentry-client.ts index e498441..1ad9abd 100644 --- a/libs/core/src/lib/service/micro-sentry-client.ts +++ b/libs/core/src/lib/service/micro-sentry-client.ts @@ -2,6 +2,7 @@ import { SentryRequestBody } from '../models/models'; import { AUTH_HEADER, DSN_REGEXP } from '../consts/consts'; import { computeStackTrace } from '../helpers/compute-stack-trace'; import { SentryClientOptions } from '../models/sentry-client-options'; +import { uuid4 } from '../helpers/uuid4'; export class MicroSentryClient { readonly authHeader?: string; @@ -65,6 +66,7 @@ export class MicroSentryClient { protected getRequestBlank(): SentryRequestBody { return { platform: 'javascript', + event_id: uuid4(), sdk: { name: 'micro-sentry.javascript.core', version: '0.0.0',