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

Set platform in sentry frames for better raw stacktrace representation #2193

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### 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
- Support `ignoredExceptionsForType` ([#2150](https://github.com/getsentry/sentry-dart/pull/2150))
- Filter out exception types by calling `SentryOptions.addExceptionFilterForType(Type exceptionType)`

Expand Down
2 changes: 2 additions & 0 deletions dart/lib/src/sentry_stack_trace_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean we aren't going to see the Dart stack traces coming from the web platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just about the raw formatting, you will still be able to see everything as before

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before it wasn't showing proper Dart-formatted stack traces on any platform.

Need to be able to see the dart stacktraces on desktop, mobile and web targets.

Also, this seem to be SDK change? The correct stack traces won't be shown on Sentry's web UI until the apps are updated and new errors/stacktraces are pushed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comment here about what we can do if you want it to work on existing issues:

#2040 (comment)

let's continue the discussion over there

final fileName =
frame.uri.pathSegments.isNotEmpty ? frame.uri.pathSegments.last : null;
final abs = '$eventOrigin${_absolutePathForCrashReport(frame)}';
Expand All @@ -114,6 +115,7 @@ class SentryStackTraceFactory {
inApp: _isInApp(frame),
fileName: fileName,
package: frame.package,
platform: platform,
);

final line = frame.line;
Expand Down
52 changes: 43 additions & 9 deletions dart/test/stack_trace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand All @@ -23,7 +24,8 @@ void main() {
'lineno': 1,
'colno': 2,
'in_app': false,
'filename': 'core'
'filename': 'core',
'platform': 'dart',
},
);
});
Expand Down Expand Up @@ -123,15 +125,17 @@ void main() {
'lineno': 46,
'colno': 9,
'in_app': true,
'filename': 'test.dart'
'filename': 'test.dart',
'platform': 'dart',
},
{
'abs_path': '${eventOrigin}test.dart',
'function': 'baz',
'lineno': 50,
'colno': 3,
'in_app': true,
'filename': 'test.dart'
'filename': 'test.dart',
'platform': 'dart',
},
]);
});
Expand All @@ -152,7 +156,8 @@ void main() {
'lineno': 46,
'colno': 9,
'in_app': true,
'filename': 'test.dart'
'filename': 'test.dart',
'platform': 'dart',
},
{
'abs_path': '<asynchronous suspension>',
Expand All @@ -163,7 +168,8 @@ void main() {
'lineno': 50,
'colno': 3,
'in_app': true,
'filename': 'test.dart'
'filename': 'test.dart',
'platform': 'dart',
},
]);
});
Expand Down Expand Up @@ -229,22 +235,25 @@ 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',
'package': 'example',
'function': 'MainScaffold.build.<fn>',
'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',
}
]);
});
Expand All @@ -258,6 +267,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');
});
});
}

Expand All @@ -266,8 +298,10 @@ class Fixture {
List<String> inAppIncludes = const [],
List<String> 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;
Expand Down
10 changes: 9 additions & 1 deletion dart/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,15 @@ Future testCaptureException(
}
expect(
topFrame.keys,
<String>['filename', 'function', 'lineno', 'colno', 'abs_path', 'in_app'],
<String>[
'filename',
'function',
'lineno',
'colno',
'abs_path',
'in_app',
'platform'
],
);

if (isWeb) {
Expand Down
Loading