import * as Sentry from '@sentry/react-native'; import type { Span } from '@sentry/types'; import Constants from 'expo-constants'; declare const __DEV__: boolean; const DSN = process.env.EXPO_PUBLIC_SENTRY_DSN; export const IS_DEV = __DEV__; export const MONITOR_ENABLED = !IS_DEV || process.env.EXPO_PUBLIC_MONITOR_ENABLED === 'true'; export function initSentry(): void { if (!MONITOR_ENABLED || !DSN) return; try { Sentry.init({ dsn: DSN, debug: IS_DEV, environment: IS_DEV ? 'development' : 'production', release: `palace-mobile@${Constants.expoConfig?.version ?? '0.0.0'}`, tracesSampleRate: IS_DEV ? 1.0 : 0.1, profilesSampleRate: IS_DEV ? 1.0 : 0.5, enableAutoSessionTracking: true, enableAutoPerformanceTracing: true, }); } catch (e) { console.warn('Telemetry initialization failed:', e); } } export type { Span }; type SpanOptions = Parameters[0]; export function startSpan(options: SpanOptions, callback: (span: Span) => T): T { return Sentry.startSpan(options, callback); } export function startInactiveSpan(options: SpanOptions & { parentSpan?: Span }): Span | undefined { return Sentry.startInactiveSpan(options); } export function captureException(error: unknown, context?: Record): void { Sentry.captureException(error, context ? { extra: context } : undefined); } export async function flushIfDev(): Promise { if (IS_DEV) await Sentry.flush(); }