Skip to content

Commit

Permalink
Merge branch 'v7.0.0' into enha/replace-to-image-with-sync
Browse files Browse the repository at this point in the history
# Conflicts:
#	flutter/lib/src/event_processor/screenshot_event_processor.dart
  • Loading branch information
denrase committed Mar 6, 2023
2 parents 47b743b + 4218615 commit d079e2c
Show file tree
Hide file tree
Showing 42 changed files with 436 additions and 148 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@
### Enhancements

- Replace `toImage` with `toImageSync` for Flutter >= 3.7 ([1268](https://github.com/getsentry/sentry-dart/pull/1268))
- Don't await `FutureOr<T>` if it's not a future. This should marginally improve the performance ([#1310](https://github.com/getsentry/sentry-dart/pull/1310))

## 7.0.0-rc.1

### Breaking Changes

- Enable enableNdkScopeSync by default ([#1276](https://github.com/getsentry/sentry-dart/pull/1276))
- Update `sentry_dio` to dio v5 ([#1282](https://github.com/getsentry/sentry-dart/pull/1282))

### Dependencies

- Bump Android SDK from v6.13.1 to v6.14.0 ([#1287](https://github.com/getsentry/sentry-dart/pull/1287))
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#6140)
- [diff](https://github.com/getsentry/sentry-java/compare/6.13.1...6.14.0)

### Features

- Allow sentry user to control resolution of captured Flutter screenshots ([#1288](https://github.com/getsentry/sentry-dart/pull/1288))

### Features

- Sentry Isolate Extension ([#1266](https://github.com/getsentry/sentry-dart/pull/1266))

## 6.21.0

Expand Down
3 changes: 3 additions & 0 deletions dart/lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ export 'src/type_check_hint.dart';
// exception extraction
export 'src/exception_cause_extractor.dart';
export 'src/exception_cause.dart';
// Isolates
export 'src/sentry_isolate_extension.dart';
export 'src/sentry_isolate.dart';
36 changes: 30 additions & 6 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ class Hub {
);
} else {
final item = _peek();
final scope = await _cloneAndRunWithScope(item.scope, withScope);
late Scope scope;
final s = _cloneAndRunWithScope(item.scope, withScope);
if (s is Future<Scope>) {
scope = await s;
} else {
scope = s;
}

try {
if (_options.isTracingEnabled()) {
Expand Down Expand Up @@ -129,7 +135,13 @@ class Hub {
);
} else {
final item = _peek();
final scope = await _cloneAndRunWithScope(item.scope, withScope);
late Scope scope;
final s = _cloneAndRunWithScope(item.scope, withScope);
if (s is Future<Scope>) {
scope = await s;
} else {
scope = s;
}

try {
var event = SentryEvent(
Expand Down Expand Up @@ -185,7 +197,13 @@ class Hub {
);
} else {
final item = _peek();
final scope = await _cloneAndRunWithScope(item.scope, withScope);
late Scope scope;
final s = _cloneAndRunWithScope(item.scope, withScope);
if (s is Future<Scope>) {
scope = await s;
} else {
scope = s;
}

try {
sentryId = await item.client.captureMessage(
Expand Down Expand Up @@ -239,12 +257,15 @@ class Hub {
}
}

Future<Scope> _cloneAndRunWithScope(
FutureOr<Scope> _cloneAndRunWithScope(
Scope scope, ScopeCallback? withScope) async {
if (withScope != null) {
try {
scope = scope.clone();
await withScope(scope);
final s = withScope(scope);
if (s is Future) {
await s;
}
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
Expand Down Expand Up @@ -306,7 +327,10 @@ class Hub {
} else {
// close integrations
for (final integration in _options.integrations) {
await integration.close();
final close = integration.close();
if (close is Future) {
await close;
}
}

final item = _peek();
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class HubAdapter implements Hub {
Future<void> close() => Sentry.close();

@override
FutureOr<void> configureScope(ScopeCallback callback) async =>
await Sentry.configureScope(callback);
FutureOr<void> configureScope(ScopeCallback callback) =>
Sentry.configureScope(callback);

@override
bool get isEnabled => Sentry.isEnabled;
Expand Down
73 changes: 6 additions & 67 deletions dart/lib/src/isolate_error_integration.dart
Original file line number Diff line number Diff line change
@@ -1,87 +1,26 @@
import 'dart:async';
import 'dart:isolate';

import 'package:meta/meta.dart';

import 'hub.dart';
import 'integration.dart';
import 'protocol.dart';
import 'sentry_isolate_extension.dart';
import 'sentry_options.dart';
import 'throwable_mechanism.dart';

class IsolateErrorIntegration extends Integration {
RawReceivePort? _receivePort;

@override
FutureOr<void> call(Hub hub, SentryOptions options) {
final safeReceivePort = _receivePort = _createPort(hub, options);
Isolate.current.addErrorListener(safeReceivePort.sendPort);
_receivePort = Isolate.current.addSentryErrorListener();
options.sdk.addIntegration('isolateErrorIntegration');
}

@override
void close() {
if (_receivePort != null) {
final safeReceivePort = _receivePort!;
safeReceivePort.close();
Isolate.current.removeErrorListener(safeReceivePort.sendPort);
final receivePort = _receivePort;
if (receivePort != null) {
receivePort.close();
Isolate.current.removeSentryErrorListener(receivePort);
}
}

/// Parse and raise an event out of the Isolate error.
@visibleForTesting
Future<void> handleIsolateError(
Hub hub,
SentryOptions options,
dynamic error,
) async {
options.logger(SentryLevel.debug, 'Capture from IsolateError $error');

// https://api.dartlang.org/stable/2.7.0/dart-isolate/Isolate/addErrorListener.html
// error is a list of 2 elements
if (error is List && error.length == 2) {
/// The errors are sent back as two-element lists.
/// The first element is a `String` representation of the error, usually
/// created by calling `toString` on the error.
/// The second element is a `String` representation of an accompanying
/// stack trace, or `null` if no stack trace was provided.
/// To convert this back to a [StackTrace] object, use [StackTrace.fromString].
final String throwable = error.first;
final String? stackTrace = error.last;

options.logger(
SentryLevel.error,
'Uncaught isolate error',
logger: 'sentry.isolateError',
exception: throwable,
stackTrace:
stackTrace == null ? null : StackTrace.fromString(stackTrace),
);

// Isolate errors don't crash the App.
final mechanism = Mechanism(type: 'isolateError', handled: true);
final throwableMechanism = ThrowableMechanism(mechanism, throwable);
final event = SentryEvent(
throwable: throwableMechanism,
level: SentryLevel.fatal,
timestamp: hub.options.clock(),
);

// marks the span status if none to `internal_error` in case there's an
// unhandled error
hub.configureScope((scope) => {
scope.span?.status ??= const SpanStatus.internalError(),
});

await hub.captureEvent(event, stackTrace: stackTrace);
}
}

RawReceivePort _createPort(Hub hub, SentryOptions options) {
return RawReceivePort(
(dynamic error) async {
await handleIsolateError(hub, options, error);
},
);
}
}
7 changes: 6 additions & 1 deletion dart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,12 @@ class Scope {
SentryEvent? processedEvent = event;
for (final processor in _eventProcessors) {
try {
processedEvent = await processor.apply(processedEvent!, hint: hint);
final e = processor.apply(processedEvent!, hint: hint);
if (e is Future) {
processedEvent = await e;
} else {
processedEvent = e;
}
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
Expand Down
18 changes: 12 additions & 6 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class Sentry {
await _initDefaultValues(sentryOptions);

try {
await optionsConfiguration(sentryOptions);
final config = optionsConfiguration(sentryOptions);
if (config is Future) {
await config;
}
} catch (exception, stackTrace) {
sentryOptions.logger(
SentryLevel.error,
Expand Down Expand Up @@ -149,7 +152,10 @@ class Sentry {
static Future<void> _callIntegrations(
Iterable<Integration> integrations, SentryOptions options) async {
for (final integration in integrations) {
await integration(HubAdapter(), options);
final execute = integration(HubAdapter(), options);
if (execute is Future) {
await execute;
}
}
}

Expand Down Expand Up @@ -219,12 +225,12 @@ class Sentry {
static SentryId get lastEventId => _hub.lastEventId;

/// Adds a breacrumb to the current Scope
static Future<void> addBreadcrumb(Breadcrumb crumb, {Hint? hint}) async =>
await _hub.addBreadcrumb(crumb, hint: hint);
static Future<void> addBreadcrumb(Breadcrumb crumb, {Hint? hint}) =>
_hub.addBreadcrumb(crumb, hint: hint);

/// Configures the scope through the callback.
static FutureOr<void> configureScope(ScopeCallback callback) async =>
await _hub.configureScope(callback);
static FutureOr<void> configureScope(ScopeCallback callback) =>
_hub.configureScope(callback);

/// Clones the current Hub
static Hub clone() => _hub.clone();
Expand Down
21 changes: 18 additions & 3 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,19 @@ class SentryClient {
try {
if (event is SentryTransaction && beforeSendTransaction != null) {
beforeSendName = 'beforeSendTransaction';
eventOrTransaction = await beforeSendTransaction(event);
final e = beforeSendTransaction(event);
if (e is Future) {
eventOrTransaction = await e;
} else {
eventOrTransaction = e;
}
} else if (beforeSend != null) {
eventOrTransaction = await beforeSend(event, hint: hint);
final e = beforeSend(event, hint: hint);
if (e is Future) {
eventOrTransaction = await e;
} else {
eventOrTransaction = e;
}
}
} catch (exception, stackTrace) {
_options.logger(
Expand Down Expand Up @@ -406,7 +416,12 @@ class SentryClient {
SentryEvent? processedEvent = event;
for (final processor in eventProcessors) {
try {
processedEvent = await processor.apply(processedEvent!, hint: hint);
final e = processor.apply(processedEvent!, hint: hint);
if (e is Future) {
processedEvent = await e;
} else {
processedEvent = e;
}
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
Expand Down
12 changes: 9 additions & 3 deletions dart/lib/src/sentry_envelope_item.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'client_reports/client_report.dart';
import 'protocol.dart';
Expand Down Expand Up @@ -25,7 +26,7 @@ class SentryEnvelopeItem {
}

factory SentryEnvelopeItem.fromAttachment(SentryAttachment attachment) {
final cachedItem = _CachedItem(() async => await attachment.bytes);
final cachedItem = _CachedItem(() => attachment.bytes);

final header = SentryEnvelopeItemHeader(
SentryItemType.attachment,
Expand Down Expand Up @@ -106,11 +107,16 @@ class SentryEnvelopeItem {
class _CachedItem {
_CachedItem(this._dataFactory);

final Future<List<int>> Function() _dataFactory;
final FutureOr<List<int>> Function() _dataFactory;
List<int>? _data;

Future<List<int>> getData() async {
_data ??= await _dataFactory();
final data = _dataFactory();
if (data is Future) {
_data ??= await data;
} else {
_data ??= data;
}
return _data!;
}

Expand Down
Loading

0 comments on commit d079e2c

Please sign in to comment.