Skip to content

Commit f754e86

Browse files
authored
Clean up code (#1878)
* Code clean up * fix doc comments
1 parent af99cbd commit f754e86

10 files changed

+154
-132
lines changed

dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ EnricherEventProcessor enricherEventProcessor(SentryOptions options) {
77
return IoEnricherEventProcessor(options);
88
}
99

10-
/// Enriches [SentryEvents] with various kinds of information.
10+
/// Enriches [SentryEvent]s with various kinds of information.
1111
/// Uses Darts [Platform](https://api.dart.dev/stable/dart-io/Platform-class.html)
1212
/// class to read information.
1313
class IoEnricherEventProcessor implements EnricherEventProcessor {
14-
IoEnricherEventProcessor(
15-
this._options,
16-
);
14+
IoEnricherEventProcessor(this._options);
1715

1816
final SentryOptions _options;
1917

dart/lib/src/event_processor/enricher/web_enricher_event_processor.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {
5050

5151
final url = request?.url ?? _window.location.toString();
5252
return (request ?? SentryRequest(url: url))
53-
.copyWith(
54-
headers: header,
55-
)
53+
.copyWith(headers: header)
5654
.sanitized();
5755
}
5856

dart/lib/src/hint.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'sentry_attachment/sentry_attachment.dart';
2+
import 'sentry_options.dart';
23

34
/// Hints are used in [BeforeSendCallback], [BeforeBreadcrumbCallback] and
45
/// event processors.

dart/lib/src/sentry_client.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import 'client_reports/client_report_recorder.dart';
2424
import 'client_reports/discard_reason.dart';
2525
import 'transport/data_category.dart';
2626

27-
/// Default value for [User.ipAddress]. It gets set when an event does not have
27+
/// Default value for [SentryUser.ipAddress]. It gets set when an event does not have
2828
/// a user and IP address. Only applies if [SentryOptions.sendDefaultPii] is set
2929
/// to true.
3030
const _defaultIpAddress = '{{auto}}';

dart/lib/src/sentry_stack_trace_factory.dart

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'noop_origin.dart' if (dart.library.html) 'origin.dart';
55
import 'protocol.dart';
66
import 'sentry_options.dart';
77

8-
/// converts [StackTrace] to [SentryStackFrames]
8+
/// converts [StackTrace] to [SentryStackFrame]s
99
class SentryStackTraceFactory {
1010
final SentryOptions _options;
1111

@@ -21,6 +21,10 @@ class SentryStackTraceFactory {
2121
'sentry_logging',
2222
'sentry_dio',
2323
'sentry_file',
24+
'sentry_hive',
25+
'sentry_isar',
26+
'sentry_sqflite',
27+
'sentry_drift',
2428
];
2529

2630
SentryStackTraceFactory(this._options);
@@ -123,16 +127,18 @@ class SentryStackTraceFactory {
123127
absPath: abs,
124128
function: member,
125129
// https://docs.sentry.io/development/sdk-dev/features/#in-app-frames
126-
inApp: isInApp(frame),
130+
inApp: _isInApp(frame),
127131
fileName: fileName,
128132
package: frame.package,
129133
);
130134

131-
if (frame.line != null && frame.line! >= 0) {
135+
final line = frame.line;
136+
if (line != null && line >= 0) {
132137
sentryStackFrame = sentryStackFrame.copyWith(lineNo: frame.line);
133138
}
134139

135-
if (frame.column != null && frame.column! >= 0) {
140+
final column = frame.column;
141+
if (column != null && column >= 0) {
136142
sentryStackFrame = sentryStackFrame.copyWith(colNo: frame.column);
137143
}
138144
return sentryStackFrame;
@@ -153,11 +159,11 @@ class SentryStackTraceFactory {
153159
return frame.uri.pathSegments.last;
154160
}
155161

156-
return '${frame.uri}';
162+
return frame.uri.toString();
157163
}
158164

159165
/// whether this frame comes from the app and not from Dart core or 3rd party librairies
160-
bool isInApp(Frame frame) {
166+
bool _isInApp(Frame frame) {
161167
final scheme = frame.uri.scheme;
162168

163169
if (scheme.isEmpty) {

dart/lib/src/sentry_tracer.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class SentryTracer extends ISentrySpan {
4949
/// highest timestamp of child spans, trimming the duration of the
5050
/// transaction. This is useful to discard extra time in the transaction that
5151
/// is not accounted for in child spans, like what happens in the
52-
/// [SentryNavigatorObserver] idle transactions, where we finish the
53-
/// transaction after a given "idle time" and we don't want this "idle time"
54-
/// to be part of the transaction.
52+
/// [SentryNavigatorObserver](https://pub.dev/documentation/sentry_flutter/latest/sentry_flutter/SentryNavigatorObserver-class.html)
53+
/// idle transactions, where we finish the transaction after a given
54+
/// "idle time" and we don't want this "idle time" to be part of the transaction.
5555
SentryTracer(
5656
SentryTransactionContext transactionContext,
5757
this._hub, {

flutter/example/lib/main.dart

+118-104
Original file line numberDiff line numberDiff line change
@@ -42,52 +42,58 @@ final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
4242

4343
Future<void> main() async {
4444
await setupSentry(
45-
() => runApp(
46-
SentryWidget(
47-
child: DefaultAssetBundle(
48-
bundle: SentryAssetBundle(),
49-
child: const MyApp(),
50-
),
51-
),
52-
),
53-
exampleDsn);
45+
() => runApp(
46+
SentryWidget(
47+
child: DefaultAssetBundle(
48+
bundle: SentryAssetBundle(),
49+
child: const MyApp(),
50+
),
51+
),
52+
),
53+
exampleDsn,
54+
);
5455
}
5556

56-
Future<void> setupSentry(AppRunner appRunner, String dsn,
57-
{bool isIntegrationTest = false,
58-
BeforeSendCallback? beforeSendCallback}) async {
59-
await SentryFlutter.init((options) {
60-
options.dsn = exampleDsn;
61-
options.tracesSampleRate = 1.0;
62-
options.profilesSampleRate = 1.0;
63-
options.reportPackages = false;
64-
options.addInAppInclude('sentry_flutter_example');
65-
options.considerInAppFramesByDefault = false;
66-
options.attachThreads = true;
67-
options.enableWindowMetricBreadcrumbs = true;
68-
options.addIntegration(LoggingIntegration(minEventLevel: Level.INFO));
69-
options.sendDefaultPii = true;
70-
options.reportSilentFlutterErrors = true;
71-
options.attachScreenshot = true;
72-
options.screenshotQuality = SentryScreenshotQuality.low;
73-
options.attachViewHierarchy = true;
74-
// We can enable Sentry debug logging during development. This is likely
75-
// going to log too much for your app, but can be useful when figuring out
76-
// configuration issues, e.g. finding out why your events are not uploaded.
77-
options.debug = true;
78-
79-
options.maxRequestBodySize = MaxRequestBodySize.always;
80-
options.maxResponseBodySize = MaxResponseBodySize.always;
81-
82-
_isIntegrationTest = isIntegrationTest;
83-
if (_isIntegrationTest) {
84-
options.dist = '1';
85-
options.environment = 'integration';
86-
options.beforeSend = beforeSendCallback;
87-
}
88-
},
89-
// Init your App.
90-
appRunner: appRunner);
57+
Future<void> setupSentry(
58+
AppRunner appRunner,
59+
String dsn, {
60+
bool isIntegrationTest = false,
61+
BeforeSendCallback? beforeSendCallback,
62+
}) async {
63+
await SentryFlutter.init(
64+
(options) {
65+
options.dsn = exampleDsn;
66+
options.tracesSampleRate = 1.0;
67+
options.profilesSampleRate = 1.0;
68+
options.reportPackages = false;
69+
options.addInAppInclude('sentry_flutter_example');
70+
options.considerInAppFramesByDefault = false;
71+
options.attachThreads = true;
72+
options.enableWindowMetricBreadcrumbs = true;
73+
options.addIntegration(LoggingIntegration(minEventLevel: Level.INFO));
74+
options.sendDefaultPii = true;
75+
options.reportSilentFlutterErrors = true;
76+
options.attachScreenshot = true;
77+
options.screenshotQuality = SentryScreenshotQuality.low;
78+
options.attachViewHierarchy = true;
79+
// We can enable Sentry debug logging during development. This is likely
80+
// going to log too much for your app, but can be useful when figuring out
81+
// configuration issues, e.g. finding out why your events are not uploaded.
82+
options.debug = true;
83+
84+
options.maxRequestBodySize = MaxRequestBodySize.always;
85+
options.maxResponseBodySize = MaxResponseBodySize.always;
86+
87+
_isIntegrationTest = isIntegrationTest;
88+
if (_isIntegrationTest) {
89+
options.dist = '1';
90+
options.environment = 'integration';
91+
options.beforeSend = beforeSendCallback;
92+
}
93+
},
94+
// Init your App.
95+
appRunner: appRunner,
96+
);
9197
}
9298

9399
class MyApp extends StatefulWidget {
@@ -123,22 +129,23 @@ class TooltipButton extends StatelessWidget {
123129
final String buttonTitle;
124130
final void Function()? onPressed;
125131

126-
const TooltipButton(
127-
{required this.onPressed,
128-
required this.buttonTitle,
129-
required this.text,
130-
Key? key})
131-
: super(key: key);
132+
const TooltipButton({
133+
required this.onPressed,
134+
required this.buttonTitle,
135+
required this.text,
136+
Key? key,
137+
}) : super(key: key);
132138

133139
@override
134140
Widget build(BuildContext context) {
135141
return Tooltip(
136-
message: text,
137-
child: ElevatedButton(
138-
onPressed: onPressed,
139-
key: key,
140-
child: Text(buttonTitle),
141-
));
142+
message: text,
143+
child: ElevatedButton(
144+
onPressed: onPressed,
145+
key: key,
146+
child: Text(buttonTitle),
147+
),
148+
);
142149
}
143150
}
144151

@@ -188,8 +195,9 @@ class MainScaffold extends StatelessWidget {
188195
const Padding(
189196
padding: EdgeInsets.all(15), //apply padding to all four sides
190197
child: Center(
191-
child: Text(
192-
'Long press a button to see more information. (hover on web)')),
198+
child: Text(
199+
'Long press a button to see more information. (hover on web)'),
200+
),
193201
),
194202
TooltipButton(
195203
onPressed: () => navigateToAutoCloseScreen(context),
@@ -301,20 +309,23 @@ class MainScaffold extends StatelessWidget {
301309
TooltipButton(
302310
onPressed: () {
303311
// modeled after a real exception
304-
FlutterError.onError?.call(FlutterErrorDetails(
305-
exception: Exception('A really bad exception'),
306-
silent: false,
307-
context: DiagnosticsNode.message('while handling a gesture'),
308-
library: 'gesture',
309-
informationCollector: () => [
310-
DiagnosticsNode.message(
311-
'Handler: "onTap" Recognizer: TapGestureRecognizer'),
312-
DiagnosticsNode.message(
313-
'Handler: "onTap" Recognizer: TapGestureRecognizer'),
314-
DiagnosticsNode.message(
315-
'Handler: "onTap" Recognizer: TapGestureRecognizer'),
316-
],
317-
));
312+
FlutterError.onError?.call(
313+
FlutterErrorDetails(
314+
exception: Exception('A really bad exception'),
315+
silent: false,
316+
context:
317+
DiagnosticsNode.message('while handling a gesture'),
318+
library: 'gesture',
319+
informationCollector: () => [
320+
DiagnosticsNode.message(
321+
'Handler: "onTap" Recognizer: TapGestureRecognizer'),
322+
DiagnosticsNode.message(
323+
'Handler: "onTap" Recognizer: TapGestureRecognizer'),
324+
DiagnosticsNode.message(
325+
'Handler: "onTap" Recognizer: TapGestureRecognizer'),
326+
],
327+
),
328+
);
318329
},
319330
text:
320331
'Creates a FlutterError and passes it to FlutterError.onError callback. This demonstrates how our flutter error integration catches unhandled exceptions.',
@@ -449,27 +460,28 @@ class MainScaffold extends StatelessWidget {
449460
),
450461
TooltipButton(
451462
onPressed: () {
452-
feedback.BetterFeedback.of(context)
453-
.show((feedback.UserFeedback feedback) {
454-
Sentry.captureMessage(
455-
feedback.text,
456-
withScope: (scope) {
457-
final entries = feedback.extra?.entries;
458-
if (entries != null) {
459-
for (final extra in entries) {
460-
scope.setExtra(extra.key, extra.value);
463+
feedback.BetterFeedback.of(context).show(
464+
(feedback.UserFeedback feedback) {
465+
Sentry.captureMessage(
466+
feedback.text,
467+
withScope: (scope) {
468+
final entries = feedback.extra?.entries;
469+
if (entries != null) {
470+
for (final extra in entries) {
471+
scope.setExtra(extra.key, extra.value);
472+
}
461473
}
462-
}
463-
scope.addAttachment(
464-
SentryAttachment.fromUint8List(
465-
feedback.screenshot,
466-
'feedback.png',
467-
contentType: 'image/png',
468-
),
469-
);
470-
},
471-
);
472-
});
474+
scope.addAttachment(
475+
SentryAttachment.fromUint8List(
476+
feedback.screenshot,
477+
'feedback.png',
478+
contentType: 'image/png',
479+
),
480+
);
481+
},
482+
);
483+
},
484+
);
473485
},
474486
text:
475487
'Sends the capture message with an image attachment to Sentry.',
@@ -754,18 +766,20 @@ class _IntegrationTestWidgetState extends State<IntegrationTestWidget> {
754766

755767
@override
756768
Widget build(BuildContext context) {
757-
return Column(children: [
758-
Text(
759-
_output,
760-
key: const Key('output'),
761-
),
762-
_isLoading
763-
? const CircularProgressIndicator()
764-
: ElevatedButton(
765-
onPressed: () async => await _captureException(),
766-
child: const Text('captureException'),
767-
)
768-
]);
769+
return Column(
770+
children: [
771+
Text(
772+
_output,
773+
key: const Key('output'),
774+
),
775+
_isLoading
776+
? const CircularProgressIndicator()
777+
: ElevatedButton(
778+
onPressed: () async => await _captureException(),
779+
child: const Text('captureException'),
780+
)
781+
],
782+
);
769783
}
770784

771785
Future<void> _captureException() async {

flutter/lib/src/integrations/screenshot_integration.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import 'package:sentry/sentry.dart';
22
import '../event_processor/screenshot_event_processor.dart';
33
import '../sentry_flutter_options.dart';
44

5-
/// Adds [ScreenshotEventProcessor] to options event processors if [attachScreenshot] is true
5+
/// Adds [ScreenshotEventProcessor] to options event processors if
6+
/// [SentryFlutterOptions.attachScreenshot] is true
67
class ScreenshotIntegration implements Integration<SentryFlutterOptions> {
78
SentryFlutterOptions? _options;
89
ScreenshotEventProcessor? _screenshotEventProcessor;

0 commit comments

Comments
 (0)