SwiftUI Instrumentation

Learn how to monitor the performance of your SwiftUI views.

This feature is stable since version 8.17.0.

You can monitor the performance of your views in a SwiftUI project with the SentrySwiftUI library, which you can install via SPM (Swift package manager) or CocoaPods:

Copied
platform :ios, '13.0'
use_frameworks! # This is important

target 'YourApp' do
  pod 'SentrySwiftUI', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '8.33.0'
end

If you plan to add SentrySwiftUI, you don`t need to also add Sentry library since the former depends on the latter.

In order to start monitoring the performance of your views, you need to wrap it with SentryTracedView, like this:

Copied

import SentrySwiftUI

var body: some View {
    SentryTracedView("<Name of your view>"){
        List {
            // Your SwiftUI code ...
        }
    }
}

You may omit the transaction name, Sentry will use the root view type as name, in the previous example the transaction name would be List.

Alternatively, you can use a modifier like this:

Copied

import SentrySwiftUI

var body: some View {
    List {
        // Your SwiftUI code ...
    }.sentryTrace("<Name of your view>")
}

It is possible to use nested SentryTracedView to have a more granular transaction.

Copied

import SentrySwiftUI

var body: some View {
    SentryTracedView("My Awesome Screen"){
        HStack {
            SentryTracedView("Menu") {
                List{
                    // Your SwiftUI code ...
                }
            }
            SentryTracedView("Content") {
                VStack{
                    // Your SwiftUI code ...
                }
            }
        }
    }
}

This is the result

Transaction with nested traced views

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").