-
-
Notifications
You must be signed in to change notification settings - Fork 277
feat: custom replay masking rules #2324
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
fa68455
refactor: change redaction logic to custom filters
vaind ec669f4
refactor widget filter to handle errors gracefully
vaind ad0f33c
cleanup
vaind 665d01d
add an option to disable masking asset images
vaind bd5d026
add new masking config class
vaind 37586fa
update widget filter to use the masking config
vaind 8135d28
cleanup
vaind f6fbf8a
Merge branch 'main' into feat/replay-custom-redact
vaind 90273fc
masking tests
vaind 1179d12
cleanup
vaind a72c3b1
test masking editable text
vaind c1495e0
Merge branch 'main' into feat/replay-custom-redact
vaind 8f3c849
fix tests on web
vaind cc5d71f
fix tests on web
vaind e877795
fix tests for wasm
vaind fa920ce
Merge branch 'main' into feat/replay-custom-redact
vaind 85a7fee
add SentryMask and SentryUnmask widgets
vaind 04805ce
Merge branch 'main' into feat/replay-custom-redact
vaind edaf732
linter issue
vaind 118398e
chore: changelog
vaind 3101e0a
rename to SentryMaskingDecision
vaind 1fe6f3f
mark new replay APIs as experimental
vaind d0c56a3
Merge branch 'main' into feat/replay-custom-redact
vaind 35495b2
Update flutter/lib/src/replay/masking_config.dart
vaind 534bbb4
Merge branch 'main' into feat/replay-custom-redact
vaind 4fa9a3d
chore: update changelog
vaind 64ee0f4
Merge branch 'main' into feat/replay-custom-redact
vaind 7739f6b
Merge branch 'main' into feat/replay-custom-redact
vaind be99d93
test: mask parent if masking the child fails
vaind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import 'package:flutter/widgets.dart'; | ||
| import 'package:meta/meta.dart'; | ||
|
|
||
| @internal | ||
| class SentryMaskingConfig { | ||
| @visibleForTesting | ||
| final List<SentryMaskingRule> rules; | ||
|
|
||
| final int length; | ||
|
|
||
| SentryMaskingConfig(List<SentryMaskingRule> rules) | ||
| // Note: fixed-size list has performance benefits over growable list. | ||
| : rules = List.of(rules, growable: false), | ||
| length = rules.length; | ||
|
|
||
| SentryMaskingDecision shouldMask<T extends Widget>( | ||
| Element element, T widget) { | ||
| for (int i = 0; i < length; i++) { | ||
| if (rules[i].appliesTo(widget)) { | ||
| // We use a switch here to get lints if more values are added. | ||
| switch (rules[i].shouldMask(element, widget)) { | ||
| case SentryMaskingDecision.mask: | ||
| return SentryMaskingDecision.mask; | ||
| case SentryMaskingDecision.unmask: | ||
| return SentryMaskingDecision.unmask; | ||
| case SentryMaskingDecision.continueProcessing: | ||
| // Continue to the next matching rule. | ||
| } | ||
| } | ||
| } | ||
| return SentryMaskingDecision.continueProcessing; | ||
| } | ||
| } | ||
|
|
||
| @experimental | ||
| enum SentryMaskingDecision { | ||
| /// Mask the widget and its children | ||
| mask, | ||
|
|
||
| /// Leave the widget visible, including its children (no more rules will | ||
| /// be checked for children). | ||
| unmask, | ||
|
|
||
| /// Don't make a decision - continue checking other rules and children. | ||
| continueProcessing | ||
| } | ||
|
|
||
| @internal | ||
| abstract class SentryMaskingRule<T extends Widget> { | ||
| @pragma('vm:prefer-inline') | ||
| bool appliesTo(Widget widget) => widget is T; | ||
vaind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| SentryMaskingDecision shouldMask(Element element, T widget); | ||
|
|
||
| const SentryMaskingRule(); | ||
| } | ||
|
|
||
| @internal | ||
| class SentryMaskingCustomRule<T extends Widget> extends SentryMaskingRule<T> { | ||
| final SentryMaskingDecision Function(Element element, T widget) callback; | ||
|
|
||
| const SentryMaskingCustomRule(this.callback); | ||
|
|
||
| @override | ||
| SentryMaskingDecision shouldMask(Element element, T widget) => | ||
| callback(element, widget); | ||
|
|
||
| @override | ||
| String toString() => '$SentryMaskingCustomRule<$T>($callback)'; | ||
| } | ||
|
|
||
| @internal | ||
| class SentryMaskingConstantRule<T extends Widget> extends SentryMaskingRule<T> { | ||
| final SentryMaskingDecision _value; | ||
| const SentryMaskingConstantRule(this._value); | ||
|
|
||
| @override | ||
| SentryMaskingDecision shouldMask(Element element, T widget) { | ||
| // This rule only makes sense with true/false. Continue won't do anything. | ||
| assert(_value == SentryMaskingDecision.mask || | ||
| _value == SentryMaskingDecision.unmask); | ||
| return _value; | ||
| } | ||
|
|
||
| @override | ||
| String toString() => | ||
| '$SentryMaskingConstantRule<$T>(${_value == SentryMaskingDecision.mask ? 'mask' : 'unmask'})'; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.