Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6fcd45f
draft
marandaneto Nov 3, 2020
4077a7b
fix conflict
marandaneto Nov 3, 2020
9fd04ba
set staging if not release mode
marandaneto Nov 3, 2020
d748ec4
clean up
marandaneto Nov 3, 2020
84d9559
Update flutter/lib/sentry_flutter.dart
marandaneto Nov 3, 2020
103bded
remove comment
marandaneto Nov 3, 2020
0a999f3
set flutter sdk on options
marandaneto Nov 4, 2020
b6e4967
Merge branch 'main' into feat/flutter-native
marandaneto Nov 4, 2020
319f89d
Merge branch 'feat/flutter-native' of github.com:getsentry/sentry-dar…
marandaneto Nov 4, 2020
d26c716
draft
marandaneto Nov 4, 2020
9b250b3
remove
marandaneto Nov 4, 2020
59f7ea7
fix
marandaneto Nov 4, 2020
9133a3e
init native sdk draft
marandaneto Nov 5, 2020
c96db31
write envelope
marandaneto Nov 5, 2020
1a2c2f3
stack trace fixes
marandaneto Nov 5, 2020
6242992
fixes
marandaneto Nov 6, 2020
eaad8ef
upgrade versions
marandaneto Nov 6, 2020
93517d4
fix
marandaneto Nov 6, 2020
e5aab67
bump android
marandaneto Nov 6, 2020
6d7821d
fix git conflict
marandaneto Nov 10, 2020
f8bd11d
fix tests
marandaneto Nov 10, 2020
3d7055a
fixes
marandaneto Nov 10, 2020
25edde3
fix
marandaneto Nov 10, 2020
81ddf3e
clean up
marandaneto Nov 10, 2020
a16e4a1
ref
marandaneto Nov 10, 2020
d879c50
debug
marandaneto Nov 11, 2020
a860ee3
fix
marandaneto Nov 11, 2020
7562bf4
Merge remote-tracking branch 'origin/main' into feat/flutter-native
rxlabz Nov 12, 2020
1bd8324
post conflict dartformt
rxlabz Nov 12, 2020
27b8ee9
fix import
rxlabz Nov 12, 2020
e48f974
fix: android native integration (#163)
marandaneto Nov 17, 2020
158c963
Fix: Handled mechanism is true and fix samples (#165)
marandaneto Nov 18, 2020
4486897
Fix: Flutter Web does not require a native integration (#166)
marandaneto Nov 18, 2020
0d13722
Tests: unit tests for the native integrations (#167)
marandaneto Nov 19, 2020
8c073bf
Ref: remove lock files (#168)
marandaneto Nov 20, 2020
bcfcc07
Fix: set Dart and Flutter min version (#170)
marandaneto Nov 20, 2020
457435b
Fix: read system variables for mobile too (#169)
marandaneto Nov 20, 2020
b75d9d4
Fix: README on Dart and Flutter SDKs (#171)
marandaneto Nov 20, 2020
c05fcbf
flutter native ios (#161)
rxlabz Nov 20, 2020
e34fd3c
Fix: CHANGELOG for sentry and sentry_flutter (#173)
marandaneto Nov 20, 2020
f8d38d8
Fix: Changelog and READMEs (#174)
marandaneto Nov 20, 2020
07b462c
fix readme
marandaneto Nov 20, 2020
eed57c0
add known limitations section
marandaneto Nov 20, 2020
960946b
remove deadcode
marandaneto Nov 20, 2020
9d4a7c8
Fix: flutter versioniong and its dependency version (#172)
marandaneto Nov 20, 2020
b199361
hack pass CI
marandaneto Nov 20, 2020
f36fb53
fix main.dart example and update readme (#176)
rxlabz Nov 20, 2020
8ea9a69
Ref: create a export file for sentry_flutter (#175)
marandaneto Nov 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
draft
  • Loading branch information
marandaneto committed Nov 4, 2020
commit d26c7163d1e4bc395f85baf67a28bba22bcbbf81
31 changes: 25 additions & 6 deletions dart/lib/src/protocol/sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,30 @@ import 'package.dart';
@immutable
class Sdk {
/// Creates an [Sdk] object which represents the SDK that created an [Event].
const Sdk({
Sdk({
@required this.name,
@required this.version,
this.integrations,
this.packages,
}) : assert(name != null || version != null);
List<String> integrations,
List<Package> packages,
}) : assert(name != null || version != null),
_integrations = integrations ?? [],
_packages = packages ?? [];

/// The name of the SDK.
final String name;

/// The version of the SDK.
final String version;

final List<String> _integrations;

/// A list of integrations enabled in the SDK that created the [Event].
final List<String> integrations;
List<String> get integrations => List.unmodifiable(_integrations);

final List<Package> _packages;

/// A list of packages that compose this SDK.
final List<Package> packages;
List<Package> get packages => List.unmodifiable(_packages);

String get identifier => '${name}/${version}';

Expand All @@ -61,13 +67,26 @@ class Sdk {
final json = <String, dynamic>{};
json['name'] = name;
json['version'] = version;

if (packages != null && packages.isNotEmpty) {
json['packages'] =
packages.map((p) => p.toJson()).toList(growable: false);
}

if (integrations != null && integrations.isNotEmpty) {
json['integrations'] = integrations;
}
return json;
}

/// Adds a package
void addPackage(String name, String version) {
final package = Package(name, version);
_packages.add(package);
}

// Adds an integration
void addIntegration(String integration) {
_integrations.add(integration);
}
}
4 changes: 3 additions & 1 deletion dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ class SentryOptions {
// TODO: sendDefaultPii

// TODO: those ctor params could be set on Sentry._setDefaultConfiguration or instantiate by default here
SentryOptions({this.dsn});
SentryOptions({this.dsn}) {
sdk.addPackage('pub:sentry', sdkVersion);
}

/// Adds an event processor
void addEventProcessor(EventProcessor eventProcessor) {
Expand Down
2 changes: 1 addition & 1 deletion flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
options.dsn = _exampleDsn,

// release is required on Web to match the source maps
options.release = _release,
// options.release = _release,
},
initMyApp);
}
Expand Down
74 changes: 74 additions & 0 deletions flutter/lib/default_integrations.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import 'dart:async';
import 'dart:isolate';

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

// TODO: we might need flags on options to disable those integrations
// not sure if its possible to use removeIntegration for runZonedGuardedIntegration
// because its an internal method

/// integration that capture errors on the current Isolate Error handler
void isolateErrorIntegration(Hub hub, SentryOptions options) {
final receivePort = RawReceivePort(
(dynamic error) async {
options.logger(SentryLevel.debug, 'Capture from IsolateError $error');

// TODO: create mechanism

// https://api.dartlang.org/stable/2.7.0/dart-isolate/Isolate/addErrorListener.html
// error is a list of 2 elements
if (error is List<dynamic> && error.length == 2) {
dynamic stackTrace = error.last;
if (stackTrace != null) {
stackTrace = StackTrace.fromString(stackTrace as String);
}
await Sentry.captureException(error.first, stackTrace: stackTrace);
}
},
);

Isolate.current.addErrorListener(receivePort.sendPort);
}

/// integration that capture errors on the FlutterError handler
void flutterErrorIntegration(Hub hub, SentryOptions options) {
final defaultOnError = FlutterError.onError;

FlutterError.onError = (FlutterErrorDetails errorDetails) async {
options.logger(
SentryLevel.debug, 'Capture from onError ${errorDetails.exception}');

// TODO: create mechanism

await hub.captureException(
errorDetails.exception,
stackTrace: errorDetails.stack,
);

// call original handler
if (defaultOnError != null) {
defaultOnError(errorDetails);
}
};
}

/// integration that capture errors on the runZonedGuarded error handler
Integration runZonedGuardedIntegration(
Function callback,
) {
void integration(Hub hub, SentryOptions options) {
runZonedGuarded(() {
callback();
}, (exception, stackTrace) async {
// TODO: create mechanism

await Sentry.captureException(
exception,
stackTrace: stackTrace,
);
});
}

return integration;
}
132 changes: 52 additions & 80 deletions flutter/lib/sentry_flutter.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'dart:async';
import 'dart:isolate';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:package_info/package_info.dart';
import 'package:sentry/sentry.dart';

import 'default_integrations.dart';
import 'version.dart';

mixin SentryFlutter {
Expand All @@ -16,97 +17,68 @@ mixin SentryFlutter {
return version;
}

static void _flutterErrorIntegration(Hub hub, SentryOptions options) {
final defaultOnError = FlutterError.onError;
static void init(
OptionsConfiguration optionsConfiguration,
Function callback,
) {
Sentry.init((options) async {
await _initDefaultValues(options, callback);

FlutterError.onError = (FlutterErrorDetails errorDetails) async {
options.logger(
SentryLevel.debug, 'Capture from onError ${errorDetails.exception}');
optionsConfiguration(options);
});
}

// TODO: create mechanism
static Future<void> _initDefaultValues(
SentryOptions options, Function callback) async {
// it is necessary to initialize Flutter method channels so that
// our plugin can call into the native code.
WidgetsFlutterBinding.ensureInitialized();

await hub.captureException(
errorDetails.exception,
stackTrace: errorDetails.stack,
);
// TODO: we could read the window and add some stuff on contexts
// final window = WidgetsBinding.instance.window;

// call original handler
if (defaultOnError != null) {
defaultOnError(errorDetails);
}
};
}
options.debug = kDebugMode;

static void _isolateErrorIntegration(Hub hub, SentryOptions options) {
final receivePort = RawReceivePort(
(dynamic error) async {
options.logger(SentryLevel.debug, 'Capture from IsolateError $error');

// TODO: create mechanism

// https://api.dartlang.org/stable/2.7.0/dart-isolate/Isolate/addErrorListener.html
// error is a list of 2 elements
if (error is List<dynamic> && error.length == 2) {
dynamic stackTrace = error.last;
if (stackTrace != null) {
stackTrace = StackTrace.fromString(stackTrace as String);
}
await Sentry.captureException(error.first, stackTrace: stackTrace);
}
},
);
if (!kReleaseMode) {
options.environment = 'debug';
}

Isolate.current.addErrorListener(receivePort.sendPort);
}
options.release = await _formatRelease(options);

static Integration _runZonedGuardedIntegration(
Function callback,
) {
void integration(Hub hub, SentryOptions options) {
runZonedGuarded(() {
// it is necessary to initialize Flutter method channels so that
// our plugin can call into the native code.
WidgetsFlutterBinding.ensureInitialized();

// TODO: we could read the window and add some stuff on contexts
// final window = WidgetsBinding.instance.window;

callback();
}, (exception, stackTrace) async {
// TODO: create mechanism

await Sentry.captureException(
exception,
stackTrace: stackTrace,
);
});
}
_addDefaultIntegrations(options, callback);

return integration;
_setSdk(options);
}

static void init(
OptionsConfiguration optionsConfiguration,
Function callback,
) {
Sentry.init((options) {
options.debug = kDebugMode;

if (!kReleaseMode) {
options.environment = 'debug';
}
static Future<String> _formatRelease(SentryOptions options) async {
final packageInfo = await PackageInfo.fromPlatform();

// overwrite sdk info with current flutter sdk
options.sdk = const Sdk(name: sdkName, version: sdkVersion);
final release =
'${packageInfo.packageName}@${packageInfo.version}+${packageInfo.buildNumber}';
options.logger(SentryLevel.debug, 'release: $release');
return release;
}

// Throws when running on the browser
if (!kIsWeb) {
options.addIntegration(_isolateErrorIntegration);
}
options.addIntegration(_flutterErrorIntegration);
options.addIntegration(_runZonedGuardedIntegration(callback));
static void _addDefaultIntegrations(
SentryOptions options, Function callback) {
// Throws when running on the browser
if (!kIsWeb) {
options.addIntegration(isolateErrorIntegration);
}
options.addIntegration(flutterErrorIntegration);
options.addIntegration(runZonedGuardedIntegration(callback));
}

optionsConfiguration(options);
});
static void _setSdk(SentryOptions options) {
// overwrite sdk info with current flutter sdk
final sdk = Sdk(
name: sdkName,
version: sdkVersion,
integrations:
List.from(options.sdk.integrations), // otherwise its readonly
packages: List.from(options.sdk.packages),
);
sdk.addPackage('pub:sentry_flutter', sdkVersion);
options.sdk = sdk;
}
}
2 changes: 2 additions & 0 deletions flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies:
sdk: flutter
sentry: #^4.0.0 uncomment before publishing
path: ../dart
#device_info: ^1.0.0
package_info: ^0.4.0

dev_dependencies:
flutter_test:
Expand Down