70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import * as Sentry from '@sentry/react-native';
|
|
import { CYBERTRON_LOGS_URL, ENV, SENTRY_DSN, TUNNEL_URL } from '../../constants/config';
|
|
import { addClickstreamEvent } from '../../services/clickstreamEventService';
|
|
import { CLICKSTREAM_EVENT_NAMES } from '../../common/Constants';
|
|
import { getAppVersion } from './commonFunctions';
|
|
import { createTransport } from '@sentry/core';
|
|
import { GLOBAL } from '@constants/Global';
|
|
import CybertronLogs, { ClientType } from '@cybertron/logger/lib/main';
|
|
|
|
function makeFetchTransport(options: any): any {
|
|
function makeRequest(request: any) {
|
|
const requestOptions: RequestInit = {
|
|
body: request.body,
|
|
method: 'POST',
|
|
referrerPolicy: 'origin',
|
|
headers: options.headers,
|
|
...options.fetchOptions,
|
|
};
|
|
|
|
return fetch(options.url, requestOptions).then((response) => {
|
|
return {
|
|
statusCode: response.status,
|
|
headers: {
|
|
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
|
|
'retry-after': response.headers.get('Retry-After'),
|
|
},
|
|
};
|
|
});
|
|
}
|
|
|
|
return createTransport(options, makeRequest);
|
|
}
|
|
|
|
export async function initSentry() {
|
|
try {
|
|
Sentry.init({
|
|
dsn: SENTRY_DSN,
|
|
transport: makeFetchTransport,
|
|
tunnel: TUNNEL_URL,
|
|
beforeSend(event) {
|
|
event.extra = {
|
|
...event.extra,
|
|
release_id: getAppVersion(),
|
|
alfredSessionId: '',
|
|
metadata: {
|
|
agentId: GLOBAL?.AGENT_ID,
|
|
deviceId: GLOBAL?.DEVICE_ID,
|
|
isImpersonated: GLOBAL?.IS_IMPERSONATED,
|
|
buildFlavour: GLOBAL?.BUILD_FLAVOUR,
|
|
},
|
|
};
|
|
return event;
|
|
},
|
|
});
|
|
|
|
CybertronLogs.setOptions({
|
|
appName: 'cosmos',
|
|
env: ENV,
|
|
baseUrl: CYBERTRON_LOGS_URL,
|
|
sessionId: GLOBAL?.AGENT_ID || 'cosmos-session',
|
|
teamName: 'collections',
|
|
threshold: 10,
|
|
clientType: ClientType.APP,
|
|
});
|
|
} catch (e) {
|
|
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_SENTRY_INTEGRATION_FAILED);
|
|
console.error('Sentry initialization failed');
|
|
}
|
|
}
|