Skip to content

Commit

Permalink
add platform to stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor committed Jul 23, 2024
1 parent 7770462 commit 6467789
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dart/lib/src/sentry_stack_trace_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
28 changes: 27 additions & 1 deletion 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 Down Expand Up @@ -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');
});
});
}

Expand All @@ -266,8 +290,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

0 comments on commit 6467789

Please sign in to comment.