Skip to content

Commit 40e7bc6

Browse files
uemanbuenaflor
andauthored
Add module in SentryStackFrame (#2931)
* add module * formatting * changelog * fix test * only test for the module * make it optional * include more info in changelog * more tests * formatting --------- Co-authored-by: Giancarlo Buenaflor <[email protected]>
1 parent 9e18a68 commit 40e7bc6

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### Features
66

77
- Add `message` parameter to `captureException()` ([#2882](https://github.com/getsentry/sentry-dart/pull/2882))
8+
- Add module in SentryStackFrame ([#2931](https://github.com/getsentry/sentry-dart/pull/2931))
9+
- Set `SentryOptions.includeModuleInStackTrace = true` to enable this. This may change grouping of exceptions.
810

911
### Dependencies
1012

dart/lib/src/sentry_options.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@ class SentryOptions {
543543
/// Disabled by default.
544544
bool enableLogs = false;
545545

546+
/// Enables adding the module in [SentryStackFrame.module].
547+
/// This option only has an effect in non-obfuscated builds.
548+
/// Enabling this option may change grouping.
549+
bool includeModuleInStackTrace = false;
550+
546551
late final SentryLogger logger = SentryLogger(clock);
547552

548553
@internal

dart/lib/src/sentry_stack_trace_factory.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ class SentryStackTraceFactory {
131131
frame.uri.pathSegments.isNotEmpty ? frame.uri.pathSegments.last : null;
132132
final abs = '$eventOrigin${_absolutePathForCrashReport(frame)}';
133133

134+
final includeModule =
135+
frame.package != null && _options.includeModuleInStackTrace;
136+
134137
var sentryStackFrame = SentryStackFrame(
135138
absPath: abs,
136139
function: member,
@@ -139,6 +142,11 @@ class SentryStackTraceFactory {
139142
fileName: fileName,
140143
package: frame.package,
141144
platform: platform,
145+
module: includeModule
146+
? frame.uri.pathSegments
147+
.sublist(0, frame.uri.pathSegments.length - 1)
148+
.join('/')
149+
: null,
142150
);
143151

144152
final line = frame.line;

dart/test/stack_trace_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,40 @@ void main() {
106106

107107
expect(serializedFrame.inApp, false);
108108
});
109+
110+
test('adds module for package frames', () {
111+
final frame = Frame(
112+
Uri.parse(
113+
'package:app_name/features/login/ui/view_model/login_view_model.dart'),
114+
1,
115+
2,
116+
'buzz',
117+
);
118+
119+
final sentryStackFrame = Fixture()
120+
.getSut(includeModuleInStackTrace: true)
121+
.encodeStackTraceFrame(frame)!;
122+
123+
expect(sentryStackFrame.module, 'app_name/features/login/ui/view_model');
124+
});
125+
126+
test(
127+
'does not add module for package frames when includeModuleInStackTrace is false',
128+
() {
129+
final frame = Frame(
130+
Uri.parse(
131+
'package:app_name/features/login/ui/view_model/login_view_model.dart'),
132+
1,
133+
2,
134+
'buzz',
135+
);
136+
137+
final sentryStackFrame = Fixture()
138+
.getSut(includeModuleInStackTrace: false)
139+
.encodeStackTraceFrame(frame)!;
140+
141+
expect(sentryStackFrame.module, null);
142+
});
109143
});
110144

111145
group('encodeStackTrace', () {
@@ -306,10 +340,12 @@ class Fixture {
306340
List<String> inAppIncludes = const [],
307341
List<String> inAppExcludes = const [],
308342
bool considerInAppFramesByDefault = true,
343+
bool includeModuleInStackTrace = false,
309344
}) {
310345
inAppIncludes.forEach(options.addInAppInclude);
311346
inAppExcludes.forEach(options.addInAppExclude);
312347
options.considerInAppFramesByDefault = considerInAppFramesByDefault;
348+
options.includeModuleInStackTrace = includeModuleInStackTrace;
313349

314350
return SentryStackTraceFactory(options);
315351
}

0 commit comments

Comments
 (0)