Skip to content

Commit ba93c17

Browse files
authored
Merge branch 'main' into feat/always-send-sampled-flag
2 parents 16ca40c + 5aa047a commit ba93c17

24 files changed

+155
-73
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Add http.request.method attribute to http spans data ([#1633](https://github.com/getsentry/sentry-dart/pull/1633))
88
- Add db.system and db.name attributes to db spans data ([#1629](https://github.com/getsentry/sentry-dart/pull/1629))
9+
- Log SDK errors to the console if the log level is `fatal` even if `debug` is disabled ([#1635](https://github.com/getsentry/sentry-dart/pull/1635))
910

1011
### Features
1112

dart/lib/src/diagnostic_logger.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class DiagnosticLogger {
2626
}
2727

2828
bool _isEnabled(SentryLevel level) {
29-
return _options.debug && level.ordinal >= _options.diagnosticLevel.ordinal;
29+
return _options.debug &&
30+
level.ordinal >= _options.diagnosticLevel.ordinal ||
31+
level == SentryLevel.fatal;
3032
}
3133
}

dart/test/diagnostic_logger_test.dart

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:sentry/sentry.dart';
2+
import 'package:sentry/src/diagnostic_logger.dart';
3+
import 'package:test/test.dart';
4+
5+
void main() {
6+
late Fixture fixture;
7+
8+
setUp(() {
9+
fixture = Fixture();
10+
});
11+
12+
test('$DiagnosticLogger do not log if debug is disabled', () {
13+
fixture.options.debug = false;
14+
15+
fixture.getSut().log(SentryLevel.error, 'foobar');
16+
17+
expect(fixture.loggedMessage, isNull);
18+
});
19+
20+
test('$DiagnosticLogger log if debug is enabled', () {
21+
fixture.options.debug = true;
22+
23+
fixture.getSut().log(SentryLevel.error, 'foobar');
24+
25+
expect(fixture.loggedMessage, 'foobar');
26+
});
27+
28+
test('$DiagnosticLogger do not log if level is too low', () {
29+
fixture.options.debug = true;
30+
fixture.options.diagnosticLevel = SentryLevel.error;
31+
32+
fixture.getSut().log(SentryLevel.warning, 'foobar');
33+
34+
expect(fixture.loggedMessage, isNull);
35+
});
36+
37+
test('$DiagnosticLogger always log fatal', () {
38+
fixture.options.debug = false;
39+
40+
fixture.getSut().log(SentryLevel.fatal, 'foobar');
41+
42+
expect(fixture.loggedMessage, 'foobar');
43+
});
44+
}
45+
46+
class Fixture {
47+
var options = SentryOptions();
48+
49+
Object? loggedMessage;
50+
51+
DiagnosticLogger getSut() {
52+
return DiagnosticLogger(mockLogger, options);
53+
}
54+
55+
void mockLogger(
56+
SentryLevel level,
57+
String message, {
58+
String? logger,
59+
Object? exception,
60+
StackTrace? stackTrace,
61+
}) {
62+
loggedMessage = message;
63+
}
64+
}

flutter/analysis_options.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
include: package:flutter_lints/flutter.yaml
22

33
analyzer:
4+
exclude:
5+
- test/*.mocks.dart
46
language:
57
strict-casts: true
68
strict-inference: true

flutter/ffi-cocoa.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: SentryCocoa
22
description: Sentry Cocoa SDK FFI binding.
33
language: objc
4-
output: lib/src/sentry_cocoa.dart
4+
output: lib/src/native/cocoa/binding.dart
55
headers:
66
entry-points:
77
- ./cocoa_bindings_temp/Sentry.framework/Versions/A/PrivateHeaders/PrivateSentrySDKOnly.h

flutter/lib/src/event_processor/native_app_start_event_processor.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import 'dart:async';
22

33
import 'package:sentry/sentry.dart';
44

5-
import '../sentry_native.dart';
6-
import '../sentry_native_channel.dart';
5+
import '../native/sentry_native.dart';
76

87
/// EventProcessor that enriches [SentryTransaction] objects with app start
98
/// measurement.

flutter/lib/src/integrations/native_app_start_integration.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:flutter/scheduler.dart';
22
import 'package:sentry/sentry.dart';
33

44
import '../sentry_flutter_options.dart';
5-
import '../sentry_native.dart';
5+
import '../native/sentry_native.dart';
66
import '../event_processor/native_app_start_event_processor.dart';
77

88
/// Integration which handles communication with native frameworks in order to

flutter/lib/src/sentry_native.dart renamed to flutter/lib/src/native/sentry_native.dart

+31-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:async';
22

33
import 'package:meta/meta.dart';
44

5-
import '../sentry_flutter.dart';
5+
import '../../sentry_flutter.dart';
66
import 'sentry_native_channel.dart';
77

88
/// [SentryNative] holds state that it fetches from to the native SDKs. Always
@@ -98,3 +98,33 @@ class SentryNative {
9898
_didFetchAppStart = false;
9999
}
100100
}
101+
102+
class NativeAppStart {
103+
NativeAppStart(this.appStartTime, this.isColdStart);
104+
105+
double appStartTime;
106+
bool isColdStart;
107+
108+
factory NativeAppStart.fromJson(Map<String, dynamic> json) {
109+
return NativeAppStart(
110+
json['appStartTime'] as double,
111+
json['isColdStart'] as bool,
112+
);
113+
}
114+
}
115+
116+
class NativeFrames {
117+
NativeFrames(this.totalFrames, this.slowFrames, this.frozenFrames);
118+
119+
int totalFrames;
120+
int slowFrames;
121+
int frozenFrames;
122+
123+
factory NativeFrames.fromJson(Map<String, dynamic> json) {
124+
return NativeFrames(
125+
json['totalFrames'] as int,
126+
json['slowFrames'] as int,
127+
json['frozenFrames'] as int,
128+
);
129+
}
130+
}

flutter/lib/src/sentry_native_channel.dart renamed to flutter/lib/src/native/sentry_native_channel.dart

+3-32
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import 'dart:async';
33
import 'package:flutter/services.dart';
44
import 'package:meta/meta.dart';
55

6-
import '../sentry_flutter.dart';
6+
import '../../sentry_flutter.dart';
7+
import 'sentry_native.dart';
78
import 'method_channel_helper.dart';
89

9-
/// Provide typed methods to access native layer.
10+
/// Provide typed methods to access native layer via MethodChannel.
1011
@internal
1112
class SentryNativeChannel {
1213
SentryNativeChannel(this._channel, this._options);
@@ -149,33 +150,3 @@ class SentryNativeChannel {
149150
);
150151
}
151152
}
152-
153-
class NativeAppStart {
154-
NativeAppStart(this.appStartTime, this.isColdStart);
155-
156-
double appStartTime;
157-
bool isColdStart;
158-
159-
factory NativeAppStart.fromJson(Map<String, dynamic> json) {
160-
return NativeAppStart(
161-
json['appStartTime'] as double,
162-
json['isColdStart'] as bool,
163-
);
164-
}
165-
}
166-
167-
class NativeFrames {
168-
NativeFrames(this.totalFrames, this.slowFrames, this.frozenFrames);
169-
170-
int totalFrames;
171-
int slowFrames;
172-
int frozenFrames;
173-
174-
factory NativeFrames.fromJson(Map<String, dynamic> json) {
175-
return NativeFrames(
176-
json['totalFrames'] as int,
177-
json['slowFrames'] as int,
178-
json['frozenFrames'] as int,
179-
);
180-
}
181-
}

flutter/lib/src/navigation/sentry_navigator_observer.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import 'package:flutter/widgets.dart';
22

33
import '../../sentry_flutter.dart';
4-
import '../sentry_native.dart';
5-
import '../sentry_native_channel.dart';
4+
import '../native/sentry_native.dart';
65

76
/// This key must be used so that the web interface displays the events nicely
87
/// See https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/

flutter/lib/src/sentry_flutter.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import 'event_processor/android_platform_exception_event_processor.dart';
1010
import 'event_processor/flutter_exception_event_processor.dart';
1111
import 'event_processor/platform_exception_event_processor.dart';
1212
import 'integrations/screenshot_integration.dart';
13-
import 'native_scope_observer.dart';
13+
import 'native/native_scope_observer.dart';
1414
import 'renderer/renderer.dart';
15-
import 'sentry_native.dart';
16-
import 'sentry_native_channel.dart';
15+
import 'native/sentry_native.dart';
16+
import 'native/sentry_native_channel.dart';
1717

1818
import 'integrations/integrations.dart';
1919
import 'event_processor/flutter_enricher_event_processor.dart';
@@ -47,10 +47,10 @@ mixin SentryFlutter {
4747
flutterOptions.rendererWrapper = rendererWrapper;
4848
}
4949

50-
final nativeChannel = SentryNativeChannel(channel, flutterOptions);
5150
if (flutterOptions.platformChecker.hasNativeIntegration) {
52-
final native = SentryNative();
53-
native.nativeChannel = nativeChannel;
51+
// Set a default native channel to the singleton SentryNative instance.
52+
SentryNative().nativeChannel =
53+
SentryNativeChannel(channel, flutterOptions);
5454
}
5555

5656
final platformDispatcher = PlatformDispatcher.instance;

flutter/test/integrations/native_app_start_integration_test.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
44
import 'package:mockito/mockito.dart';
55
import 'package:sentry_flutter/sentry_flutter.dart';
66
import 'package:sentry_flutter/src/integrations/native_app_start_integration.dart';
7-
import 'package:sentry_flutter/src/sentry_native.dart';
8-
import 'package:sentry_flutter/src/sentry_native_channel.dart';
7+
import 'package:sentry_flutter/src/native/sentry_native.dart';
98
import 'package:sentry/src/sentry_tracer.dart';
109

1110
import '../mocks.dart';

flutter/test/method_channel_helper_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter_test/flutter_test.dart';
2-
import 'package:sentry_flutter/src/method_channel_helper.dart';
2+
import 'package:sentry_flutter/src/native/method_channel_helper.dart';
33
import 'package:collection/collection.dart';
44

55
void main() {

flutter/test/mocks.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import 'package:sentry/src/sentry_tracer.dart';
1111
import 'package:meta/meta.dart';
1212
import 'package:sentry_flutter/src/binding_wrapper.dart';
1313
import 'package:sentry_flutter/src/renderer/renderer.dart';
14-
import 'package:sentry_flutter/src/sentry_native.dart';
15-
import 'package:sentry_flutter/src/sentry_native_channel.dart';
14+
import 'package:sentry_flutter/src/native/sentry_native.dart';
15+
import 'package:sentry_flutter/src/native/sentry_native_channel.dart';
1616

1717
import 'mocks.mocks.dart';
1818
import 'no_such_method_provider.dart';

flutter/test/mocks.mocks.dart

+29-12
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import 'package:sentry/sentry.dart' as _i2;
1313
import 'package:sentry/src/protocol.dart' as _i3;
1414
import 'package:sentry/src/sentry_envelope.dart' as _i7;
1515
import 'package:sentry/src/sentry_tracer.dart' as _i8;
16-
import 'package:sentry_flutter/src/sentry_native.dart' as _i10;
17-
import 'package:sentry_flutter/src/sentry_native_channel.dart' as _i11;
16+
import 'package:sentry_flutter/src/native/sentry_native.dart' as _i10;
17+
import 'package:sentry_flutter/src/native/sentry_native_channel.dart' as _i11;
1818

1919
import 'mocks.dart' as _i12;
2020

@@ -112,8 +112,18 @@ class _FakeSentryId_7 extends _i1.SmartFake implements _i3.SentryId {
112112
);
113113
}
114114

115-
class _FakeHub_8 extends _i1.SmartFake implements _i2.Hub {
116-
_FakeHub_8(
115+
class _FakeScope_8 extends _i1.SmartFake implements _i2.Scope {
116+
_FakeScope_8(
117+
Object parent,
118+
Invocation parentInvocation,
119+
) : super(
120+
parent,
121+
parentInvocation,
122+
);
123+
}
124+
125+
class _FakeHub_9 extends _i1.SmartFake implements _i2.Hub {
126+
_FakeHub_9(
117127
Object parent,
118128
Invocation parentInvocation,
119129
) : super(
@@ -144,7 +154,6 @@ class MockTransport extends _i1.Mock implements _i2.Transport {
144154
/// A class which mocks [SentryTracer].
145155
///
146156
/// See the documentation for Mockito's code generation for more information.
147-
// ignore: invalid_use_of_internal_member
148157
class MockSentryTracer extends _i1.Mock implements _i8.SentryTracer {
149158
MockSentryTracer() {
150159
_i1.throwOnMissingStub(this);
@@ -526,13 +535,13 @@ class MockSentryNative extends _i1.Mock implements _i10.SentryNative {
526535
returnValue: false,
527536
) as bool);
528537
@override
529-
_i6.Future<_i11.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod(
538+
_i6.Future<_i10.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod(
530539
Invocation.method(
531540
#fetchNativeAppStart,
532541
[],
533542
),
534-
returnValue: _i6.Future<_i11.NativeAppStart?>.value(),
535-
) as _i6.Future<_i11.NativeAppStart?>);
543+
returnValue: _i6.Future<_i10.NativeAppStart?>.value(),
544+
) as _i6.Future<_i10.NativeAppStart?>);
536545
@override
537546
_i6.Future<void> beginNativeFramesCollection() => (super.noSuchMethod(
538547
Invocation.method(
@@ -543,15 +552,15 @@ class MockSentryNative extends _i1.Mock implements _i10.SentryNative {
543552
returnValueForMissingStub: _i6.Future<void>.value(),
544553
) as _i6.Future<void>);
545554
@override
546-
_i6.Future<_i11.NativeFrames?> endNativeFramesCollection(
555+
_i6.Future<_i10.NativeFrames?> endNativeFramesCollection(
547556
_i3.SentryId? traceId) =>
548557
(super.noSuchMethod(
549558
Invocation.method(
550559
#endNativeFramesCollection,
551560
[traceId],
552561
),
553-
returnValue: _i6.Future<_i11.NativeFrames?>.value(),
554-
) as _i6.Future<_i11.NativeFrames?>);
562+
returnValue: _i6.Future<_i10.NativeFrames?>.value(),
563+
) as _i6.Future<_i10.NativeFrames?>);
555564
@override
556565
_i6.Future<void> setContexts(
557566
String? key,
@@ -695,6 +704,14 @@ class MockHub extends _i1.Mock implements _i2.Hub {
695704
),
696705
) as _i3.SentryId);
697706
@override
707+
_i2.Scope get scope => (super.noSuchMethod(
708+
Invocation.getter(#scope),
709+
returnValue: _FakeScope_8(
710+
this,
711+
Invocation.getter(#scope),
712+
),
713+
) as _i2.Scope);
714+
@override
698715
_i6.Future<_i3.SentryId> captureEvent(
699716
_i3.SentryEvent? event, {
700717
dynamic stackTrace,
@@ -828,7 +845,7 @@ class MockHub extends _i1.Mock implements _i2.Hub {
828845
#clone,
829846
[],
830847
),
831-
returnValue: _FakeHub_8(
848+
returnValue: _FakeHub_9(
832849
this,
833850
Invocation.method(
834851
#clone,

flutter/test/native_scope_observer_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import 'package:flutter_test/flutter_test.dart';
44
import 'package:sentry/sentry.dart';
5-
import 'package:sentry_flutter/src/native_scope_observer.dart';
5+
import 'package:sentry_flutter/src/native/native_scope_observer.dart';
66

77
import 'mocks.dart';
88

flutter/test/sentry_flutter_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
66
import 'package:sentry_flutter/src/integrations/integrations.dart';
77
import 'package:sentry_flutter/src/integrations/screenshot_integration.dart';
88
import 'package:sentry_flutter/src/renderer/renderer.dart';
9-
import 'package:sentry_flutter/src/sentry_native.dart';
9+
import 'package:sentry_flutter/src/native/sentry_native.dart';
1010
import 'package:sentry_flutter/src/version.dart';
1111
import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_integration.dart';
1212
import 'mocks.dart';

0 commit comments

Comments
 (0)