Skip to main content

Lesson 5 of 10

Logging & Crash Reporting - Sentry

Production logging is the difference between fixing a crash in minutes vs hours. Sentry captures unhandled exceptions, JavaScript errors, and even native crashes, with the full stack trace and context.

20 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Sentry Setup and Usage

Sentry Setup and Usage
npx expo install @sentry/react-native
npx sentry-wizard@latest -i reactNative --saas

// App.tsx
import * as Sentry from '@sentry/react-native';

Sentry.init({
  dsn: process.env.EXPO_PUBLIC_SENTRY_DSN,
  environment: process.env.EXPO_PUBLIC_ENV ?? 'development',
  release: `${Application.applicationId}@${Application.nativeApplicationVersion}+${Application.nativeBuildVersion}`,
  dist: Application.nativeBuildVersion ?? undefined,
  debug: __DEV__,
  tracesSampleRate: __DEV__ ? 1.0 : 0.2,
  profilesSampleRate: 0.1,
  integrations: [
    Sentry.reactNativeTracingIntegration(), // trace navigations
  ],
  // Filter noise
  beforeSend(event) {
    if (__DEV__) return null;    // don't send dev errors
    return event;
  },
});

export default Sentry.wrap(function App() {
  return <RootNavigator />;
});

// ---- Capture events ----
// Log non-fatal error with context
Sentry.withScope(scope => {
  scope.setUser({ id: userId, email: userEmail });
  scope.setTag('flow', 'checkout');
  scope.setContext('cart', { items: cart.items.length, total: cart.total });
  scope.setLevel('error');
  Sentry.captureException(error);
});

// Add breadcrumbs (navigation trail)
Sentry.addBreadcrumb({
  category: 'navigation',
  message: 'Navigated to ProductDetail',
  data: { productId },
  level: 'info',
});

// Custom performance transaction
const transaction = Sentry.startTransaction({ name: 'checkout' });
Sentry.getCurrentHub().configureScope(scope => scope.setSpan(transaction));
// ... do work ...
transaction.finish();

Tip

Tip

Practice Logging Crash Reporting Sentry in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Symbolicating minified JS stack traces and tracking user breadcrumbs with Sentry

Practice Task

Note

Practice Task - (1) Write a working example of Logging Crash Reporting Sentry from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Logging Crash Reporting Sentry is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.

Topics in This Module

0/10 done