Skip to content

Commit d87888e

Browse files
buenaflorkahest
andauthored
flutter: improve app start and frames tracking docs (#11891)
* update * update * update frames tracking docs * update wording * Apply suggestions from code review Co-authored-by: Karl Heinz Struggl <[email protected]> * remove usages of 'we' --------- Co-authored-by: Karl Heinz Struggl <[email protected]>
1 parent 63142cc commit d87888e

File tree

2 files changed

+55
-52
lines changed

2 files changed

+55
-52
lines changed

docs/platforms/flutter/integrations/app-start-instrumentation.mdx

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@ categories:
1010

1111
Sentry's app start instrumentation provides insight into how long your application takes to launch.
1212

13+
<Note>
14+
15+
App start instrumentation is available on **iOS** and **Android**.
16+
17+
</Note>
18+
1319
## Instrumentation Behaviour
1420

1521
Before diving into the configuration, it's important to understand how app start instrumentation behaves:
1622

17-
- The SDK attaches the app start metrics to the **first run transaction**.
18-
- It tracks the length of time from the **earliest native process initialization** until the very first [PostFrameCallback](https://api.flutter.dev/flutter/scheduler/SchedulerBinding/addPostFrameCallback.html) is triggered.
19-
- The SDK differentiates between a cold and a warm start, but doesn't track hot starts/resumes.
23+
App start instrumentation tracks the duration between the earliest native process initialization and the first frame rendered (as reported by [addTimingsCallback](https://api.flutter.dev/flutter/scheduler/SchedulerBinding/addTimingsCallback.html)). Once the app start is processed, the callback is removed to avoid additional overhead.
24+
25+
When the SDK receives the start and end times of the app launch, the SDK:
26+
- Creates a transaction named `ui.load`
27+
- Attaches a span with either `app.start.cold` or `app.start.warm` operation
28+
- Adds app start metrics to the transaction
29+
30+
<Note>
31+
32+
While the SDK differentiates between cold and warm starts, it doesn't track hot starts/resumes.
33+
34+
</Note>
2035

2136
## Prerequisites
2237

@@ -27,49 +42,18 @@ Before starting, ensure:
2742

2843
## Configure
2944

30-
This type of instrumentation is automatically enabled. There is no need for further configuration.
45+
This instrumentation is automatically enabled. There is no need for further configuration.
3146

3247
## Verify
3348

34-
### 1. Execute the Transaction:
35-
36-
Initiate a transaction immediately after the app launches.
49+
### 1. Launch Your App:
3750

38-
```dart
39-
import 'package:sentry/sentry.dart';
40-
41-
final transaction = Sentry.startTransaction("test test", "my operation");
42-
await Future.delayed(const Duration(milliseconds: 1000));
43-
transaction.finish();
44-
```
51+
Launch your Sentry configured app.
4552

4653
### 2. Locate Your Transaction:
4754

48-
Open the [sentry.io](https://sentry.io/) performance dashboard, find, and select the transaction you executed.
55+
Open the [sentry.io performance page](https://sentry.io/performance), find, and select the 'root /' transaction and navigate to the trace view of a sampled event.
4956

5057
### 3. View App Start Metrics:
5158

52-
Select the event within your transaction. Sentry.io displays the app start metrics on the right side of the screen.
53-
54-
## Additional Configuration
55-
56-
### Change App Start Tracking End
57-
58-
1. Set `autoAppStart` to `false` in the Sentry options.
59-
2. Call `SentryFlutter.setAppStartEnd`.
60-
61-
```dart
62-
import 'package:sentry_flutter/sentry_flutter.dart';
63-
64-
// Run my App and do my things first
65-
66-
// Initialize the Flutter SDK
67-
Future<void> main() async {
68-
await SentryFlutter.init(
69-
(options) => options.autoAppStart = false,
70-
);
71-
}
72-
73-
// End the App Start metric
74-
SentryFlutter.setAppStartEnd(DateTime.now().toUtc());
75-
```
59+
Select the event within your transaction. Sentry displays the app start metrics on the right side of the screen in the **Mobile Vitals** section.

docs/platforms/flutter/integrations/slow-and-frozen-frames-instrumentation.mdx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ Unresponsive UI and animation hitches annoy users and degrade the user experienc
1212
This integration can help. Set it up and identify these problems in your app by tracking and showing **slow frames**, **frozen frames**, and **frame delay** metrics for spans.
1313
Learn more about frame delay [here](https://develop.sentry.dev/sdk/performance/frames-delay/).
1414

15+
<Note>
16+
17+
Frames tracking instrumentation is available on **iOS**, **macOS** and **Android**.
18+
19+
</Note>
20+
1521
## Instrumentation Behaviour
1622

17-
Frame metrics are manually calculated using the [addPersistentFrameCallback](https://api.flutter.dev/flutter/scheduler/SchedulerBinding/addPersistentFrameCallback.html) API from the Flutter SDK.
18-
Frame duration tracking in Sentry's Flutter SDK begins automatically when a span starts. It continuously measures each frame's render time until the span finishes, then calculates and attaches frame metrics to the completed span.
23+
The frames tracking instrumentation measures frame metrics (slow frames, frozen frames, and frame delay) for each span. To calculate these metrics, the SDK uses a custom `WidgetsFlutterBinding` that measures the duration between [handleBeginFrame](https://api.flutter.dev/flutter/scheduler/SchedulerBinding/handleBeginFrame.html) and [handleDrawFrame](https://api.flutter.dev/flutter/scheduler/SchedulerBinding/handleDrawFrame.html) to determine each frame's render time.
24+
25+
Frame duration tracking begins automatically when a span starts. The integration continuously measures frame durations until the span finishes, then calculates and attaches the frame metrics to the completed span.
1926

2027
## Prerequisite
2128

@@ -26,22 +33,34 @@ Before starting, ensure:
2633

2734
## Configure
2835

29-
This type of instrumentation is automatically enabled. There is no need for further configuration.
36+
This instrumentation is automatically enabled through two integrations:
37+
- The `WidgetsFlutterBindingIntegration` which provides the custom binding for frame tracking
38+
- The `FramesTrackingIntegration` which processes and attaches the frame metrics to spans
39+
40+
In most cases, no additional configuration is required.
41+
42+
### Early Widgets Binding Initialization
43+
44+
If you need to initialize the widgets binding earlier than `SentryFlutter.init()`, you must call `SentryWidgetsFlutterBinding.ensureInitialized()` manually. Note that using a different custom binding will prevent this instrumentation from working properly.
45+
46+
Example:
47+
```dart {2}
48+
void main() {
49+
SentryWidgetsFlutterBinding.ensureInitialized();
50+
// ... rest of your initialization code
51+
}
52+
```
3053

3154
## Additional Configuration
3255

3356
### Disabling the Instrumentation
3457

3558
Set `enableFramesTracking` to `false` in the options to disable the instrumentation.
3659

37-
```dart
38-
import 'package:flutter/widgets.dart';
39-
import 'package:sentry_flutter/sentry_flutter.dart';
40-
41-
Future<void> main() async {
42-
await SentryFlutter.init(
43-
(options) => options.enableFramesTracking = false,
44-
appRunner: () => runApp(MyApp()),
45-
);
46-
}
60+
```dart {3}
61+
await SentryFlutter.init(
62+
(options) {
63+
options.enableFramesTracking = false
64+
},
65+
);
4766
```

0 commit comments

Comments
 (0)