Files
super-app/App/common/utilities/SentryUtils.ts
Prajjaval Verma 878df9b50d NTP-11825 | CyberDroid Integration (#13584)
Co-authored-by: Shivam Goyal <shivam.goyal@navi.com>
2024-12-09 15:14:23 +00:00

82 lines
2.1 KiB
TypeScript

import { createTransport } from "@sentry/core";
import * as Sentry from "@sentry/react-native";
import { getBundleVersion } from "../../../network/NetworkUtils";
import { AnalyticsEventNameConstants, SentryConstants } from "../constants";
import { sendAsAnalyticsEvent } from "../hooks/useAnalyticsEvent";
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(env?: string) {
try {
Sentry.init({
dsn:
env === "prod"
? SentryConstants.SENTRY_DSN_PROD
: SentryConstants.SENTRY_DSN_QA,
transport: makeFetchTransport,
tunnel:
env === "prod"
? SentryConstants.TUNNEL_URL_PROD
: SentryConstants.TUNNEL_URL_QA,
beforeSend(event) {
event.extra = {
...event.extra,
release_id: getBundleVersion().toString(),
alfredSessionId: "",
metadata: {},
};
return event;
},
});
} catch (e) {
sendAsAnalyticsEvent({
name: AnalyticsEventNameConstants.HI_RN_SENTRY_INIT_FAIL,
properties: {
error: `${e}`,
},
});
}
}
export const logError = (error: Error, extraInfo = "") => {
if (__DEV__) {
return;
}
Sentry.captureException(error, scope => {
scope.setExtra("ExtraInfo", extraInfo);
return scope;
});
};
export const sentryCaptureMessage = (errorStr: string, extraInfo = "") => {
if (__DEV__) {
return;
}
Sentry.captureMessage(errorStr, scope => {
scope.setExtra("ExtraInfo", extraInfo);
return scope;
});
};