Skip to content

Commit

Permalink
Merge branch 'main' into feat/enable-tracing-option
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Apr 21, 2023
2 parents 1b0548b + fed8146 commit 10927cf
Show file tree
Hide file tree
Showing 62 changed files with 361 additions and 339 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@
- If set to `true`, performance is enabled, even if no `tracesSampleRate` or `tracesSampler` have been configured.
- If set to `true`, sampler will use default sample rate of 1.0, if no `tracesSampleRate` is set.
- If set to `false` performance is disabled, regardless of `tracesSampleRate` and `tracesSampler` options.
- Set User `name` and `geo` in native plugins ([#1393](https://github.com/getsentry/sentry-dart/pull/1393))

### Fixes

- Screenshots and View Hierarchy should only be added to errors ([#1385](https://github.com/getsentry/sentry-dart/pull/1385))
- View Hierarchy is removed from Web errors since we don't symbolicate minified View Hierarchy yet.
- More improvements related to not awaiting `FutureOr<T>` if it's not a future ([#1385](https://github.com/getsentry/sentry-dart/pull/1385))
- Do not report only async gap frames for logging calls ([#1398](https://github.com/getsentry/sentry-dart/pull/1398))

### Dependencies

- Bump Cocoa SDK from v8.4.0 to v8.5.0 ([#1394](https://github.com/getsentry/sentry-dart/pull/1394))
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#850)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.4.0...8.5.0)

## 7.4.2

### Fixes
Expand Down
4 changes: 2 additions & 2 deletions dart/example/bin/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ Future<void> decode() async {
throw StateError('This is a test error');
}

class TagEventProcessor extends EventProcessor {
class TagEventProcessor implements EventProcessor {
@override
FutureOr<SentryEvent?> apply(SentryEvent event, {hint}) {
SentryEvent? apply(SentryEvent event, {hint}) {
return event..tags?.addAll({'page-locale': 'en-us'});
}
}
4 changes: 2 additions & 2 deletions dart/example_web/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ Future<void> parseData() async {
throw StateError('This is a test error');
}

class TagEventProcessor extends EventProcessor {
class TagEventProcessor implements EventProcessor {
@override
FutureOr<SentryEvent?> apply(SentryEvent event, {hint}) {
SentryEvent? apply(SentryEvent event, {hint}) {
return event..tags?.addAll({'page-locale': 'en-us'});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:collection';
import '../event_processor.dart';
import '../hint.dart';
Expand All @@ -19,15 +18,15 @@ import '../sentry_options.dart';
/// var fooTwo = Exception('foo');
/// ```
/// because (fooOne == fooTwo) equals false
class DeduplicationEventProcessor extends EventProcessor {
class DeduplicationEventProcessor implements EventProcessor {
DeduplicationEventProcessor(this._options);

// Using a HashSet makes this performant.
final Queue<int> _exceptionToDeduplicate = Queue<int>();
final SentryOptions _options;

@override
FutureOr<SentryEvent?> apply(SentryEvent event, {Hint? hint}) {
SentryEvent? apply(SentryEvent event, {Hint? hint}) {
if (event is SentryTransaction) {
return event;
}
Expand All @@ -39,7 +38,7 @@ class DeduplicationEventProcessor extends EventProcessor {
return _deduplicate(event);
}

FutureOr<SentryEvent?> _deduplicate(SentryEvent event) {
SentryEvent? _deduplicate(SentryEvent event) {
// Cast to `Object?` in order to enable better type checking
// because `event.throwable` is `dynamic`
final exception = event.throwable as Object?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:io';

import '../../../sentry.dart';
Expand All @@ -19,7 +18,7 @@ class IoEnricherEventProcessor implements EnricherEventProcessor {
final SentryOptions _options;

@override
FutureOr<SentryEvent> apply(SentryEvent event, {Hint? hint}) {
SentryEvent? apply(SentryEvent event, {Hint? hint}) {
// If there's a native integration available, it probably has better
// information available than Flutter.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:html' as html show window, Window;

import '../../../sentry.dart';
Expand All @@ -22,7 +21,7 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {
final SentryOptions _options;

@override
FutureOr<SentryEvent> apply(SentryEvent event, {Hint? hint}) {
SentryEvent? apply(SentryEvent event, {Hint? hint}) {
// Web has no native integration, so no need to check for it

final contexts = event.contexts.copyWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class IoExceptionEventProcessor implements ExceptionEventProcessor {
final SentryOptions _options;

@override
SentryEvent apply(SentryEvent event, {Hint? hint}) {
SentryEvent? apply(SentryEvent event, {Hint? hint}) {
final throwable = event.throwable;
if (throwable is HttpException) {
return _applyHttpException(throwable, event);
Expand Down
5 changes: 4 additions & 1 deletion dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ class Hub {
final item = _peek();

try {
await callback(item.scope);
final result = callback(item.scope);
if (result is Future) {
await result;
}
} catch (err) {
_options.logger(
SentryLevel.error,
Expand Down
5 changes: 2 additions & 3 deletions dart/lib/src/isolate_error_integration.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import 'dart:async';
import 'dart:isolate';

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

class IsolateErrorIntegration extends Integration {
class IsolateErrorIntegration implements Integration<SentryOptions> {
RawReceivePort? _receivePort;

@override
FutureOr<void> call(Hub hub, SentryOptions options) {
void call(Hub hub, SentryOptions options) {
_receivePort = Isolate.current.addSentryErrorListener();
options.sdk.addIntegration('isolateErrorIntegration');
}
Expand Down
10 changes: 4 additions & 6 deletions dart/lib/src/noop_isolate_error_integration.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import 'dart:async';

import 'hub.dart';
import 'integration.dart';
import 'sentry_options.dart';

/// NoOp web integration : isolate doesnt' work in browser
class IsolateErrorIntegration extends Integration {
class IsolateErrorIntegration extends Integration<SentryOptions> {
@override
FutureOr<void> call(Hub hub, SentryOptions options) async {}
void call(Hub hub, SentryOptions options) {}

Future<void> handleIsolateError(
void handleIsolateError(
Hub hub,
SentryOptions options,
dynamic error,
) async {}
) {}
}
4 changes: 2 additions & 2 deletions dart/lib/src/run_zoned_guarded_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef RunZonedGuardedOnError = FutureOr<void> Function(Object, StackTrace);
///
/// This integration also records calls to `print()` as Breadcrumbs.
/// This can be configured with [SentryOptions.enablePrintBreadcrumbs]
class RunZonedGuardedIntegration extends Integration {
class RunZonedGuardedIntegration extends Integration<SentryOptions> {
RunZonedGuardedIntegration(this._runner, this._onError);

final RunZonedGuardedRunner _runner;
Expand Down Expand Up @@ -64,7 +64,7 @@ class RunZonedGuardedIntegration extends Integration {
}

@override
FutureOr<void> call(Hub hub, SentryOptions options) {
Future<void> call(Hub hub, SentryOptions options) {
final completer = Completer<void>();

runZonedGuarded(
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class Scope {
for (final processor in _eventProcessors) {
try {
final e = processor.apply(processedEvent!, hint: hint);
if (e is Future) {
if (e is Future<SentryEvent?>) {
processedEvent = await e;
} else {
processedEvent = e;
Expand Down
6 changes: 3 additions & 3 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ class SentryClient {
if (event is SentryTransaction && beforeSendTransaction != null) {
beforeSendName = 'beforeSendTransaction';
final e = beforeSendTransaction(event);
if (e is Future) {
if (e is Future<SentryTransaction?>) {
eventOrTransaction = await e;
} else {
eventOrTransaction = e;
}
} else if (beforeSend != null) {
final e = beforeSend(event, hint: hint);
if (e is Future) {
if (e is Future<SentryEvent?>) {
eventOrTransaction = await e;
} else {
eventOrTransaction = e;
Expand Down Expand Up @@ -411,7 +411,7 @@ class SentryClient {
for (final processor in eventProcessors) {
try {
final e = processor.apply(processedEvent!, hint: hint);
if (e is Future) {
if (e is Future<SentryEvent?>) {
processedEvent = await e;
} else {
processedEvent = e;
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/sentry_envelope_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class _CachedItem {

Future<List<int>> getData() async {
final data = _dataFactory();
if (data is Future) {
if (data is Future<List<int>>) {
_data ??= await data;
} else {
_data ??= data;
Expand Down
84 changes: 42 additions & 42 deletions dart/test/event_processor/enricher/io_enricher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ void main() {
fixture = Fixture();
});

test('adds dart runtime', () async {
test('adds dart runtime', () {
final enricher = fixture.getSut();
final event = await enricher.apply(SentryEvent());
final event = enricher.apply(SentryEvent());

expect(event.contexts.runtimes, isNotEmpty);
final dartRuntime = event.contexts.runtimes
expect(event?.contexts.runtimes, isNotEmpty);
final dartRuntime = event?.contexts.runtimes
.firstWhere((element) => element.name == 'Dart');
expect(dartRuntime.name, 'Dart');
expect(dartRuntime.rawDescription, isNotNull);
expect(dartRuntime?.name, 'Dart');
expect(dartRuntime?.rawDescription, isNotNull);
});

test('does add to existing runtimes', () async {
test('does add to existing runtimes', () {
final runtime = SentryRuntime(name: 'foo', version: 'bar');
var event = SentryEvent(contexts: Contexts(runtimes: [runtime]));
final enricher = fixture.getSut();

event = await enricher.apply(event);
event = enricher.apply(event)!;

expect(event.contexts.runtimes.contains(runtime), true);
// second runtime is Dart runtime
Expand All @@ -40,53 +40,53 @@ void main() {

test(
'does not add device, os and culture if native integration is available',
() async {
() {
final enricher = fixture.getSut(hasNativeIntegration: true);
final event = await enricher.apply(SentryEvent());
final event = enricher.apply(SentryEvent());

expect(event.contexts.device, isNull);
expect(event.contexts.operatingSystem, isNull);
expect(event.contexts.culture, isNull);
expect(event?.contexts.device, isNull);
expect(event?.contexts.operatingSystem, isNull);
expect(event?.contexts.culture, isNull);
});

test('adds device, os and culture if no native integration is available',
() async {
() {
final enricher = fixture.getSut(hasNativeIntegration: false);
final event = await enricher.apply(SentryEvent());
final event = enricher.apply(SentryEvent());

expect(event.contexts.device, isNotNull);
expect(event.contexts.operatingSystem, isNotNull);
expect(event.contexts.culture, isNotNull);
expect(event?.contexts.device, isNotNull);
expect(event?.contexts.operatingSystem, isNotNull);
expect(event?.contexts.culture, isNotNull);
});

test('device has name', () async {
test('device has name', () {
final enricher = fixture.getSut();
final event = await enricher.apply(SentryEvent());
final event = enricher.apply(SentryEvent());

expect(event.contexts.device?.name, isNotNull);
expect(event?.contexts.device?.name, isNotNull);
});

test('culture has locale and timezone', () async {
test('culture has locale and timezone', () {
final enricher = fixture.getSut();
final event = await enricher.apply(SentryEvent());
final event = enricher.apply(SentryEvent());

expect(event.contexts.culture?.locale, isNotNull);
expect(event.contexts.culture?.timezone, isNotNull);
expect(event?.contexts.culture?.locale, isNotNull);
expect(event?.contexts.culture?.timezone, isNotNull);
});

test('os has name and version', () async {
test('os has name and version', () {
final enricher = fixture.getSut();
final event = await enricher.apply(SentryEvent());
final event = enricher.apply(SentryEvent());

expect(event.contexts.operatingSystem?.name, isNotNull);
expect(event.contexts.operatingSystem?.version, isNotNull);
expect(event?.contexts.operatingSystem?.name, isNotNull);
expect(event?.contexts.operatingSystem?.version, isNotNull);
});

test('adds Dart context with PII', () async {
test('adds Dart context with PII', () {
final enricher = fixture.getSut(includePii: true);
final event = await enricher.apply(SentryEvent());
final event = enricher.apply(SentryEvent());

final dartContext = event.contexts['dart_context'];
final dartContext = event?.contexts['dart_context'];
expect(dartContext, isNotNull);
// Getting the executable sometimes throws
//expect(dartContext['executable'], isNotNull);
Expand All @@ -95,11 +95,11 @@ void main() {
// package_config and executable_arguments are optional
});

test('adds Dart context without PII', () async {
test('adds Dart context without PII', () {
final enricher = fixture.getSut(includePii: false);
final event = await enricher.apply(SentryEvent());
final event = enricher.apply(SentryEvent());

final dartContext = event.contexts['dart_context'];
final dartContext = event?.contexts['dart_context'];
expect(dartContext, isNotNull);
expect(dartContext['compile_mode'], isNotNull);
expect(dartContext['executable'], isNull);
Expand All @@ -109,7 +109,7 @@ void main() {
// and Platform is not mockable
});

test('does not override event', () async {
test('does not override event', () {
final fakeEvent = SentryEvent(
contexts: Contexts(
device: SentryDevice(
Expand All @@ -131,29 +131,29 @@ void main() {
hasNativeIntegration: false,
);

final event = await enricher.apply(fakeEvent);
final event = enricher.apply(fakeEvent);

// contexts.device
expect(
event.contexts.device?.name,
event?.contexts.device?.name,
fakeEvent.contexts.device?.name,
);
// contexts.culture
expect(
event.contexts.culture?.locale,
event?.contexts.culture?.locale,
fakeEvent.contexts.culture?.locale,
);
expect(
event.contexts.culture?.timezone,
event?.contexts.culture?.timezone,
fakeEvent.contexts.culture?.timezone,
);
// contexts.operatingSystem
expect(
event.contexts.operatingSystem?.name,
event?.contexts.operatingSystem?.name,
fakeEvent.contexts.operatingSystem?.name,
);
expect(
event.contexts.operatingSystem?.version,
event?.contexts.operatingSystem?.version,
fakeEvent.contexts.operatingSystem?.version,
);
});
Expand Down
Loading

0 comments on commit 10927cf

Please sign in to comment.