Integrating Sentry for mobile app error tracking
Sentry differs from Firebase Crashlytics in one key way — it tracks not just crashes, but performance: transactions, spans, slow HTTP requests, ANR/hang on UI thread. For applications where not just crashes matter but UX degradation, this makes Sentry more informative.
iOS: SPM connection
Add https://github.com/getsentry/sentry-cocoa to Package Dependencies, then in AppDelegate or @main:
import Sentry
SentrySDK.start { options in
options.dsn = "https://<key>@sentry.io/<project>"
options.environment = Bundle.main.object(forInfoDictionaryKey: "SentryEnvironment") as? String ?? "production"
options.tracesSampleRate = 0.2 // 20% of transactions for performance
options.profilesSampleRate = 0.1
options.attachViewHierarchy = true // view hierarchy snapshot on crash
}
attachViewHierarchy = true — useful feature: each crash report includes UIView/SwiftUI hierarchy tree at moment of crash. Immediately see which screen and UI state the crash occurred in.
Android: Gradle + Application
implementation("io.sentry:sentry-android:7.+")
// Application.onCreate()
SentryAndroid.init(this) { options ->
options.dsn = "https://<key>@sentry.io/<project>"
options.environment = BuildConfig.SENTRY_ENVIRONMENT
options.tracesSampleRate = 0.2
options.isEnableUserInteractionTracing = true // auto-trace taps
}
isEnableUserInteractionTracing automatically creates transactions on user UI interaction. Without additional code see that "Checkout" button triggers 4.2-second network request on 3G.
Performance monitoring
// iOS: manual transaction
let transaction = SentrySDK.startTransaction(name: "checkout", operation: "ui.action")
let span = transaction.startChild(operation: "http.client", description: "POST /orders")
// ... request ...
span.finish()
transaction.finish()
Transactions appear in Performance section in Sentry. Shows p50/p75/p95/p99 percentiles, heatmap of slow requests and exact spans.
Custom tags and breadcrumbs
SentrySDK.configureScope { scope in
scope.setUser(SentryUser(userId: userId))
scope.setTag(value: "premium", key: "subscription")
scope.addBreadcrumb({
let crumb = Breadcrumb()
crumb.message = "Opened shopping cart screen"
crumb.category = "navigation"
return crumb
}())
}
Breadcrumbs — sequence of events before crash. Allow reconstructing user path without reproducing bug.
Source maps for React Native
If project is React Native — need to upload JS bundle source maps on each release:
npx sentry-cli releases \
files "$VERSION" \
upload-sourcemaps \
--dist "$BUILD_NUMBER" \
./dist/bundle.js.map
Without source maps, RN crash stack trace looks like set of anonymous functions from minified bundle.
What's included in the work
- Connecting sentry-cocoa / sentry-android / sentry-react-native
- Configuring environments (dev / staging / production)
- Performance tracing configuration with reasonable sample rate
- Scope integration: User ID, tags, breadcrumbs
- Configuring alerts on error rate and p95 latency
- Upload dSYM / ProGuard mapping / JS source maps in CI
Timeline
Basic crash reporting integration: 0.5–1 day. Full performance tracing with custom transactions: 1–2 days. Cost calculated individually.







