-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathprepareReplayEvent.ts
61 lines (51 loc) · 1.64 KB
/
prepareReplayEvent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { getIsolationScope, prepareEvent } from '@sentry/core';
import type { Client, EventHint, ReplayEvent, Scope } from '@sentry/core';
/**
* Prepare a replay event & enrich it with the SDK metadata.
*/
export async function prepareReplayEvent({
client,
scope,
replayId: event_id,
event,
}: {
client: Client;
scope: Scope;
replayId: string;
event: ReplayEvent;
}): Promise<ReplayEvent | null> {
const integrations =
typeof client['_integrations'] === 'object' &&
client['_integrations'] !== null &&
!Array.isArray(client['_integrations'])
? Object.keys(client['_integrations'])
: undefined;
const eventHint: EventHint = { event_id, integrations };
client.emit('preprocessEvent', event, eventHint);
const preparedEvent = (await prepareEvent(
client.getOptions(),
event,
eventHint,
scope,
client,
getIsolationScope(),
)) as ReplayEvent | null;
// If e.g. a global event processor returned null
if (!preparedEvent) {
return null;
}
client.emit('postprocessEvent', preparedEvent, eventHint);
// This normally happens in browser client "_prepareEvent"
// but since we do not use this private method from the client, but rather the plain import
// we need to do this manually.
preparedEvent.platform = preparedEvent.platform || 'javascript';
// extract the SDK name because `client._prepareEvent` doesn't add it to the event
const metadata = client.getSdkMetadata();
const { name, version } = metadata?.sdk || {};
preparedEvent.sdk = {
...preparedEvent.sdk,
name: name || 'sentry.javascript.unknown',
version: version || '0.0.0',
};
return preparedEvent;
}