iOS

Features:

  • Multiple types of errors are captured, including:
    • Mach exceptions
    • Fatal signals
    • Unhandled exceptions
    • C++ exceptions
    • Objective-C exceptions
    • Error messages of fatalError, assert, and precondition
    • App Hang Detection (not available for watchOS)
    • Watchdog Terminations
    • HTTP Client Errors
    • Start-up crashes. The SDK init waits synchronously for up to 5 seconds to flush out events if the app crashes within 2 seconds after the SDK init.
  • Events enriched with device data
  • Offline caching when a device is unable to connect; we send a report once we receive another event
  • Breadcrumbs automatically captured for
    • Application lifecycle events (didBecomeActive, didEnterBackground, viewDidAppear)
    • Touch events
    • System events (battery level or state changed, memory warnings, device orientation changed, keyboard did show and did hide, screenshot taken)
    • Outgoing HTTP requests
  • Release health tracks crash free users and sessions
  • Automatic Performance Tracking
    • Rendering of UIViewControllers
    • Performance of HTTP requests
    • Distributed tracing
    • Mobile Vitals
      • Cold and warm start
      • Slow and frozen frames
    • Performance of file I/O operations
    • Performance of Core Data queries
    • User Interaction transactions for UI clicks
  • Attachments enrich your event by storing additional files, such as config or log files
  • User Feedback provides the ability to collect user information when an event occurs
  • Screenshot attachments for errors
  • Source Context shows snippets of code around the location of stack frames

On this page, we get you up and running with Sentry's SDK.

Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.

Sentry captures data by using an SDK within your application’s runtime.

We recommend installing the SDK through our installation wizard by running the following command inside your project directory:

Copied
brew install getsentry/tools/sentry-wizard && sentry-wizard -i ios

The wizard will prompt you to log in to Sentry. It'll then automatically do the following steps for you:

  • install the Sentry SDK via Swift Package Manager or Cocoapods
  • update your AppDelegate or SwiftUI App Initializer with the default Sentry configuration and an example error
  • add a new Upload Debug Symbols phase to your xcodebuild build script
  • create .sentryclirc with an auth token to upload debug symbols (this file is automatically added to .gitignore)
  • when you're using Fastlane, it will add a Sentry lane for uploading debug symbols

After the wizard setup is completed, the SDK will automatically capture unhandled exceptions, and monitor performance. You can also manually capture errors.

Configuration should happen as early as possible in your application's lifecycle.

Additional options can be found on our dedicated options page.

Here, you'll also be able to set context data, which includes data about the user, tags, or even arbitrary data, all of which will be added to every event sent to Sentry.

Want to play with some new features? Try out our experimental features for View Hierarchy, Time to Full Display (TTFD), MetricKit, Prewarmed App Start Tracing, Swift Async Stack Traces and App Launch Profiling. Experimental features are still a work-in-progress and may have bugs. We recognize the irony.

Let us know if you have feedback through GitHub issues.

Copied
import Sentry

SentrySDK.start { options in
    // ...

    // Enable all experimental features
    options.attachViewHierarchy = true
    options.enableMetricKit = true
    options.enableTimeToFullDisplayTracing = true
    options.swiftAsyncStacktraces = true
    options.enableAppLaunchProfiling = true
}

If you use Swift concurrency, this feature will stitch your stack traces together. That means you will be able to see the full stack trace of your async code. For this to happen you need to enable the swiftAsyncStacktraces option. You can also enable this in your Objective-C project, however, only async code written in Swift will be stitched together.

Copied
import Sentry

SentrySDK.start { options in
    // ...
    options.swiftAsyncStacktraces = true
}

If you want to find out the performance of your Views in a SwiftUI project, try the SentrySwiftUI library.

To capture crashes, you need to provide debug information to Sentry. You can also use our source context feature to display code snippets next to the event stack traces by enabling the include-sources option when uploading your debug information files. Debug information is provided by uploading dSYM files.

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

Copied
import Sentry

do {
    try aMethodThatMightFail()
} catch {
    SentrySDK.capture(error: error)
}

To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").