Skip to content

Commit bc18c11

Browse files
philipphofmannimatwawanaromtsn
authored
feat(apple): User interaction instrumentation (#5098)
Add docs similar to user interaction instrumentation on Android. As the implementations don't match exactly we can't create reusable docs. Co-authored-by: Isabel <[email protected]> Co-authored-by: Roman Zavarnitsyn <[email protected]>
1 parent 7f6560a commit bc18c11

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/platforms/apple/common/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,67 @@ SentrySDK.start { options in
164164
}];
165165
```
166166
167+
## User Interaction Instrumentation
168+
169+
<Alert level="info" title="Important">
170+
171+
This is an experimental feature and requires an opt-in. Experimental features are still a work-in-progress and may have bugs. We recognize the irony.
172+
173+
</Alert>
174+
175+
The UI instrumentation, once enabled, captures transactions for clicks. The UI instrumentation is disabled by default, but you can enable it by setting:
176+
177+
```swift {tabTitle:Swift}
178+
import Sentry
179+
180+
SentrySDK.start { options in
181+
options.dsn = "___PUBLIC_DSN___"
182+
options.enableUserInteractionTracing = true
183+
}
184+
```
185+
```objc {tabTitle:Objective-C}
186+
@import Sentry;
187+
188+
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
189+
options.dsn = @"___PUBLIC_DSN___";
190+
options.enableUserInteractionTracing = YES;
191+
}];
192+
```
193+
194+
The SDK composes the transaction name out of the host `UIViewController` and the method that the `UIView` is calling; for example, `YourApp_LoginUIViewController.loginButton`. The transaction operation is set to `ui.action` plus the interaction type `click`. The transaction finishes automatically after it reaches the specified [idleTimeout](/platforms/android/configuration/options/#idle-timeout) and all of its child spans are finished. The `idleTimeoout` defaults to `3000` milliseconds (three seconds).
195+
196+
<Note>
197+
198+
If the UI transaction has idled, but didn't have any child spans added, it will be dropped.
199+
200+
</Note>
201+
202+
The SDK binds user interaction transactions to the `Scope` automatically if there's no other transaction set. Because of that, you can create spans using manual instrumentation, and those spans will be automatically associated with the running UI transaction.
203+
204+
```Swift
205+
import Sentry
206+
207+
func loadUserDataOnClick() {
208+
let span = SentrySDK.span
209+
let innerSpan = span?.startChild(operation: "loadUserData")
210+
// omitted code
211+
innerSpan?.finish()
212+
}
213+
```
214+
215+
```objc {tabTitle:Objective-C}
216+
@import Sentry;
217+
218+
- (void)loadUserDataOnClick {
219+
id<SentrySpan> span = SentrySDK.span;
220+
id<SentrySpan> innerSpan = [span startChildWithOperation:@"loadUserData"];
221+
// omitted code
222+
[innerSpan finish];
223+
}
224+
```
225+
226+
When the user interaction transaction is not finished yet, but the user makes a new interaction, or the SDK starts a new UIViewController transaction, the SDK automatically finishes the previous user interaction transaction. This is because only one transaction can be bound to the scope at a time. However, if the same view has been interacted with (for example, a `UIButton` was clicked again within the `idleTimeout` window), the idle timer will be reset and the transaction duration will be extended with the `idleTimeout` value.
227+
167228
## Opt Out
168229

169230
You can opt out of UIViewController, App Start, Slow and Frozen Frames, and HTTP Instrumentation using options:

0 commit comments

Comments
 (0)