SwiftUI Instrumentation
This feature is currently in Beta. Beta features are still in progress and may have bugs. We recognize the irony.
You can monitor the performance of your views in a SwiftUI
projectRepresents your service in Sentry and allows you to scope events to a distinct application.
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.13.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
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
- Package:
- cocoapods:sentry-cocoa
- Version:
- 8.13.0
- Repository:
- https://github.com/getsentry/sentry-cocoa