Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonatanm09 committed Sep 25, 2024
1 parent 2f61482 commit efea448
Show file tree
Hide file tree
Showing 75 changed files with 1,298 additions and 1,370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SentryFlutter(
}
data.getIfNotNull<String>("diagnosticLevel") {
if (options.isDebug) {
val sentryLevel = SentryLevel.valueOf(it.uppercase(Locale.ROOT))
val sentryLevel = SentryLevel.valueOf(it.toUpperCase(Locale.ROOT))
options.setDiagnosticLevel(sentryLevel)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import io.sentry.protocol.User
import io.sentry.transport.CurrentDateProvider
import java.io.File
import java.lang.ref.WeakReference
import kotlin.time.DurationUnit
import kotlin.time.toDuration

class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private lateinit var channel: MethodChannel
Expand Down Expand Up @@ -173,16 +171,6 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

val appStartMetrics = AppStartMetrics.getInstance()

if (!appStartMetrics.isAppLaunchedInForeground ||
appStartMetrics.appStartTimeSpan.durationMs > 1.toDuration(DurationUnit.MINUTES).inWholeMilliseconds
) {
Log.w(
"Sentry",
"Invalid app start data: app not launched in foreground or app start took too long (>60s)",
)
result.success(null)
}

val appStartTimeSpan = appStartMetrics.appStartTimeSpan
val appStartTime = appStartTimeSpan.startTimestamp
val isColdStart = appStartMetrics.appStartType == AppStartMetrics.AppStartType.COLD
Expand Down
3 changes: 3 additions & 0 deletions flutter/example/integration_test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/integrations/native_app_start_integration.dart';
import 'package:sentry_flutter_example/main.dart';

void main() {
Expand All @@ -25,6 +26,8 @@ void main() {
// Using fake DSN for testing purposes.
Future<void> setupSentryAndApp(WidgetTester tester,
{String? dsn, BeforeSendCallback? beforeSendCallback}) async {
NativeAppStartIntegration.isIntegrationTest = true;

await setupSentry(
() async {
await tester.pumpWidget(SentryScreenshotWidget(
Expand Down
2 changes: 1 addition & 1 deletion flutter/example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import Flutter
import Sentry

@main
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
private let _channel = "example.flutter.sentry.io"

Expand Down
2 changes: 1 addition & 1 deletion flutter/example/lib/user_feedback_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class _SentryLogo extends StatelessWidget {
var color = Colors.white;
final brightenss = Theme.of(context).brightness;
if (brightenss == Brightness.light) {
color = const Color(0xff362d59);
color = const Color(0xff362d59).withOpacity(1.0);
}

return FittedBox(
Expand Down
3 changes: 0 additions & 3 deletions flutter/lib/src/binding_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class BindingWrapper {
stackTrace: s,
logger: 'BindingWrapper',
);
if (_hub.options.automatedTestMode) {
rethrow;
}
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class AndroidPlatformExceptionEventProcessor implements EventProcessor {
exception: e,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
return event;
}
}
Expand Down
152 changes: 152 additions & 0 deletions flutter/lib/src/event_processor/native_app_start_event_processor.dart
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ScreenshotEventProcessor implements EventProcessor {
exception: exception,
stackTrace: stackTrace,
);
// ignore: invalid_use_of_internal_member
if (_options.automatedTestMode) {
rethrow;
}
Expand Down Expand Up @@ -137,9 +138,6 @@ class ScreenshotEventProcessor implements EventProcessor {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
return null;
}
Expand Down
7 changes: 2 additions & 5 deletions flutter/lib/src/file_system_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import 'dart:typed_data';

import 'package:flutter/services.dart';
import 'package:sentry/sentry.dart';

import '../sentry_flutter.dart';
import 'native/sentry_native_binding.dart';

class FileSystemTransport implements Transport {
FileSystemTransport(this._native, this._options);

final SentryNativeBinding _native;
final SentryFlutterOptions _options;
final SentryOptions _options;

@override
Future<SentryId?> send(SentryEnvelope envelope) async {
Expand All @@ -28,9 +28,6 @@ class FileSystemTransport implements Transport {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
return SentryId.empty();
}

Expand Down
3 changes: 0 additions & 3 deletions flutter/lib/src/integrations/load_contexts_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ class _LoadContextsIntegrationEventProcessor implements EventProcessor {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
return event;
}
Expand Down
3 changes: 0 additions & 3 deletions flutter/lib/src/integrations/load_release_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class LoadReleaseIntegration extends Integration<SentryFlutterOptions> {
exception: exception,
stackTrace: stackTrace,
);
if (options.automatedTestMode) {
rethrow;
}
}

options.sdk.addIntegration('loadReleaseIntegration');
Expand Down
Loading

0 comments on commit efea448

Please sign in to comment.