forked from getsentry/sentry-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f61482
commit efea448
Showing
75 changed files
with
1,298 additions
and
1,370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
flutter/lib/src/event_processor/native_app_start_event_processor.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// ignore_for_file: invalid_use_of_internal_member | ||
|
||
import 'dart:async'; | ||
|
||
import '../../sentry_flutter.dart'; | ||
import '../integrations/integrations.dart'; | ||
|
||
// ignore: implementation_imports | ||
import 'package:sentry/src/sentry_tracer.dart'; | ||
|
||
/// EventProcessor that enriches [SentryTransaction] objects with app start | ||
/// measurement. | ||
class NativeAppStartEventProcessor implements EventProcessor { | ||
final Hub _hub; | ||
|
||
NativeAppStartEventProcessor({Hub? hub}) : _hub = hub ?? HubAdapter(); | ||
|
||
@override | ||
Future<SentryEvent?> apply(SentryEvent event, Hint hint) async { | ||
final options = _hub.options; | ||
if (NativeAppStartIntegration.didAddAppStartMeasurement || | ||
event is! SentryTransaction || | ||
options is! SentryFlutterOptions) { | ||
return event; | ||
} | ||
|
||
AppStartInfo? appStartInfo; | ||
if (!options.autoAppStart) { | ||
final appStartEnd = NativeAppStartIntegration.appStartEnd; | ||
if (appStartEnd != null) { | ||
appStartInfo = await NativeAppStartIntegration.getAppStartInfo(); | ||
appStartInfo?.end = appStartEnd; | ||
} else { | ||
// If autoAppStart is disabled and appStartEnd is not set, we can't add app starts | ||
return event; | ||
} | ||
} else { | ||
appStartInfo = await NativeAppStartIntegration.getAppStartInfo(); | ||
} | ||
|
||
final measurement = appStartInfo?.toMeasurement(); | ||
if (measurement != null) { | ||
event.measurements[measurement.name] = measurement; | ||
NativeAppStartIntegration.didAddAppStartMeasurement = true; | ||
} | ||
|
||
if (appStartInfo != null) { | ||
await _attachAppStartSpans(appStartInfo, event.tracer); | ||
} | ||
|
||
return event; | ||
} | ||
|
||
Future<void> _attachAppStartSpans( | ||
AppStartInfo appStartInfo, SentryTracer transaction) async { | ||
final transactionTraceId = transaction.context.traceId; | ||
final appStartEnd = appStartInfo.end; | ||
if (appStartEnd == null) { | ||
return; | ||
} | ||
|
||
final appStartSpan = await _createAndFinishSpan( | ||
tracer: transaction, | ||
operation: appStartInfo.appStartTypeOperation, | ||
description: appStartInfo.appStartTypeDescription, | ||
parentSpanId: transaction.context.spanId, | ||
traceId: transactionTraceId, | ||
startTimestamp: appStartInfo.start, | ||
endTimestamp: appStartEnd); | ||
|
||
await _attachNativeSpans(appStartInfo, transaction, appStartSpan); | ||
|
||
final pluginRegistrationSpan = await _createAndFinishSpan( | ||
tracer: transaction, | ||
operation: appStartInfo.appStartTypeOperation, | ||
description: appStartInfo.pluginRegistrationDescription, | ||
parentSpanId: appStartSpan.context.spanId, | ||
traceId: transactionTraceId, | ||
startTimestamp: appStartInfo.start, | ||
endTimestamp: appStartInfo.pluginRegistration); | ||
|
||
final sentrySetupSpan = await _createAndFinishSpan( | ||
tracer: transaction, | ||
operation: appStartInfo.appStartTypeOperation, | ||
description: appStartInfo.sentrySetupDescription, | ||
parentSpanId: appStartSpan.context.spanId, | ||
traceId: transactionTraceId, | ||
startTimestamp: appStartInfo.pluginRegistration, | ||
endTimestamp: appStartInfo.sentrySetupStart); | ||
|
||
final firstFrameRenderSpan = await _createAndFinishSpan( | ||
tracer: transaction, | ||
operation: appStartInfo.appStartTypeOperation, | ||
description: appStartInfo.firstFrameRenderDescription, | ||
parentSpanId: appStartSpan.context.spanId, | ||
traceId: transactionTraceId, | ||
startTimestamp: appStartInfo.sentrySetupStart, | ||
endTimestamp: appStartEnd); | ||
|
||
transaction.children.addAll([ | ||
appStartSpan, | ||
pluginRegistrationSpan, | ||
sentrySetupSpan, | ||
firstFrameRenderSpan | ||
]); | ||
} | ||
|
||
Future<void> _attachNativeSpans(AppStartInfo appStartInfo, | ||
SentryTracer transaction, SentrySpan parent) async { | ||
await Future.forEach<TimeSpan>(appStartInfo.nativeSpanTimes, | ||
(timeSpan) async { | ||
try { | ||
final span = await _createAndFinishSpan( | ||
tracer: transaction, | ||
operation: appStartInfo.appStartTypeOperation, | ||
description: timeSpan.description, | ||
parentSpanId: parent.context.spanId, | ||
traceId: transaction.context.traceId, | ||
startTimestamp: timeSpan.start, | ||
endTimestamp: timeSpan.end); | ||
span.data.putIfAbsent('native', () => true); | ||
transaction.children.add(span); | ||
} catch (e) { | ||
_hub.options.logger(SentryLevel.warning, | ||
'Failed to attach native span to app start transaction: $e'); | ||
} | ||
}); | ||
} | ||
|
||
Future<SentrySpan> _createAndFinishSpan({ | ||
required SentryTracer tracer, | ||
required String operation, | ||
required String description, | ||
required SpanId parentSpanId, | ||
required SentryId traceId, | ||
required DateTime startTimestamp, | ||
required DateTime endTimestamp, | ||
}) async { | ||
final span = SentrySpan( | ||
tracer, | ||
SentrySpanContext( | ||
operation: operation, | ||
description: description, | ||
parentSpanId: parentSpanId, | ||
traceId: traceId, | ||
), | ||
_hub, | ||
startTimestamp: startTimestamp); | ||
await span.finish(endTimestamp: endTimestamp); | ||
return span; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.