Files
self/app/src/Sentry.ts
Justin Hernandez 12aff535de chore(app): resolve lint warnings (#990)
* chore(app): resolve lint warnings

* update lock

* clean up any types

* fix types

* feedback from cr
2025-08-29 21:01:24 -07:00

124 lines
2.7 KiB
TypeScript

// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
import { SENTRY_DSN } from '@env';
import {
captureException as sentryCaptureException,
captureFeedback as sentryCaptureFeedback,
captureMessage as sentryCaptureMessage,
consoleLoggingIntegration,
feedbackIntegration,
init as sentryInit,
wrap,
} from '@sentry/react-native';
export const captureException = (
error: Error,
context?: Record<string, unknown>,
) => {
if (isSentryDisabled) {
return;
}
sentryCaptureException(error, {
extra: context,
});
};
export const captureFeedback = (
feedback: string,
context?: Record<string, unknown>,
) => {
if (isSentryDisabled) {
return;
}
sentryCaptureFeedback(
{
message: feedback,
name: context?.name as string | undefined,
email: context?.email as string | undefined,
tags: {
category: (context?.category as string) || 'general',
source: (context?.source as string) || 'feedback_modal',
},
},
{
captureContext: {
tags: {
category: (context?.category as string) || 'general',
source: (context?.source as string) || 'feedback_modal',
},
},
},
);
};
export const captureMessage = (
message: string,
context?: Record<string, unknown>,
) => {
if (isSentryDisabled) {
return;
}
sentryCaptureMessage(message, {
extra: context,
});
};
export const initSentry = () => {
if (isSentryDisabled) {
return;
}
sentryInit({
dsn: SENTRY_DSN,
debug: false,
enableAutoSessionTracking: true,
// Performance Monitoring
tracesSampleRate: 1.0,
// Session Replay
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
// Disable collection of PII data
beforeSend(event) {
// Remove PII data
if (event.user) {
delete event.user.ip_address;
delete event.user.id;
}
return event;
},
integrations: [
consoleLoggingIntegration({
levels: ['log', 'error', 'warn', 'info', 'debug'],
}),
feedbackIntegration({
buttonOptions: {
styles: {
triggerButton: {
position: 'absolute',
top: 20,
right: 20,
bottom: undefined,
marginTop: 100,
},
},
},
enableTakeScreenshot: true,
namePlaceholder: 'Fullname',
emailPlaceholder: 'Email',
}),
],
_experiments: {
enableLogs: true,
},
});
};
export const isSentryDisabled = !SENTRY_DSN;
export const wrapWithSentry = (App: React.ComponentType) => {
return isSentryDisabled ? App : wrap(App);
};