Skip to content

Commit

Permalink
feat: add required event_id param (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevaru authored Nov 22, 2023
1 parent 1d658ce commit f8d00a5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ describe('BrowserMicroSentryClient', () => {
},
tags: { tag: 'value' },
timestamp: expect.any(Number),
event_id: expect.any(String),
});
});

Expand All @@ -309,6 +310,7 @@ describe('BrowserMicroSentryClient', () => {
},
tags: { tag: 'value' },
timestamp: expect.any(Number),
event_id: expect.any(String),
});
});
});
Expand Down
16 changes: 16 additions & 0 deletions libs/core/src/lib/helpers/uuid4.spec.ts
Original file line number Diff line number Diff line change
@@ -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('-');
});
});
15 changes: 15 additions & 0 deletions libs/core/src/lib/helpers/uuid4.ts
Original file line number Diff line number Diff line change
@@ -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);
});
}
1 change: 1 addition & 0 deletions libs/core/src/lib/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface SentryRequestBody {
version: string;
};
timestamp: number;
event_id: string;
request?: {
url?: string;
headers?: {
Expand Down
1 change: 1 addition & 0 deletions libs/core/src/lib/service/micro-sentry-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('MiniSentryClient', () => {
version: expect.any(String),
},
timestamp: expect.any(Number),
event_id: expect.any(String),
});
});
});
2 changes: 2 additions & 0 deletions libs/core/src/lib/service/micro-sentry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit f8d00a5

Please sign in to comment.