NTP-11825 | CyberDroid Integration (#13584)

Co-authored-by: Shivam Goyal <shivam.goyal@navi.com>
This commit is contained in:
Prajjaval Verma
2024-12-09 20:44:23 +05:30
committed by GitHub
parent 960e1582b9
commit 878df9b50d
6 changed files with 102 additions and 9 deletions

View File

@@ -3,18 +3,20 @@ import codePush from "react-native-code-push";
import { GenericErrorScreen } from "./App/Container/Navi-Insurance";
import {
AnalyticsEventNameConstants,
BASE_SCREEN,
BundleState,
CODEPUSH_METHOD,
EVENT_NAMES,
EVENT_PROPERTY_KEYS,
EVENT_PROPERTY_VALUES,
SentryConstants,
} from "./App/common/constants";
import { sendAsAnalyticsEvent } from "./App/common/hooks/useAnalyticsEvent";
import { CtaData } from "./App/common/interface";
import RnApp from "./App/common/navigator/RnAppCreator";
import { setBuildConfigDetailsFromCta } from "./App/common/utilities/CacheUtils";
import {
getBuildConfigDetailsFromCta,
setBuildConfigDetailsFromCta,
} from "./App/common/utilities/CacheUtils";
import { initSentry } from "./App/common/utilities/SentryUtils";
import {
getStringPreference,
setStringPreference,
@@ -29,6 +31,7 @@ const preloadBundle: string = "PreloadBundle";
export default class App extends Component<{}, AppState> {
constructor(props: {}) {
super(props);
initSentry(getBuildConfigDetailsFromCta(this.getInitialCta()!!).flavor);
let bundleState = BundleState.LOADING;
getBundleStatus().then(value => (bundleState = value));
this.state = {

View File

@@ -27,6 +27,7 @@ export const AnalyticsEventNameConstants = {
HI_RN_INVALID_JSON_ERROR: "hi_rn_invalid_json_error",
HI_RN_INVALID_ARITHMETIC_ERROR: "hi_rn_invalid_arithmetic_error",
HI_RN_FETCH_NATIVE_HEADER_ERROR: "hi_rn_fetch_native_header_error",
HI_RN_SENTRY_INIT_FAIL: "hi_rn_sentry_init_fail",
};
export const AnalyticsEventPropertyConstants = {

View File

@@ -1,5 +1,10 @@
export const SentryConstants = {
SENTRY_DSN: "https://3c1639ff154fcdcfe417c485e80db17f@o4506931811254272.ingest.us.sentry.io/4506931817676800",
SENTRY_ENVIRONMENT_PRODUCTION: "production",
SENTRY_ENVIRONMENT_DEVELOPMENT: "development",
SENTRY_DSN_QA:
"https://35a300131251d53a92e5e705c316fc55@cybetron.np.navi-ppl.in/220582376234120579338115031530316318641",
SENTRY_DSN_PROD:
"https://c7ea344069d4ddea1d969cbe89a300f5@cybetron.np.navi-ppl.in/232196262456315044471201793383582317162",
TUNNEL_URL_QA:
"https://qa-sa.navi.com/cybertron/api/220582376234120579338115031530316318641/envelope?sentry_key=35a300131251d53a92e5e705c316fc55",
TUNNEL_URL_PROD:
"https://sa.navi.com/cybertron/api/232196262456315044471201793383582317162/envelope?sentry_key=c7ea344069d4ddea1d969cbe89a300f5",
};

View File

@@ -0,0 +1,81 @@
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;
});
};

View File

@@ -1,5 +1,5 @@
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
const { withSentryConfig } = require("@sentry/react-native/metro");
/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
@@ -8,4 +8,6 @@ const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
*/
const config = {};
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
module.exports = withSentryConfig(
mergeConfig(getDefaultConfig(__dirname), config),
);

View File

@@ -29,6 +29,7 @@
"@react-navigation/stack": "^6.3.17",
"@react-spring/native": "9.5.5",
"@reduxjs/toolkit": "^1.9.5",
"@sentry/react-native": "^5.35.0",
"axios": "^1.4.0",
"lodash": "^4.17.21",
"lottie-react-native": "^5.1.6",