Skip to content

Commit 55abee0

Browse files
committed
feat(profiling[cocoa]): update docs for profiling v2
1 parent 78869b0 commit 55abee0

File tree

3 files changed

+147
-74
lines changed

3 files changed

+147
-74
lines changed

docs/platforms/apple/common/index.mdx

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ To capture all errors, initialize the SDK as soon as possible, such as in your `
8787

8888
<PlatformSection notSupported={["apple.tvos", "apple.watchos", "apple.visionos"]}>
8989

90-
```swift {tabTitle:Swift} {"onboardingOptions": {"performance": "13-16", "profiling": "18-28"}}
90+
```swift {tabTitle:Swift} {"onboardingOptions": {"performance": "13-16", "profiling": "17-21"}}
9191
import Sentry
9292

9393
func application(_ application: UIApplication,
@@ -101,27 +101,21 @@ func application(_ application: UIApplication,
101101
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
102102
options.sendDefaultPii = true
103103

104-
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
104+
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
105105
// We recommend adjusting this value in production.
106-
options.tracesSampleRate = 1.0
106+
options.tracesSampleRate = 1
107+
108+
options.configureProfiling = {
109+
$0.lifecycle = .trace
110+
$0.sessionSampleRate = 1
111+
}
107112
}
108113

109-
// Manually call startProfiler and stopProfiler to profile any code that runs in between.
110-
SentrySDK.startProfiler()
111-
112-
//
113-
// ...anything here will be profiled...
114-
//
115-
116-
// Calls to stopProfiler are optional - if you don't stop the profiler, it will keep profiling
117-
// your application until the process exits, the app goes to the background, or stopProfiling is called.
118-
SentrySDK.stopProfiler()
119-
120114
return true
121115
}
122116
```
123117

124-
```objc {tabTitle:Objective-C} {"onboardingOptions": {"performance": "12-15", "profiling": "17-27"}}
118+
```objc {tabTitle:Objective-C} {"onboardingOptions": {"performance": "12-15", "profiling": "16-20"}}
125119
@import Sentry;
126120

127121
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
@@ -136,25 +130,19 @@ func application(_ application: UIApplication,
136130

137131
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
138132
// We recommend adjusting this value in production.
139-
options.tracesSampleRate = @1.0;
133+
options.tracesSampleRate = @1.f;
134+
135+
options.configureProfiling = ^(SentryProfileOptions *profiling) {
136+
profiling.lifecycle = SentryProfileLifecycleTrace;
137+
profiling.sessionSampleRate = 1.f;
138+
};
140139
}];
141140

142-
// Manually call startProfiler and stopProfiler to profile any code that runs in between.
143-
[SentrySDK startProfiler];
144-
145-
//
146-
// ...anything here will be profiled...
147-
//
148-
149-
// Calls to stopProfiler are optional - if you don't stop the profiler, it will keep profiling
150-
// your application until the process exits, the app goes to the background, or stopProfiling is called.
151-
[SentrySDK stopProfiler];
152-
153141
return YES;
154142
}
155143
```
156144

157-
```swift {tabTitle:SwiftUI with App conformer} {"onboardingOptions": {"performance": "13-16", "profiling": "18-28"}}
145+
```swift {tabTitle:SwiftUI with App conformer} {"onboardingOptions": {"performance": "13-16", "profiling": "17-21"}}
158146
import Sentry
159147

160148
@main
@@ -168,29 +156,23 @@ struct SwiftUIApp: App {
168156
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
169157
options.sendDefaultPii = true
170158

171-
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
159+
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
172160
// We recommend adjusting this value in production.
173-
options.tracesSampleRate = 1.0
161+
options.tracesSampleRate = 1
162+
163+
options.configureProfiling = {
164+
$0.lifecycle = .trace
165+
$0.sessionSampleRate = 1
166+
}
174167
}
175-
176-
// Manually call startProfiler and stopProfiler to profile any code that runs in between.
177-
SentrySDK.startProfiler()
178-
179-
//
180-
// ...anything here will be profiled...
181-
//
182-
183-
// Calls to stopProfiler are optional - if you don't stop the profiler, it will keep profiling
184-
// your application until the process exits, the app goes to the background, or stopProfiling is called.
185-
SentrySDK.stopProfiler()
186168
}
187169
}
188170
```
189171
</PlatformSection>
190172

191173
<PlatformSection notSupported={["apple.ios", "apple.macos"]}>
192174

193-
```swift {tabTitle:Swift} {"onboardingOptions": {"performance": "13-16"}}
175+
```swift {tabTitle:Swift} {"onboardingOptions": {"performance": "13-16", "profiling": "17-21"}}
194176
import Sentry
195177

196178
func application(_ application: UIApplication,
@@ -204,16 +186,21 @@ func application(_ application: UIApplication,
204186
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
205187
options.sendDefaultPii = true
206188

207-
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
189+
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
208190
// We recommend adjusting this value in production.
209-
options.tracesSampleRate = 1.0
191+
options.tracesSampleRate = 1
192+
193+
options.configureProfiling = {
194+
$0.lifecycle = .trace
195+
$0.sessionSampleRate = 1
196+
}
210197
}
211198

212199
return true
213200
}
214201
```
215202

216-
```objc {tabTitle:Objective-C} {"onboardingOptions": {"performance": "12-15"}}
203+
```objc {tabTitle:Objective-C} {"onboardingOptions": {"performance": "12-15", "profiling": "16-20"}}
217204
@import Sentry;
218205

219206
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
@@ -228,14 +215,19 @@ func application(_ application: UIApplication,
228215

229216
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
230217
// We recommend adjusting this value in production.
231-
options.tracesSampleRate = @1.0;
218+
options.tracesSampleRate = @1.f;
219+
220+
options.configureProfiling = ^(SentryProfileOptions *profiling) {
221+
profiling.lifecycle = SentryProfileLifecycleTrace;
222+
profiling.sessionSampleRate = 1.f;
223+
};
232224
}];
233225

234226
return YES;
235227
}
236228
```
237229

238-
```swift {tabTitle:SwiftUI with App conformer} {"onboardingOptions": {"performance": "13-16"}}
230+
```swift {tabTitle:SwiftUI with App conformer} {"onboardingOptions": {"performance": "13-16", "profiling": "17-21"}}
239231
import Sentry
240232

241233
@main
@@ -249,9 +241,14 @@ struct SwiftUIApp: App {
249241
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
250242
options.sendDefaultPii = true
251243

252-
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
244+
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
253245
// We recommend adjusting this value in production.
254-
options.tracesSampleRate = 1.0
246+
options.tracesSampleRate = 1
247+
248+
options.configureProfiling = {
249+
$0.lifecycle = .trace
250+
$0.sessionSampleRate = 1
251+
}
255252
}
256253
}
257254
}

docs/platforms/apple/common/profiling/index.mdx

Lines changed: 100 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ notSupported:
1515
<PlatformContent includePath="profiling/index/preface" />
1616
<PlatformContent includePath="profiling/index/why-profiling" />
1717

18-
## Enable Tracing
18+
## Enable Profiling
19+
20+
<Alert>
1921

20-
Profiling depends on Sentry’s Tracing product being enabled beforehand. To enable tracing in the SDK:
22+
Profiling V2 was introduced in SDK version 8.49.0. All prior profiling API are deprecated and will be removed in a future major version of the SDK.
23+
24+
</Alert>
2125

26+
To configure profiling, assign a closure to `SentryOptions.configureProfiling`, setting the desired options on the object passed in as parameter:
2227

2328
```swift {tabTitle:Swift}
2429
import Sentry
2530

2631
SentrySDK.start { options in
2732
options.dsn = "___PUBLIC_DSN___"
28-
options.tracesSampleRate = 1.0
33+
options.configureProfiling = {
34+
$0.sessionSampleRate = 1
35+
}
2936
}
3037
```
3138

@@ -34,22 +41,81 @@ SentrySDK.start { options in
3441

3542
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
3643
options.dsn = @"___PUBLIC_DSN___";
37-
options.tracesSampleRate = @1.0;
44+
options.configureProfiling = ^(SentryProfileOptions *profiling) {
45+
profiling.sessionSampleRate = 1.f;
46+
};
3847
}];
3948
```
4049
41-
Check out the <PlatformLink to="/tracing/">tracing setup documentation</PlatformLink> for more detailed information on how to configure sampling. Setting the sample rate to 1.0 means all transactions will be captured.
50+
By default, `sessionSampleRate` is `0`, so you'll need to set it to a higher value to receive profile data. `sessionSampleRate` is evaluated once per user session and applies to any attempt to start a profile until the next user session starts. See <PlatformLink to="/configuration/releases/#sessions">user session documentation</PlatformLink> for more information on user sessions.
4251
43-
By default, some transactions will be created automatically for common operations like loading a view controller/activity and app startup.
52+
See the subsections below to learn about the various ways the profiler can be started and stopped.
4453
45-
## Enable Profiling
54+
### Manual Lifecycle
55+
56+
By default, the profiler can only be started and stopped manually with calls to `SentrySDK.startProfiler` and `SentrySDK.stopProfiler`. All code that executes on all threads in between those calls will be recorded. The configurations shown above demonstrate configuring manual profiling mode.
57+
58+
### Trace Lifecycle
59+
60+
The profiler can be configured to start when a new root span is started where none already exist, and stopped when there are no root spans remaining. For this mode, you must set the `SentryProfileOptions.lifecycle` property to `SentryProfileLifecycleTrace` and ensure some traces will be sampled:
61+
62+
```swift {tabTitle:Swift}
63+
import Sentry
64+
65+
SentrySDK.start { options in
66+
options.dsn = "___PUBLIC_DSN___"
67+
options.tracesSampleRate = 1
68+
options.configureProfiling = {
69+
$0.sessionSampleRate = 1
70+
$0.lifecycle = .trace
71+
}
72+
}
73+
```
74+
75+
```objc {tabTitle:Objective-C}
76+
@import Sentry;
77+
78+
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
79+
options.dsn = @"___PUBLIC_DSN___";
80+
options.tracesSampleRate = @1.f;
81+
options.configureProfiling = ^(SentryProfileOptions *profiling) {
82+
profiling.sessionSampleRate = 1.f;
83+
profiling.lifecycle = SentryProfileLifecycleTrace;
84+
};
85+
}];
86+
```
87+
88+
<Alert>
89+
90+
The `sessionSampleRate` for profiles is undersampled with respect to the `tracesSampleRate`.
91+
92+
</Alert>
93+
94+
Check out the <PlatformLink to="/tracing/">tracing setup documentation</PlatformLink> for more detailed information on how to configure sampling for Sentry Tracing.
95+
96+
### App Starts
97+
98+
If configured with manual lifecycle, then a profile starts on the next app launch, and continues until you call `SentrySDK.stopProfiler`.
99+
100+
If configured with trace lifecycle, then app start profiles are attached to a special performance transaction operation called `app.launch` and displayed in the product simply as `launch`, which is stopped either when `SentrySDK.startWithOptions` is called, or, if <PlatformLink to="/tracing/instrumentation/automatic-instrumentation/#time-to-initial-display">TTID</PlatformLink>/<PlatformLink to="/tracing/instrumentation/automatic-instrumentation/#time-to-full-display">TTFD</PlatformLink> tracking is enabled, when the SDK determines that TTID/TTFD has been reached.
101+
102+
Every time `SentrySDK.startWithOptions` is called with app start profiling configured, a separate sample decision is generated with `sessionSampleRate` and stored until the next app launch (as well as `tracesSampleRate` if trace profile lifecycle is configured). The same sample decision will apply for the remainder of the profile session following that subsequent launch.
103+
104+
## Transaction Profiling (deprecated)
46105
47106
<Alert>
48107
49-
iOS profiling is available starting in SDK version `8.12.0`.
108+
Profiling configuration as explained below was originally introduced in SDK version `8.12.0` and is deprecated in favor of profiling V2 introduced in 8.49.0, explained at the beginning of this section.
50109
51110
</Alert>
52111
112+
<Alert>
113+
114+
Profiling depends on Sentry’s Tracing product being enabled beforehand. Check out the <PlatformLink to="/tracing/">tracing setup documentation</PlatformLink> for more detailed information on how to configure sampling.
115+
116+
</Alert>
117+
118+
Configure the sampling rates for traces and profiles to ensure they are nonzero so that some are recorded. The <PlatformIdentifier name="profiles-sample-rate" /> setting is _relative_ to the <PlatformIdentifier name="traces-sample-rate" /> setting.
53119
54120
```swift {tabTitle:Swift}
55121
import Sentry
@@ -58,7 +124,6 @@ SentrySDK.start { options in
58124
options.dsn = "___PUBLIC_DSN___"
59125
options.tracesSampleRate = 1.0 // tracing must be enabled for profiling
60126
options.profilesSampleRate = 1.0 // see also `profilesSampler` if you need custom sampling logic
61-
options.enableAppLaunchProfiling = true // experimental new feature to start profiling in the pre-main launch phase
62127
}
63128
```
64129

@@ -69,26 +134,17 @@ SentrySDK.start { options in
69134
options.dsn = @"___PUBLIC_DSN___";
70135
options.tracesSampleRate = @1.0; // tracing must be enabled for profiling
71136
options.profilesSampleRate = @1.0; // see also `profilesSampler` if you need custom sampling logic
72-
options.enableAppLaunchProfiling = YES; // experimental new feature to start profiling in the pre-main launch phase
73137
}];
74138
```
75139
76-
<Alert>
77-
78-
The <PlatformIdentifier name="profiles-sample-rate" /> setting is _relative_ to the <PlatformIdentifier name="traces-sample-rate" /> setting.
79-
80-
</Alert>
81-
82-
## Enable Launch Profiling
140+
## Launch Profiling (deprecated)
83141
84142
<Alert>
85143
86-
This feature is experimental and may have bugs.
144+
Launch profiling configuration as explained below was originally introduced in SDK version 8.21.0 and is deprecated in favor of profiling V2 configuration released in 8.49.0, explained at the beginning of this section.
87145
88146
</Alert>
89147
90-
_(New in version 8.21.0)_
91-
92148
Normally, a profile can only be taken during a trace span after the SDK has been initialized. Now, you can configure the SDK to automatically profile certain app launches.
93149
94150
To set up launch profiling, use the `enableAppLaunchProfiling` option and configure the sample rates for traces and profiles with `SentrySDK.startWithOptions` to determine if the subsequent app launch should be automatically profiled. This allows you to gather information on what is going on in your app even before `main` is called, making it easier to diagnose issues with slow app launches.
@@ -97,16 +153,36 @@ If you use `SentryOptions.tracesSampler` or `SentryOptions.profilesSampler`, it
97153
98154
Currently, launch profiles are attached to a special performance transaction operation called `app.launch` and displayed in the product simply as `launch`.
99155
100-
## Continuous Profiling
156+
```swift {tabTitle:Swift}
157+
import Sentry
158+
159+
SentrySDK.start { options in
160+
options.dsn = "___PUBLIC_DSN___"
161+
options.tracesSampleRate = 1.0 // tracing must be enabled for profiling
162+
options.profilesSampleRate = 1.0 // see also `profilesSampler` if you need custom sampling logic
163+
options.enableAppLaunchProfiling = true
164+
}
165+
```
166+
167+
```objc {tabTitle:Objective-C}
168+
@import Sentry;
169+
170+
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
171+
options.dsn = @"___PUBLIC_DSN___";
172+
options.tracesSampleRate = @1.0; // tracing must be enabled for profiling
173+
options.profilesSampleRate = @1.0; // see also `profilesSampler` if you need custom sampling logic
174+
options.enableAppLaunchProfiling = YES;
175+
}];
176+
```
177+
178+
## Continuous Profiling (deprecated)
101179
102180
<Alert>
103181
104-
This feature is experimental and may have bugs.
182+
Continuous profiling as explained below was originally introduced in SDK version 8.36.0 and is deprecated in favor of profiling V2 configuration released in 8.49.0, explained at the beginning of this section.
105183
106184
</Alert>
107185
108-
_(New in version 8.36.0)_
109-
110186
The current profiling implementation stops the profiler automatically after 30 seconds (unless you manually stop it earlier). Naturally, this limitation makes it difficult to get full coverage of your app's execution. We now offer an experimental continuous mode, where profiling data is periodically uploaded while running, with no limit to how long the profiler may run.
111187
112188
Previously, profiles only ran in tandem with performance transactions that were started either automatically or manually with `SentrySDK.startTransaction`. Now, you can start and stop the profiler directly with `SentrySDK.startProfiler` and `SentrySDK.stopProfiler`. You can also start a profile at app launch by setting `SentryOptions.enableAppLaunchProfiling = true` in your call to `SentrySDK.startWithOptions`.

docs/platforms/apple/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ keywords:
1212
- swift
1313
---
1414

15-
Sentry supports the Apple platform via the `sentry-cocoa` SDK. Select your platform to get started:
15+
Sentry supports Apple platforms via the [`sentry-cocoa`](https://github.com/getsentry/sentry-cocoa) SDK. Select your platform to get started:
1616

1717
<GuideGrid platform="apple" />

0 commit comments

Comments
 (0)