-
-
Notifications
You must be signed in to change notification settings - Fork 276
Support allowUrls, denyUrls #2227
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
Changes from all commits
47beb08
65c2868
92f02c3
11a06c5
934c9d0
24c48e9
e510129
5d62144
f623e07
40cadc9
2812a96
c0ffc67
5598f4c
8523a6d
a30a862
1ec7235
160ddcc
dc06ba9
e38e625
5e7ccc1
a4c0d59
102f0e5
e5a3315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import 'package:meta/meta.dart'; | ||
|
|
||
| @internal | ||
| bool isMatchingRegexPattern(String value, List<String> regexPattern, | ||
martinhaintz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {bool caseSensitive = false}) { | ||
| final combinedRegexPattern = regexPattern.join('|'); | ||
| final regExp = RegExp(combinedRegexPattern, caseSensitive: caseSensitive); | ||
| return regExp.hasMatch(value); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import 'package:sentry/src/utils/regex_utils.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| group('regex_utils', () { | ||
| final testString = "this is a test"; | ||
|
|
||
| test('testString contains string pattern', () { | ||
| expect(isMatchingRegexPattern(testString, ["is"]), isTrue); | ||
| }); | ||
|
|
||
| test('testString does not contain string pattern', () { | ||
| expect(isMatchingRegexPattern(testString, ["not"]), isFalse); | ||
| }); | ||
|
|
||
| test('testString contains regex pattern', () { | ||
| expect(isMatchingRegexPattern(testString, ["^this.*\$"]), isTrue); | ||
| }); | ||
|
|
||
| test('testString does not contain regex pattern', () { | ||
| expect(isMatchingRegexPattern(testString, ["^is.*\$"]), isFalse); | ||
| }); | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import 'dart:html' as html show window, Window; | ||
|
|
||
| import '../../../sentry_flutter.dart'; | ||
| import 'url_filter_event_processor.dart'; | ||
| // ignore: implementation_imports | ||
| import 'package:sentry/src/utils/regex_utils.dart'; | ||
|
|
||
| // ignore_for_file: invalid_use_of_internal_member | ||
|
|
||
| UrlFilterEventProcessor urlFilterEventProcessor(SentryFlutterOptions options) => | ||
| WebUrlFilterEventProcessor(options); | ||
|
|
||
| class WebUrlFilterEventProcessor implements UrlFilterEventProcessor { | ||
| WebUrlFilterEventProcessor( | ||
| this._options, | ||
| ); | ||
|
|
||
| final SentryFlutterOptions _options; | ||
|
|
||
| @override | ||
| SentryEvent? apply(SentryEvent event, Hint hint) { | ||
| final frames = _getStacktraceFrames(event); | ||
| final lastPath = frames?.first?.absPath; | ||
|
|
||
| if (lastPath == null) { | ||
| return event; | ||
| } | ||
|
Comment on lines
+23
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have you tried if this works with a release build? you'll also need the sentry_dart_plugin to upload source maps if you haven't |
||
|
|
||
| if (_options.allowUrls.isNotEmpty && | ||
| !isMatchingRegexPattern(lastPath, _options.allowUrls)) { | ||
| return null; | ||
| } | ||
|
|
||
| if (_options.denyUrls.isNotEmpty && | ||
| isMatchingRegexPattern(lastPath, _options.denyUrls)) { | ||
| return null; | ||
| } | ||
|
|
||
| return event; | ||
| } | ||
|
|
||
| Iterable<SentryStackFrame?>? _getStacktraceFrames(SentryEvent event) { | ||
| if (event.exceptions?.isNotEmpty == true) { | ||
| return event.exceptions?.first.stackTrace?.frames; | ||
| } | ||
| if (event.threads?.isNotEmpty == true) { | ||
| final stacktraces = event.threads?.map((e) => e.stacktrace); | ||
| return stacktraces | ||
| ?.where((element) => element != null) | ||
| .expand((element) => element!.frames); | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import '../../../sentry_flutter.dart'; | ||
| import 'url_filter_event_processor.dart'; | ||
|
|
||
| UrlFilterEventProcessor urlFilterEventProcessor(SentryFlutterOptions _) => | ||
| IoUrlFilterEventProcessor(); | ||
|
|
||
| class IoUrlFilterEventProcessor implements UrlFilterEventProcessor { | ||
| @override | ||
| SentryEvent apply(SentryEvent event, Hint hint) => event; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import '../../../sentry_flutter.dart'; | ||
| import 'io_url_filter_event_processor.dart' | ||
| if (dart.library.html) 'html_url_filter_event_processor.dart' | ||
| if (dart.library.js_interop) 'web_url_filter_event_processor.dart'; | ||
|
|
||
| abstract class UrlFilterEventProcessor implements EventProcessor { | ||
| factory UrlFilterEventProcessor(SentryFlutterOptions options) => | ||
| urlFilterEventProcessor(options); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // We would lose compatibility with old dart versions by adding web to pubspec. | ||
| // ignore: depend_on_referenced_packages | ||
| import 'package:web/web.dart' as web show window, Window; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we are accessing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd have expected CI to fail as it is. Actually, it seems like we don't run wasm tests on flutter test. Let me fix that: #2231 |
||
|
|
||
| import '../../../sentry_flutter.dart'; | ||
| import 'url_filter_event_processor.dart'; | ||
| // ignore: implementation_imports | ||
| import 'package:sentry/src/utils/regex_utils.dart'; | ||
|
|
||
| // ignore_for_file: invalid_use_of_internal_member | ||
|
|
||
| UrlFilterEventProcessor urlFilterEventProcessor(SentryFlutterOptions options) => | ||
| WebUrlFilterEventProcessor(options); | ||
|
|
||
| class WebUrlFilterEventProcessor implements UrlFilterEventProcessor { | ||
| WebUrlFilterEventProcessor( | ||
| this._options, | ||
| ); | ||
|
|
||
| final SentryFlutterOptions _options; | ||
|
|
||
| @override | ||
| SentryEvent? apply(SentryEvent event, Hint hint) { | ||
| final frames = _getStacktraceFrames(event); | ||
| final lastPath = frames?.first?.absPath; | ||
|
|
||
| if (lastPath == null) { | ||
| return event; | ||
| } | ||
|
|
||
| if (_options.allowUrls.isNotEmpty && | ||
| !isMatchingRegexPattern(lastPath, _options.allowUrls)) { | ||
| return null; | ||
| } | ||
|
|
||
| if (_options.denyUrls.isNotEmpty && | ||
| isMatchingRegexPattern(lastPath, _options.denyUrls)) { | ||
| return null; | ||
| } | ||
|
|
||
| return event; | ||
| } | ||
|
|
||
| Iterable<SentryStackFrame?>? _getStacktraceFrames(SentryEvent event) { | ||
| if (event.exceptions?.isNotEmpty == true) { | ||
| return event.exceptions?.first.stackTrace?.frames; | ||
| } | ||
| if (event.threads?.isNotEmpty == true) { | ||
| final stacktraces = event.threads?.map((e) => e.stacktrace); | ||
| return stacktraces | ||
| ?.where((element) => element != null) | ||
| .expand((element) => element!.frames); | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| @TestOn('vm') | ||
| library flutter_test; | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:sentry_flutter/sentry_flutter.dart'; | ||
| import 'package:sentry_flutter/src/event_processor/url_filter/url_filter_event_processor.dart'; | ||
|
|
||
| void main() { | ||
| group("ignore allowUrls and denyUrls for non Web", () { | ||
| late Fixture fixture; | ||
|
|
||
| setUp(() async { | ||
| fixture = Fixture(); | ||
| }); | ||
|
|
||
| test('returns the event and ignore allowUrls and denyUrls for non Web', | ||
| () async { | ||
| SentryEvent? event = SentryEvent( | ||
| request: SentryRequest( | ||
| url: 'another.url/for/a/special/test/testing/this-feature', | ||
| ), | ||
| ); | ||
| fixture.options.allowUrls = ["^this.is/.*\$"]; | ||
| fixture.options.denyUrls = ["special"]; | ||
|
|
||
| var eventProcessor = fixture.getSut(); | ||
| event = await eventProcessor.apply(event, Hint()); | ||
|
|
||
| expect(event, isNotNull); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| class Fixture { | ||
| SentryFlutterOptions options = SentryFlutterOptions(); | ||
| UrlFilterEventProcessor getSut() { | ||
| return UrlFilterEventProcessor(options); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.