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

Discard empty stack frames #1625

Merged
merged 8 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- Normalize data properties of `SentryUser` and `Breadcrumb` before sending over method channel ([#1591](https://github.com/getsentry/sentry-dart/pull/1591))
- Fixing memory leak issue in SentryFlutterPlugin (Android Plugin) ([#1588](https://github.com/getsentry/sentry-dart/pull/1588))
- Discard empty stack frames ([#1625](https://github.com/getsentry/sentry-dart/pull/1625))

### Dependencies

Expand Down
24 changes: 12 additions & 12 deletions dio/test/dio_event_processor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void main() {
throwable: throwable,
exceptions: [
fixture.sentryError(throwable),
fixture.sentryError(dioError)
fixture.sentryError(dioError),
],
);
final processedEvent = sut.apply(event) as SentryEvent;
Expand Down Expand Up @@ -96,7 +96,7 @@ void main() {
throwable: throwable,
exceptions: [
fixture.sentryError(throwable),
fixture.sentryError(dioError)
fixture.sentryError(dioError),
],
);
final processedEvent = sut.apply(event) as SentryEvent;
Expand Down Expand Up @@ -125,7 +125,7 @@ void main() {
throwable: throwable,
exceptions: [
fixture.sentryError(throwable),
fixture.sentryError(dioError)
fixture.sentryError(dioError),
],
);
final processedEvent = sut.apply(event) as SentryEvent;
Expand Down Expand Up @@ -177,7 +177,7 @@ void main() {
throwable: throwable,
exceptions: [
fixture.sentryError(throwable),
fixture.sentryError(dioError)
fixture.sentryError(dioError),
],
);
final processedEvent = sut.apply(event) as SentryEvent;
Expand Down Expand Up @@ -207,7 +207,7 @@ void main() {
data: 'foobar',
headers: Headers.fromMap(<String, List<String>>{
'foo': ['bar'],
'set-cookie': ['foo=bar']
'set-cookie': ['foo=bar'],
}),
requestOptions: request,
isRedirect: true,
Expand All @@ -219,7 +219,7 @@ void main() {
throwable: throwable,
exceptions: [
fixture.sentryError(throwable),
fixture.sentryError(dioError)
fixture.sentryError(dioError),
],
);
final processedEvent = sut.apply(event) as SentryEvent;
Expand Down Expand Up @@ -248,7 +248,7 @@ void main() {
response: Response<dynamic>(
data: 'foobar',
headers: Headers.fromMap(<String, List<String>>{
'foo': ['bar']
'foo': ['bar'],
}),
requestOptions: request,
isRedirect: true,
Expand All @@ -260,7 +260,7 @@ void main() {
throwable: throwable,
exceptions: [
fixture.sentryError(throwable),
fixture.sentryError(dioError)
fixture.sentryError(dioError),
],
);
final processedEvent = sut.apply(event) as SentryEvent;
Expand Down Expand Up @@ -320,7 +320,7 @@ void main() {
throwable: throwable,
exceptions: [
fixture.sentryError(throwable),
fixture.sentryError(dioError)
fixture.sentryError(dioError),
],
);
final processedEvent = sut.apply(event) as SentryEvent;
Expand All @@ -338,7 +338,7 @@ void main() {
final dataByType = {
ResponseType.plain: ['plain'],
ResponseType.bytes: [
[1337]
[1337],
],
ResponseType.json: [
9001,
Expand All @@ -347,7 +347,7 @@ void main() {
true,
['list'],
{'map-key': 'map-value'},
]
],
};

for (final entry in dataByType.entries) {
Expand Down Expand Up @@ -375,7 +375,7 @@ void main() {
throwable: throwable,
exceptions: [
fixture.sentryError(throwable),
fixture.sentryError(dioError)
fixture.sentryError(dioError),
],
);
final processedEvent = sut.apply(event) as SentryEvent;
Expand Down
2 changes: 1 addition & 1 deletion dio/test/failed_request_interceptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Fixture {

FailedRequestInterceptor getSut({
List<SentryStatusCode> failedRequestStatusCodes = const [
SentryStatusCode.defaultRange()
SentryStatusCode.defaultRange(),
],
List<String> failedRequestTargets = const ['.*'],
}) {
Expand Down
2 changes: 1 addition & 1 deletion dio/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final fakeEvent = SentryEvent(
type: 'navigation',
data: <String, dynamic>{'screen': 'MainActivity', 'state': 'created'},
level: SentryLevel.info,
)
),
],
contexts: Contexts(
operatingSystem: const SentryOperatingSystem(
Expand Down
8 changes: 6 additions & 2 deletions flutter/lib/src/jvm/jvm_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ class JvmException {
frames.add(trimmed);
}

final thisExceptionFrames =
thisException.map((e) => JvmFrame.parse(e)).toList(growable: false);
final thisExceptionFrames = thisException
// Sometimes stringified exceptions from the native side have
// empty lines. Discard those!
.where((line) => line.trim().isNotEmpty)
denrase marked this conversation as resolved.
Show resolved Hide resolved
.map((e) => JvmFrame.parse(e))
.toList(growable: false);

final suppressedExceptions = supressed
.map((e) => JvmException.parse(e.join(_newLine)))
Expand Down
30 changes: 29 additions & 1 deletion flutter/test/jvm/jvm_exception_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main() {
'Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]');
expect(thirdCause.thread, null);
expect(thirdCause.type, 'java.sql.SQLException');
expect(thirdCause.stackTrace.length, 6);
expect(thirdCause.stackTrace.length, 5);
expect(thirdCause.causes, null);
expect(thirdCause.suppressed, null);
});
Expand Down Expand Up @@ -85,6 +85,16 @@ void main() {
expect(exception.stackTrace[0].fileName, 'StandardMessageCodec.java');
expect(exception.stackTrace[0].lineNumber, 292);
});

test('parse drops empty frames', () {
final exception = JvmException.parse(platformExceptionWithEmptyStackFrames);
expect(exception.stackTrace.length, 13);
expect(exception.stackTrace.last.className,
'com.android.internal.os.ZygoteInit');
expect(exception.stackTrace.last.fileName, 'ZygoteInit.java');
expect(exception.stackTrace.last.method, 'main');
expect(exception.stackTrace.last.lineNumber, 936);
});
}

const javaExceptionWithCauses = '''
Expand Down Expand Up @@ -194,3 +204,21 @@ java.lang.IllegalArgumentException: Unsupported value: '[Ljava.lang.StackTraceEl
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)''';

const platformExceptionWithEmptyStackFrames = '''
java.lang.RuntimeException: Catch this platform exception!
at io.sentry.samples.flutter.MainActivity\$configureFlutterEngine\$1.onMethodCall(MainActivity.kt:40)
at io.flutter.plugin.common.MethodChannel\$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda\$dispatchMessageToQueue\$0\$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
at io.flutter.embedding.engine.dart.DartMessenger\$\$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

''';
1 change: 1 addition & 0 deletions flutter/test/sentry_navigator_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ class _MockHub extends MockHub {
@override
final options = SentryOptions(dsn: fakeDsn);

@override
late final scope = Scope(options);

@override
Expand Down
15 changes: 11 additions & 4 deletions sqflite/lib/src/sentry_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
@internal Hub? hub,
}) : _hub = hub ?? HubAdapter(),
dbName = p.basenameWithoutExtension(_database.path),
super(_database,
hub: hub, dbName: p.basenameWithoutExtension(_database.path)) {
super(
_database,
hub: hub,
dbName: p.basenameWithoutExtension(_database.path),
) {
// ignore: invalid_use_of_internal_member
final options = _hub.options;
options.sdk.addIntegration('SentrySqfliteTracing');
Expand Down Expand Up @@ -132,8 +135,12 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
setDatabaseAttributeData(span, dbName);

Future<T> newAction(Transaction txn) async {
final executor = SentryDatabaseExecutor(txn,
parentSpan: span, hub: _hub, dbName: dbName);
final executor = SentryDatabaseExecutor(
txn,
parentSpan: span,
hub: _hub,
dbName: dbName,
);
final sentrySqfliteTransaction =
SentrySqfliteTransaction(executor, hub: _hub, dbName: dbName);

Expand Down
3 changes: 2 additions & 1 deletion sqflite/test/mocks/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ ISentrySpan startTransactionShim(
],
customMocks: [
MockSpec<Hub>(
fallbackGenerators: {#startTransaction: startTransactionShim}),
fallbackGenerators: {#startTransaction: startTransactionShim},
),
],
)
void main() {}
8 changes: 6 additions & 2 deletions sqflite/test/sentry_batch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ SELECT * FROM Product''';
final span = fixture.tracer.children.last;
expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
expect(
span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);
span.data[SentryDatabase.dbNameKey],
(db as SentryDatabase).dbName,
);

await db.close();
});
Expand All @@ -313,7 +315,9 @@ SELECT * FROM Product''';
final span = fixture.tracer.children.last;
expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
expect(
span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);
span.data[SentryDatabase.dbNameKey],
(db as SentryDatabase).dbName,
);

await db.close();
});
Expand Down
4 changes: 3 additions & 1 deletion sqflite/test/sentry_database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ void main() {
expect(insertSpan.context.parentSpanId, trSpan.context.spanId);
expect(insertSpan.status, SpanStatus.ok());
expect(
insertSpan.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
insertSpan.data[SentryDatabase.dbSystemKey],
SentryDatabase.dbSystem,
);
expect(insertSpan.data[SentryDatabase.dbNameKey], inMemoryDatabasePath);

expect(
Expand Down
Loading