-
Notifications
You must be signed in to change notification settings - Fork 58
/
index.js
69 lines (62 loc) · 1.71 KB
/
index.js
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
62
63
64
65
66
67
68
69
/**
* External dependencies
*/
import { NativeModules, Platform } from 'react-native';
import * as Sentry from '@sentry/react-native';
const { RNSentry } = NativeModules;
const IGNORED_DEFAULT_INTEGRATIONS = [
'Release',
'Breadcrumbs',
'UserAgent',
'DeviceContext',
];
export function initialize( options ) {
// Disable Sentry initialization on Android because it's not available yet.
if ( Platform.OS === 'android' ) {
return;
}
if ( ! options ) {
// eslint-disable-next-line no-console
console.warn(
"Sentry options are not defined so it won't be initialized."
);
return;
}
const { dsn, environment, releaseName } = options;
Sentry.init( {
dsn,
debug: __DEV__,
environment,
release: releaseName,
dist: releaseName,
beforeSend: async ( event ) => {
const shouldSendEvent = await RNSentry.shouldSendEvent();
if ( ! shouldSendEvent ) {
return false;
}
// The scope from the native side is attached to the event.
const eventWithScope = await RNSentry.attachScopeToEvent( event );
// Set user fetched from native side to the event.
eventWithScope.user = await RNSentry.getUser();
return eventWithScope;
},
integrations: ( items ) => {
const filteredIntegrations = items.filter(
( item ) => ! IGNORED_DEFAULT_INTEGRATIONS.includes( item.name )
);
// Breadcrumbs integration is required to enable breadcumbs in the event.
// As the breadcrumbs will be set by the main apps, we disable all the tracking options.
filteredIntegrations.push(
new Sentry.BrowserIntegrations.Breadcrumbs( {
console: false,
dom: false,
fetch: false,
history: false,
sentry: false,
xhr: false,
} )
);
return filteredIntegrations;
},
} );
}