82 lines
2.1 KiB
TypeScript
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;
|
|
});
|
|
};
|