|
| 1 | +// We would lose compatibility with old dart versions by adding web to pubspec. |
| 2 | +// ignore: depend_on_referenced_packages |
| 3 | +import 'package:web/web.dart' as web show window, Window; |
| 4 | + |
| 5 | +import '../../../sentry_flutter.dart'; |
| 6 | +import 'url_filter_event_processor.dart'; |
| 7 | +// ignore: implementation_imports |
| 8 | +import 'package:sentry/src/utils/regex_utils.dart'; |
| 9 | + |
| 10 | +// ignore_for_file: invalid_use_of_internal_member |
| 11 | + |
| 12 | +UrlFilterEventProcessor urlFilterEventProcessor(SentryFlutterOptions options) => |
| 13 | + WebUrlFilterEventProcessor(options); |
| 14 | + |
| 15 | +class WebUrlFilterEventProcessor implements UrlFilterEventProcessor { |
| 16 | + WebUrlFilterEventProcessor( |
| 17 | + this._options, |
| 18 | + ); |
| 19 | + |
| 20 | + final SentryFlutterOptions _options; |
| 21 | + |
| 22 | + @override |
| 23 | + SentryEvent? apply(SentryEvent event, Hint hint) { |
| 24 | + final frames = _getStacktraceFrames(event); |
| 25 | + final lastPath = frames?.first?.absPath; |
| 26 | + |
| 27 | + if (lastPath == null) { |
| 28 | + return event; |
| 29 | + } |
| 30 | + |
| 31 | + if (_options.allowUrls.isNotEmpty && |
| 32 | + !isMatchingRegexPattern(lastPath, _options.allowUrls)) { |
| 33 | + return null; |
| 34 | + } |
| 35 | + |
| 36 | + if (_options.denyUrls.isNotEmpty && |
| 37 | + isMatchingRegexPattern(lastPath, _options.denyUrls)) { |
| 38 | + return null; |
| 39 | + } |
| 40 | + |
| 41 | + return event; |
| 42 | + } |
| 43 | + |
| 44 | + Iterable<SentryStackFrame?>? _getStacktraceFrames(SentryEvent event) { |
| 45 | + if (event.exceptions?.isNotEmpty == true) { |
| 46 | + return event.exceptions?.first.stackTrace?.frames; |
| 47 | + } |
| 48 | + if (event.threads?.isNotEmpty == true) { |
| 49 | + final stacktraces = event.threads?.map((e) => e.stacktrace); |
| 50 | + return stacktraces |
| 51 | + ?.where((element) => element != null) |
| 52 | + .expand((element) => element!.frames); |
| 53 | + } |
| 54 | + return null; |
| 55 | + } |
| 56 | +} |
0 commit comments