Skip to content
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

redact screenshots via view hierarchy #2361

Merged
merged 63 commits into from
Nov 24, 2024

Conversation

martinhaintz
Copy link
Contributor

@martinhaintz martinhaintz commented Oct 15, 2024

📜 Description

Switching to View Hierarchy for screenshot generation.

💡 Motivation and Context

close #1956

💚 How did you test it?

Example App and Unittests

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

  • Update the Docs

Copy link
Contributor

github-actions bot commented Oct 15, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 3fbe924

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 89.47368% with 8 lines in your changes missing coverage. Please review.

Project coverage is 92.09%. Comparing base (25fc225) to head (3fbe924).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
flutter/lib/src/screenshot/recorder.dart 64.70% 6 Missing ⚠️
...rc/event_processor/screenshot_event_processor.dart 92.85% 1 Missing ⚠️
flutter/lib/src/sentry_privacy_options.dart 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2361      +/-   ##
==========================================
+ Coverage   86.94%   92.09%   +5.14%     
==========================================
  Files         257       83     -174     
  Lines        9238     2871    -6367     
==========================================
- Hits         8032     2644    -5388     
+ Misses       1206      227     -979     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Contributor

github-actions bot commented Oct 16, 2024

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 445.36 ms 487.04 ms 41.68 ms
Size 6.49 MiB 7.56 MiB 1.07 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
d4120ac 373.14 ms 447.35 ms 74.21 ms
103eb14 405.50 ms 444.30 ms 38.80 ms
ad69abc 297.35 ms 385.89 ms 88.54 ms
72dfc83 298.62 ms 340.14 ms 41.52 ms
061fed2 434.11 ms 506.49 ms 72.38 ms
256df44 447.58 ms 485.84 ms 38.25 ms
30c1193 349.00 ms 438.20 ms 89.20 ms
408bdab 360.18 ms 434.92 ms 74.74 ms
cecd4ed 438.09 ms 490.12 ms 52.04 ms
09eab47 455.30 ms 478.46 ms 23.16 ms

App size

Revision Plain With Sentry Diff
d4120ac 6.27 MiB 7.20 MiB 960.42 KiB
103eb14 6.52 MiB 7.59 MiB 1.06 MiB
ad69abc 6.06 MiB 7.09 MiB 1.03 MiB
72dfc83 5.94 MiB 6.92 MiB 1001.71 KiB
061fed2 6.52 MiB 7.59 MiB 1.06 MiB
256df44 6.52 MiB 7.59 MiB 1.06 MiB
30c1193 6.27 MiB 7.20 MiB 958.74 KiB
408bdab 6.27 MiB 7.20 MiB 959.07 KiB
cecd4ed 6.49 MiB 7.57 MiB 1.08 MiB
09eab47 6.49 MiB 7.56 MiB 1.07 MiB

Previous results on branch: feat/redact-screenshots-via-view-hierarchy

Startup times

Revision Plain With Sentry Diff
198d1a3 478.64 ms 529.65 ms 51.01 ms
cc1d836 506.06 ms 517.21 ms 11.15 ms
42be7f3 351.20 ms 372.54 ms 21.34 ms
606454f 473.23 ms 532.88 ms 59.65 ms
22f22b0 468.33 ms 511.96 ms 43.63 ms
57a0823 485.63 ms 526.69 ms 41.06 ms
823598a 468.91 ms 496.46 ms 27.55 ms
8202004 464.45 ms 512.12 ms 47.67 ms
3606202 672.45 ms 690.24 ms 17.80 ms
73a4224 510.66 ms 563.88 ms 53.22 ms

App size

Revision Plain With Sentry Diff
198d1a3 6.49 MiB 7.56 MiB 1.07 MiB
cc1d836 6.49 MiB 7.56 MiB 1.07 MiB
42be7f3 6.49 MiB 7.57 MiB 1.08 MiB
606454f 6.49 MiB 7.56 MiB 1.07 MiB
22f22b0 6.49 MiB 7.57 MiB 1.08 MiB
57a0823 6.49 MiB 7.57 MiB 1.08 MiB
823598a 6.49 MiB 7.56 MiB 1.07 MiB
8202004 6.49 MiB 7.56 MiB 1.07 MiB
3606202 6.49 MiB 7.57 MiB 1.08 MiB
73a4224 6.49 MiB 7.57 MiB 1.08 MiB

Copy link
Contributor

github-actions bot commented Oct 16, 2024

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1241.61 ms 1252.35 ms 10.74 ms
Size 8.38 MiB 9.78 MiB 1.40 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
a49594a 1284.83 ms 1313.29 ms 28.45 ms
f2db4ec 1244.14 ms 1259.79 ms 15.65 ms
117d988 1200.83 ms 1223.24 ms 22.41 ms
613760b 1263.10 ms 1277.27 ms 14.16 ms
48adddf 1255.76 ms 1280.31 ms 24.55 ms
09c1f55 1258.11 ms 1280.45 ms 22.34 ms
3a69405 1292.84 ms 1303.96 ms 11.12 ms
0a23f98 1252.98 ms 1276.76 ms 23.78 ms
3e33891 6245.86 ms 6260.90 ms 15.04 ms
e8603bb 1240.85 ms 1254.79 ms 13.94 ms

App size

Revision Plain With Sentry Diff
a49594a 8.16 MiB 9.16 MiB 1.00 MiB
f2db4ec 8.10 MiB 9.16 MiB 1.07 MiB
117d988 8.32 MiB 9.38 MiB 1.05 MiB
613760b 8.15 MiB 9.13 MiB 1000.46 KiB
48adddf 8.28 MiB 9.34 MiB 1.06 MiB
09c1f55 8.38 MiB 9.74 MiB 1.36 MiB
3a69405 8.15 MiB 9.15 MiB 1018.56 KiB
0a23f98 8.10 MiB 9.18 MiB 1.08 MiB
3e33891 8.29 MiB 9.38 MiB 1.09 MiB
e8603bb 8.33 MiB 9.40 MiB 1.07 MiB

Previous results on branch: feat/redact-screenshots-via-view-hierarchy

Startup times

Revision Plain With Sentry Diff
981039c 1231.98 ms 1243.80 ms 11.82 ms
22f22b0 1248.92 ms 1274.13 ms 25.21 ms
35ebb0b 1230.51 ms 1247.45 ms 16.94 ms
8202004 1244.20 ms 1249.82 ms 5.61 ms
d6212ac 1248.63 ms 1267.72 ms 19.08 ms
3606202 1257.33 ms 1284.26 ms 26.93 ms
823598a 1251.18 ms 1275.98 ms 24.80 ms
198d1a3 1244.67 ms 1259.96 ms 15.28 ms
57a0823 1239.41 ms 1267.28 ms 27.87 ms
73a4224 1240.18 ms 1266.15 ms 25.96 ms

App size

Revision Plain With Sentry Diff
981039c 8.38 MiB 9.75 MiB 1.37 MiB
22f22b0 8.38 MiB 9.75 MiB 1.37 MiB
35ebb0b 8.38 MiB 9.75 MiB 1.37 MiB
8202004 8.38 MiB 9.77 MiB 1.39 MiB
d6212ac 8.38 MiB 9.77 MiB 1.39 MiB
3606202 8.38 MiB 9.75 MiB 1.37 MiB
823598a 8.38 MiB 9.77 MiB 1.39 MiB
198d1a3 8.38 MiB 9.77 MiB 1.39 MiB
57a0823 8.38 MiB 9.75 MiB 1.37 MiB
73a4224 8.38 MiB 9.75 MiB 1.37 MiB

@martinhaintz martinhaintz requested a review from vaind October 16, 2024 14:52
@martinhaintz
Copy link
Contributor Author

martinhaintz commented Oct 16, 2024

@vaind @buenaflor I moved the redacting features from the SR(Screen Replay) config to the SS(ScreenShot) config and derived from it. I also copied the options from SR for the SS functionality.

  • Should we keep the settings separate, so the user can enable redacting for SR but disable it for SS?

  • Why is the SR feature experimental? Should the redacting settings for SS also stay experimental?

@vaind
Copy link
Collaborator

vaind commented Oct 17, 2024

Why is the SR feature experimental? Should the redacting settings for SS also stay experimental?

There still may be changes to replay as well as the redaction logic, therefore I'd say it should be marked experimental for screenshot redaction too. The main purpose is that it lets users know they should use this feature with care as it may have some issues. Also it may change without a major release.

Copy link
Collaborator

@vaind vaind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is still a draft but wanted to have a first look early. Looks like you're on a good path to integrating these two features, I've just had some comments what could possibly be improved.

flutter/lib/src/screenshot/recorder.dart Outdated Show resolved Hide resolved
flutter/lib/src/screenshot/sentry_screenshot_quality.dart Outdated Show resolved Hide resolved
flutter/lib/src/screenshot/recorder.dart Outdated Show resolved Hide resolved
flutter/lib/src/sentry_replay_options.dart Show resolved Hide resolved
@martinhaintz martinhaintz marked this pull request as ready for review October 25, 2024 09:54
@getsentry getsentry deleted a comment from github-actions bot Nov 15, 2024
@getsentry getsentry deleted a comment from github-actions bot Nov 15, 2024
@getsentry getsentry deleted a comment from github-actions bot Nov 15, 2024
@getsentry getsentry deleted a comment from github-actions bot Nov 15, 2024
@getsentry getsentry deleted a comment from github-actions bot Nov 15, 2024
@martinhaintz
Copy link
Contributor Author

martinhaintz commented Nov 15, 2024

@buenaflor @vaind In screenshot_event_processor.dart the beforeScreenshot callback is executed first and afterwards it will check if the screenshot functionality is available for this renderer. Is this a bug or is this the expected behaviour?

IMHO I would assume, that the beforeScreenshotis not called, if the screenshot feature itself is not available for the platform. Therefore I would move the platform check before the callback handling.

    final beforeScreenshot = _options.screenshot.beforeCapture;
    if (beforeScreenshot != null) {
      try {
        final result = beforeScreenshot(event, hint: hint);
        bool takeScreenshot;
        if (result is Future<bool>) {
          takeScreenshot = await result;
        } else {
          takeScreenshot = result;
        }
        if (!takeScreenshot) {
          return event;
        }
      } catch (exception, stackTrace) {
        _options.logger(
          SentryLevel.error,
          'The beforeScreenshot callback threw an exception',
          exception: exception,
          stackTrace: stackTrace,
        );
        if (_options.automatedTestMode) {
          rethrow;
        }
      }
    }

    final renderer = _options.rendererWrapper.getRenderer();

    if (_options.platformChecker.isWeb &&
        renderer != FlutterRenderer.canvasKit) {
      _options.logger(
        SentryLevel.debug,
        'Cannot take screenshot with ${renderer?.name} renderer.',
      );
      return event;
    }

Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • flutter/lib/src/screenshot/recorder.dart
  • flutter/lib/src/screenshot/widget_filter.dart

@getsentry getsentry deleted a comment from github-actions bot Nov 15, 2024
@martinhaintz
Copy link
Contributor Author

@vaind I reverted the changes regarding the html renderer, went through all files changed in this PR and tested it on the android emulator on Pixel 7 Pro API 35 for quality low, high and full, with and without redaction and the screenshot size and the redaction looks good.

Let me know, if I can support you in testing.

Copy link
Collaborator

@vaind vaind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for all the changes.

@martinhaintz martinhaintz requested a review from romtsn November 18, 2024 08:12
Copy link
Contributor

@buenaflor buenaflor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one last comment

flutter/lib/src/sentry_flutter_options.dart Outdated Show resolved Hide resolved
@martinhaintz
Copy link
Contributor Author

I will now start to update the docs, based on the changes of this PR.

@vaind
Copy link
Collaborator

vaind commented Nov 20, 2024

I will now start to update the docs, based on the changes of this PR.

We should merge prior to docs changes as these should normally come live only when a release is being made

@martinhaintz martinhaintz merged commit 4c13d97 into main Nov 24, 2024
51 checks passed
@martinhaintz martinhaintz deleted the feat/redact-screenshots-via-view-hierarchy branch November 24, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redact Screenshots via View Hierarchy
4 participants