From 64677890ca4722fa6fde38a3717745201da1e2e2 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 23 Jul 2024 14:47:40 +0200 Subject: [PATCH 1/5] add platform to stacktrace --- dart/lib/src/sentry_stack_trace_factory.dart | 6 +++++ dart/test/stack_trace_test.dart | 28 +++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/dart/lib/src/sentry_stack_trace_factory.dart b/dart/lib/src/sentry_stack_trace_factory.dart index 25a97e6eab..b17b785be1 100644 --- a/dart/lib/src/sentry_stack_trace_factory.dart +++ b/dart/lib/src/sentry_stack_trace_factory.dart @@ -125,6 +125,12 @@ class SentryStackTraceFactory { if (column != null && column >= 0) { sentryStackFrame = sentryStackFrame.copyWith(colNo: frame.column); } + + if (sentryStackFrame.platform == null) { + sentryStackFrame = sentryStackFrame.copyWith( + platform: sentryStackFrame.platform ?? + (_options.platformChecker.isWeb ? 'javascript' : 'dart')); + } return sentryStackFrame; } diff --git a/dart/test/stack_trace_test.dart b/dart/test/stack_trace_test.dart index 3ab8f9d116..89b1d32aaa 100644 --- a/dart/test/stack_trace_test.dart +++ b/dart/test/stack_trace_test.dart @@ -9,6 +9,7 @@ import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; import 'mocks.dart'; +import 'mocks/mock_platform_checker.dart'; void main() { group('encodeStackTraceFrame', () { @@ -258,6 +259,29 @@ isolate_instructions: 10fa27070, vm_instructions: 10fa21e20 .map((frame) => frame.toJson()); expect(frames.isEmpty, true); }); + + test('sets platform to javascript for web and dart for non-web', () { + final frame = Frame(Uri.parse('file://foo/bar/baz.dart'), 1, 2, 'buzz'); + final fixture = Fixture(); + + // Test for web platform + final webSut = fixture.getSut(isWeb: true); + var webFrame = webSut.encodeStackTraceFrame(frame)!; + expect(webFrame.platform, 'javascript'); + + // Test for non-web platform + final nativeFrameBeforeSut = fixture.getSut(isWeb: false); + var nativeFrameBefore = + nativeFrameBeforeSut.encodeStackTraceFrame(frame)!; + expect(nativeFrameBefore.platform, 'dart'); + + // Test when platform is already set + final frameWithPlatform = fixture + .getSut() + .encodeStackTraceFrame(frame)! + .copyWith(platform: 'native'); + expect(frameWithPlatform.platform, 'native'); + }); }); } @@ -266,8 +290,10 @@ class Fixture { List inAppIncludes = const [], List inAppExcludes = const [], bool considerInAppFramesByDefault = true, + bool isWeb = false, }) { - final options = SentryOptions(dsn: fakeDsn); + final options = SentryOptions( + dsn: fakeDsn, checker: MockPlatformChecker(isWebValue: isWeb)); inAppIncludes.forEach(options.addInAppInclude); inAppExcludes.forEach(options.addInAppExclude); options.considerInAppFramesByDefault = considerInAppFramesByDefault; From 5806d8275d7e0d6fb1434cba1c6cbe42d0754ce8 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Tue, 23 Jul 2024 14:55:06 +0200 Subject: [PATCH 2/5] update --- dart/lib/src/sentry_stack_trace_factory.dart | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dart/lib/src/sentry_stack_trace_factory.dart b/dart/lib/src/sentry_stack_trace_factory.dart index b17b785be1..7aab228a3e 100644 --- a/dart/lib/src/sentry_stack_trace_factory.dart +++ b/dart/lib/src/sentry_stack_trace_factory.dart @@ -103,6 +103,7 @@ class SentryStackTraceFactory { // least we get an indication something's wrong and are able to fix it. } + final platform = _options.platformChecker.isWeb ? 'javascript' : 'dart'; final fileName = frame.uri.pathSegments.isNotEmpty ? frame.uri.pathSegments.last : null; final abs = '$eventOrigin${_absolutePathForCrashReport(frame)}'; @@ -114,6 +115,7 @@ class SentryStackTraceFactory { inApp: _isInApp(frame), fileName: fileName, package: frame.package, + platform: platform, ); final line = frame.line; @@ -125,12 +127,6 @@ class SentryStackTraceFactory { if (column != null && column >= 0) { sentryStackFrame = sentryStackFrame.copyWith(colNo: frame.column); } - - if (sentryStackFrame.platform == null) { - sentryStackFrame = sentryStackFrame.copyWith( - platform: sentryStackFrame.platform ?? - (_options.platformChecker.isWeb ? 'javascript' : 'dart')); - } return sentryStackFrame; } From 0c77f6b19aa76ea95948e5ea263cdfe8265b1da1 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 24 Jul 2024 10:59:36 +0200 Subject: [PATCH 3/5] Update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e8f190369..aef9304f4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +### Features + +- Add dart platform to sentry frames ([#2193](https://github.com/getsentry/sentry-dart/pull/2193)) + - This allows viewing the correct dart formatted raw stacktrace in the Sentry UI + ### Fixes - Disable sff & frame delay detection on web, linux and windows ([#2182](https://github.com/getsentry/sentry-dart/pull/2182)) From 10ede79dc8617e7f43184900800d7a515d578741 Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 24 Jul 2024 11:12:04 +0200 Subject: [PATCH 4/5] Fix tests --- dart/test/stack_trace_test.dart | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/dart/test/stack_trace_test.dart b/dart/test/stack_trace_test.dart index 89b1d32aaa..3636d845a4 100644 --- a/dart/test/stack_trace_test.dart +++ b/dart/test/stack_trace_test.dart @@ -24,7 +24,8 @@ void main() { 'lineno': 1, 'colno': 2, 'in_app': false, - 'filename': 'core' + 'filename': 'core', + 'platform': 'dart', }, ); }); @@ -124,7 +125,8 @@ void main() { 'lineno': 46, 'colno': 9, 'in_app': true, - 'filename': 'test.dart' + 'filename': 'test.dart', + 'platform': 'dart', }, { 'abs_path': '${eventOrigin}test.dart', @@ -132,7 +134,8 @@ void main() { 'lineno': 50, 'colno': 3, 'in_app': true, - 'filename': 'test.dart' + 'filename': 'test.dart', + 'platform': 'dart', }, ]); }); @@ -153,7 +156,8 @@ void main() { 'lineno': 46, 'colno': 9, 'in_app': true, - 'filename': 'test.dart' + 'filename': 'test.dart', + 'platform': 'dart', }, { 'abs_path': '', @@ -164,7 +168,8 @@ void main() { 'lineno': 50, 'colno': 3, 'in_app': true, - 'filename': 'test.dart' + 'filename': 'test.dart', + 'platform': 'dart', }, ]); }); @@ -230,7 +235,8 @@ isolate_instructions: 10fa27070, vm_instructions: 10fa21e20 'function': 'PlatformDispatcher._dispatchPointerDataPacket', 'lineno': 341, 'abs_path': '${eventOrigin}dart:ui/platform_dispatcher.dart', - 'in_app': false + 'in_app': false, + 'platform': 'dart', }, { 'filename': 'main.dart', @@ -238,14 +244,16 @@ isolate_instructions: 10fa27070, vm_instructions: 10fa21e20 'function': 'MainScaffold.build.', 'lineno': 131, 'abs_path': '${eventOrigin}package:example/main.dart', - 'in_app': true + 'in_app': true, + 'platform': 'dart', }, { 'filename': 'main.dart', 'function': 'asyncThrows', 'lineno': 404, 'abs_path': '${eventOrigin}main.dart', - 'in_app': true + 'in_app': true, + 'platform': 'dart', } ]); }); From ab615e6fb30c04dcbd857287e55cb852ebc355cf Mon Sep 17 00:00:00 2001 From: GIancarlo Buenaflor Date: Wed, 24 Jul 2024 12:15:09 +0200 Subject: [PATCH 5/5] Fix test --- dart/test/test_utils.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dart/test/test_utils.dart b/dart/test/test_utils.dart index 87a0be0f0a..c7a0138a76 100644 --- a/dart/test/test_utils.dart +++ b/dart/test/test_utils.dart @@ -124,7 +124,15 @@ Future testCaptureException( } expect( topFrame.keys, - ['filename', 'function', 'lineno', 'colno', 'abs_path', 'in_app'], + [ + 'filename', + 'function', + 'lineno', + 'colno', + 'abs_path', + 'in_app', + 'platform' + ], ); if (isWeb) {