Skip to content

Commit 5b9a0da

Browse files
authored
Tag all spans during app start with start type info (#3190)
1 parent 36820e8 commit 5b9a0da

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Bumped `dio` min verion to `5.2.0`
1919
- Log a warning when dropping envelope items ([#3165](https://github.com/getsentry/sentry-dart/pull/3165))
2020
- Call options.log for structured logs ([#3187](https://github.com/getsentry/sentry-dart/pull/3187))
21+
- Tag all spans during app start with start type info ([#3190](https://github.com/getsentry/sentry-dart/pull/3190))
2122

2223
### Dependencies
2324

packages/flutter/lib/src/integrations/native_app_start_handler.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class NativeAppStartHandler {
5656
} else {
5757
return;
5858
}
59+
sentryTracer.setData("app_start_type", appStartInfo.type.name);
5960

6061
// We need to add the measurements before we add the child spans
6162
// If the child span finish the transaction will finish and then we cannot add measurements
@@ -143,6 +144,7 @@ class NativeAppStartHandler {
143144
traceId: transactionTraceId,
144145
startTimestamp: appStartInfo.start,
145146
endTimestamp: appStartEnd,
147+
appStartType: appStartInfo.type.name,
146148
);
147149

148150
await _attachNativeSpans(appStartInfo, transaction, appStartSpan);
@@ -155,6 +157,7 @@ class NativeAppStartHandler {
155157
traceId: transactionTraceId,
156158
startTimestamp: appStartInfo.start,
157159
endTimestamp: appStartInfo.pluginRegistration,
160+
appStartType: appStartInfo.type.name,
158161
);
159162

160163
final sentrySetupSpan = await _createAndFinishSpan(
@@ -165,6 +168,7 @@ class NativeAppStartHandler {
165168
traceId: transactionTraceId,
166169
startTimestamp: appStartInfo.pluginRegistration,
167170
endTimestamp: appStartInfo.sentrySetupStart,
171+
appStartType: appStartInfo.type.name,
168172
);
169173

170174
final firstFrameRenderSpan = await _createAndFinishSpan(
@@ -175,6 +179,7 @@ class NativeAppStartHandler {
175179
traceId: transactionTraceId,
176180
startTimestamp: appStartInfo.sentrySetupStart,
177181
endTimestamp: appStartEnd,
182+
appStartType: appStartInfo.type.name,
178183
);
179184

180185
transaction.children.addAll([
@@ -201,6 +206,7 @@ class NativeAppStartHandler {
201206
traceId: transaction.context.traceId,
202207
startTimestamp: timeSpan.start,
203208
endTimestamp: timeSpan.end,
209+
appStartType: appStartInfo.type.name,
204210
);
205211
span.data.putIfAbsent('native', () => true);
206212
transaction.children.add(span);
@@ -219,6 +225,7 @@ class NativeAppStartHandler {
219225
required SentryId traceId,
220226
required DateTime startTimestamp,
221227
required DateTime endTimestamp,
228+
required String appStartType,
222229
}) async {
223230
final span = SentrySpan(
224231
tracer,
@@ -231,6 +238,7 @@ class NativeAppStartHandler {
231238
_hub,
232239
startTimestamp: startTimestamp,
233240
);
241+
span.setData("app_start_type", appStartType);
234242
await span.finish(endTimestamp: endTimestamp);
235243
return span;
236244
}

packages/flutter/test/integrations/native_app_start_handler_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ void main() {
240240
expect(fixture.scope.span, isA<SentryTracer>());
241241
});
242242

243+
test('added transaction has app_start_type data', () async {
244+
await fixture.call(
245+
appStartEnd: DateTime.fromMillisecondsSinceEpoch(10),
246+
);
247+
expect(fixture._enrichedTransaction?.data["app_start_type"], 'cold');
248+
});
249+
243250
test('added transaction is not bound to scope if already set', () async {
244251
final alreadySet = MockSentryTracer();
245252
fixture.scope.span = alreadySet;
@@ -404,6 +411,14 @@ void main() {
404411
expect(firstFrameRenderSpan, isNotNull);
405412
});
406413

414+
test('have app_start_type data set', () async {
415+
// Verify that app start spans have the app_start_type data set
416+
expect(coldStartSpan?.data["app_start_type"], "cold");
417+
expect(pluginRegistrationSpan?.data["app_start_type"], "cold");
418+
expect(sentrySetupSpan?.data["app_start_type"], "cold");
419+
expect(firstFrameRenderSpan?.data["app_start_type"], "cold");
420+
});
421+
407422
test('have correct op', () async {
408423
const op = 'app.start.cold';
409424
expect(coldStartSpan?.context.operation, op);

0 commit comments

Comments
 (0)