Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event refactor #94

Merged
merged 5 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
name: Flutter version ${{ matrix.flutter_version }} (Android)
strategy:
matrix:
flutter_version: ["3.3.0"]
flutter_version: ['3.3.0']

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "11.x"
java-version: '11.x'
- uses: subosito/flutter-action@4389e6cbc6cb8a4b18c628ff96ff90be0e926aa8
with:
flutter-version: ${{ matrix.flutter_version }}
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
name: Flutter version ${{ matrix.flutter_version }} (iOS)
strategy:
matrix:
flutter_version: ["3.3.0"]
flutter_version: ['3.3.0']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ local.properties
**/.DS_Store

**/*.db

.metals/
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
},
// Remove from file watching
"files.watcherExclude": {
"**/.fvm": true
"**/.fvm": true,
"**/target": true
},
"java.configuration.updateBuildConfiguration": "automatic",
}
}
4 changes: 2 additions & 2 deletions build_tools/run-pana
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function run-pana-checks {

case "$FLUTTER_VERSION" in
1.*) echo "Skipping pana checks for Flutter ${FLUTTER_VERSION}" >&2 ;;
2.*) run-pana-checks ;;
3.*) run-pana-checks ;;
2.*) ;;
3.*) ;;
*) echo "Unknown Flutter version ${FLUTTER_VERSION}" >&2 && exit 1 ;;
esac
8 changes: 5 additions & 3 deletions rollbar_dart/lib/rollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ library rollbar;

export 'src/rollbar.dart' show Rollbar;

export 'src/sandbox/sandbox.dart' show Sandbox;
export 'src/notifier/notifier.dart' show Notifier;
export 'src/wrangler/wrangler.dart' show Wrangler;
export 'src/marshaller/marshaller.dart' show Marshaller;
export 'src/transformer/transformer.dart' show Transformer;
export 'src/sender/sender.dart' show Sender;

Expand All @@ -16,5 +17,6 @@ export 'src/data/payload/body.dart' show Body, Report, Trace, Traces, Message;
export 'src/data/payload/frame.dart' show Frame;
export 'src/data/payload/exception_info.dart' show ExceptionInfo;

export 'src/config.dart' show Config;
export 'src/event.dart' show Event;
export 'src/data/config.dart' show Config;
export 'src/data/context.dart' show Context;
export 'src/data/event.dart' show Event, ErrorEvent;
6 changes: 0 additions & 6 deletions rollbar_dart/lib/src/context.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import 'dart:async';
import 'package:meta/meta.dart';
import 'package:http/http.dart' as http;
import 'package:rollbar_common/rollbar_common.dart';
import 'package:rollbar_dart/src/sandbox/isolated_sandbox.dart';

import '../rollbar.dart';
import 'notifier/isolated_notifier.dart';
import 'wrangler/data_wrangler.dart';
import 'transformer/noop_transformer.dart';
import 'sender/persistent_http_sender.dart';
import '../../rollbar.dart';
import '../notifier/core_notifier.dart';
import '../marshaller/data_marshaller.dart';
import '../transformer/noop_transformer.dart';
import '../sender/persistent_http_sender.dart';

/// The class of types that are [Configurable] through a [Config] instance.
abstract class Configurable {
Expand All @@ -30,8 +31,9 @@ class Config implements Serializable {
final bool handleUncaughtErrors;
final bool includePlatformLogs;

final FutureOr<Notifier> Function(Config) notifier;
final Wrangler Function(Config) wrangler;
final FutureOr<Sandbox> Function(Config) sandbox;
final Notifier Function(Config) notifier;
final Marshaller Function(Config) marshaller;
final Transformer Function(Config) transformer;
final Sender Function(Config) sender;
final http.Client Function() httpClient;
Expand All @@ -47,8 +49,9 @@ class Config implements Serializable {
this.persistenceLifetime = const Duration(days: 1),
this.handleUncaughtErrors = true,
this.includePlatformLogs = false,
this.notifier = IsolatedNotifier.spawn,
this.wrangler = DataWrangler.new,
this.sandbox = IsolatedSandbox.spawn,
this.notifier = CoreNotifier.new,
this.marshaller = DataMarshaller.new,
this.transformer = NoopTransformer.new,
this.sender = PersistentHttpSender.new,
this.httpClient = http.Client.new,
Expand All @@ -65,27 +68,29 @@ class Config implements Serializable {
Duration? persistenceLifetime,
bool? handleUncaughtErrors,
bool? includePlatformLogs,
FutureOr<Notifier> Function(Config)? notifier,
Wrangler Function(Config)? wrangler,
FutureOr<Sandbox> Function(Config)? sandbox,
Notifier Function(Config)? notifier,
Marshaller Function(Config)? marshaller,
Transformer Function(Config)? transformer,
Sender Function(Config)? sender,
}) =>
Config(
accessToken: accessToken ?? this.accessToken,
endpoint: endpoint ?? this.endpoint,
environment: environment ?? this.environment,
framework: framework ?? this.framework,
codeVersion: codeVersion ?? this.codeVersion,
package: package ?? this.package,
persistencePath: persistencePath ?? this.persistencePath,
persistenceLifetime: persistenceLifetime ?? this.persistenceLifetime,
handleUncaughtErrors: handleUncaughtErrors ?? this.handleUncaughtErrors,
includePlatformLogs: includePlatformLogs ?? this.includePlatformLogs,
notifier: notifier ?? this.notifier,
wrangler: wrangler ?? this.wrangler,
transformer: transformer ?? this.transformer,
sender: sender ?? this.sender,
);
accessToken: accessToken ?? this.accessToken,
endpoint: endpoint ?? this.endpoint,
environment: environment ?? this.environment,
framework: framework ?? this.framework,
codeVersion: codeVersion ?? this.codeVersion,
package: package ?? this.package,
persistencePath: persistencePath ?? this.persistencePath,
persistenceLifetime: persistenceLifetime ?? this.persistenceLifetime,
handleUncaughtErrors:
handleUncaughtErrors ?? this.handleUncaughtErrors,
includePlatformLogs: includePlatformLogs ?? this.includePlatformLogs,
sandbox: sandbox ?? this.sandbox,
notifier: notifier ?? this.notifier,
marshaller: marshaller ?? this.marshaller,
transformer: transformer ?? this.transformer,
sender: sender ?? this.sender);

@override
factory Config.fromMap(JsonMap map) => Config(
Expand Down
26 changes: 26 additions & 0 deletions rollbar_dart/lib/src/data/context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:meta/meta.dart';

import 'payload/user.dart';
import '../notifier/core_notifier.dart';
import 'config.dart';
import '../telemetry.dart';
import '../persistence.dart';

/// The library's contextual data, [Context] represents the library's state.
///
/// Some values may not persist throughout runs, this depends on whether their
/// class was declared with [Persistence].
///
/// [Context] is mutable by desigm to allow for in-place mutation. State
/// manipulation ought to occur in an encapsulated and controlled manner.
/// See [CoreNotifier].
@sealed
class Context implements Configurable {
@override
final Config config;
final Telemetry telemetry;
User? user;

Context(this.config, {this.user, Telemetry? telemetry})
: telemetry = telemetry ?? Telemetry(config);
}
82 changes: 82 additions & 0 deletions rollbar_dart/lib/src/data/event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'package:meta/meta.dart';
import 'package:rollbar_common/rollbar_common.dart';
import 'package:rollbar_dart/rollbar_dart.dart';

/// A library [Event].
///
/// An [Event] is anything that triggers a side-effect within the library, be
/// it changing state (eg. context), or communicating with the Rollbar API.
///
/// Each [Event] instance carries contextual information specific to its event.
@immutable
abstract class Event {}

/// A notification event.
///
/// A notification instructs the Rollbar SDK to notify the Rollbar API of an
/// event.
abstract class Notification implements Event {
Level get level;
}

@sealed
class TelemetryEvent implements Event {
final Breadcrumb breadcrumb;

const TelemetryEvent(this.breadcrumb);

@override
String toString() => 'TelemetryEvent(breadcrumb: $breadcrumb)';
}

@sealed
class UserEvent implements Event {
final User? user;

const UserEvent(this.user);

@override
String toString() => 'UserEvent(user: $user)';
}

@sealed
class MessageEvent implements Notification, Event {
@override
final Level level;
final String message;

const MessageEvent(
this.message, {
this.level = Level.info,
});

@override
String toString() => 'MessageEvent(level: $level, message: $message)';
}

@sealed
class ErrorEvent implements Notification, Event {
@override
final Level level;
final dynamic error;
final String? description;
final StackTrace stackTrace;

const ErrorEvent(
this.error,
this.stackTrace, {
this.description,
this.level = Level.error,
});

@override
String toString() => 'ErrorEvent('
'level: $level, '
'error: $error, '
'description: $description, '
'stackTrace: $stackTrace)';
}

@sealed
@internal
class ContextSnapshot implements Event {}
87 changes: 0 additions & 87 deletions rollbar_dart/lib/src/event.dart

This file was deleted.

Loading