- Replaced Sentry breadcrumbs and context setting with a custom telemetry implementation across various components including Apps, WebView, CarouselBox, and ndView. - Introduced a new telemetry module to encapsulate observability logic and provide a unified API for logging events, messages, and exceptions. - Updated documentation to reflect changes in observability architecture, consolidating Sentry initialization and telemetry usage. - Enhanced error handling and logging in data fetching and application lifecycle management.
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import type { ComponentType } from "react";
|
|
import * as Sentry from "@sentry/react-native";
|
|
|
|
/**
|
|
* Sentry is kept behind this module so application and domain code does not
|
|
* depend directly on the vendor SDK.
|
|
*/
|
|
export function initializeSentry() {
|
|
Sentry.init({
|
|
dsn: "https://1090312e4cf501f5a455d523eff2d538@o4511646874664960.ingest.us.sentry.io/4511646880432128",
|
|
|
|
// Adds more context data to events (IP address, cookies, user, etc.)
|
|
// For more information, visit: https://docs.sentry.io/platforms/react-native/data-management/data-collected/
|
|
sendDefaultPii: true,
|
|
|
|
// Enable Logs
|
|
enableLogs: true,
|
|
|
|
// Configure Session Replay
|
|
replaysSessionSampleRate: 0.1,
|
|
replaysOnErrorSampleRate: 1,
|
|
integrations: [
|
|
Sentry.mobileReplayIntegration(),
|
|
Sentry.feedbackIntegration(),
|
|
],
|
|
|
|
tracesSampleRate: __DEV__ ? 1.0 : 0.05,
|
|
|
|
beforeSend(event) {
|
|
const dataFetch = event.contexts?.data_fetch as any;
|
|
if (dataFetch?.responseHead && typeof dataFetch.responseHead === "string") {
|
|
dataFetch.responseHead = dataFetch.responseHead.slice(0, 300);
|
|
}
|
|
return event;
|
|
},
|
|
|
|
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
|
|
// spotlight: __DEV__,
|
|
});
|
|
}
|
|
|
|
export function wrapWithSentry(component: ComponentType<Record<string, unknown>>) {
|
|
return Sentry.wrap(component);
|
|
}
|
|
|
|
export function recordBreadcrumb(...args: Parameters<typeof Sentry.addBreadcrumb>) {
|
|
Sentry.addBreadcrumb(...args);
|
|
}
|
|
|
|
export function setTelemetryTag(...args: Parameters<typeof Sentry.setTag>) {
|
|
Sentry.setTag(...args);
|
|
}
|
|
|
|
export function setTelemetryContext(...args: Parameters<typeof Sentry.setContext>) {
|
|
Sentry.setContext(...args);
|
|
}
|
|
|
|
export function captureTelemetryMessage(...args: Parameters<typeof Sentry.captureMessage>) {
|
|
return Sentry.captureMessage(...args);
|
|
}
|
|
|
|
export function captureTelemetryException(...args: Parameters<typeof Sentry.captureException>) {
|
|
return Sentry.captureException(...args);
|
|
}
|
|
|
|
export function startTelemetrySpan<T>(
|
|
options: Record<string, unknown>,
|
|
callback: () => Promise<T>,
|
|
): Promise<T> {
|
|
const startSpan = (Sentry as any).startSpan;
|
|
if (typeof startSpan !== "function") {
|
|
return callback();
|
|
}
|
|
return startSpan(options, callback);
|
|
}
|