> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shipnative.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Tracking

> Error monitoring with Sentry

Shipnative uses [Sentry](https://sentry.io/) for error tracking and performance monitoring.

## Setup

```bash theme={null}
yarn setup
```

The wizard prompts for your Sentry DSN.

Or manually add to `apps/app/.env`:

```bash theme={null}
EXPO_PUBLIC_SENTRY_DSN=https://key@sentry.io/project-id
```

**Without DSN:** Errors log to console. Connect Sentry early to catch errors with full stack traces and context.

***

## Usage

### Track Errors

```typescript theme={null}
import { trackError } from '@/utils/analytics'

try {
  // risky code
} catch (error) {
  trackError(error as Error, {
    tags: { screen: 'Checkout', action: 'payment' },
    extra: { amount: 99.99 },
  })
}
```

### Log Messages

```typescript theme={null}
import { trackMessage } from '@/utils/analytics'

trackMessage('User completed onboarding', 'info')
trackMessage('API rate limit approaching', 'warning')
```

### User Context

```typescript theme={null}
import { setUserContext, clearUserContext } from '@/utils/analytics'

// After login
setUserContext({ id: 'user-123', email: 'user@example.com' })

// After logout
clearUserContext()
```

### Breadcrumbs

```typescript theme={null}
import { addBreadcrumb } from '@/utils/analytics'

addBreadcrumb({
  category: 'navigation',
  message: 'Navigated to Settings',
})
```

### Direct Sentry Access

```typescript theme={null}
import { sentry } from '@/services/sentry'

sentry.captureException(new Error('Something went wrong'))
sentry.captureMessage('Info message', 'info')
```

***

## Testing

**Mock mode:** Errors log to console as `[MockSentry] Exception: ...`

**Real Sentry:**

1. Add DSN to `.env`
2. Trigger an error: `throw new Error('Test error')`
3. View in Sentry Dashboard → Issues

***

## Troubleshooting

**Errors not showing in Sentry?**

* Verify DSN is correct
* Check network connectivity
* Allow a few seconds for upload

**Still in mock mode?**

* Verify `apps/app/.env` has `EXPO_PUBLIC_SENTRY_DSN`
* Restart Metro: `yarn start --clear`

For more, see [Sentry React Native SDK](https://docs.sentry.io/platforms/react-native/).
