Skip to content

enh: use lifecycle hook for before send event #3017

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

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

buenaflor
Copy link
Contributor

@buenaflor buenaflor commented Jun 25, 2025

📜 Description

Now that we have sdk lifecycle hooks we can re-factor the beforeSendEvent observer that we added to implement web sessions

💡 Motivation and Context

💚 How did you test it?

📝 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

Copy link
Contributor

github-actions bot commented Jun 27, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- use lifecycle hook for before send event ([#3017](https://github.com/getsentry/sentry-dart/pull/3017))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 6eda8bd

Copy link

codecov bot commented Jun 27, 2025

Codecov Report

Attention: Patch coverage is 36.66667% with 19 lines in your changes missing coverage. Please review.

Project coverage is 87.87%. Comparing base (e2d675d) to head (6eda8bd).

Files with missing lines Patch % Lines
dart/lib/src/sentry_client.dart 37.50% 5 Missing ⚠️
dart/lib/src/hub.dart 0.00% 4 Missing ⚠️
dart/lib/src/hub_adapter.dart 0.00% 4 Missing ⚠️
dart/lib/src/noop_hub.dart 0.00% 3 Missing ⚠️
.../lib/src/integrations/web_session_integration.dart 66.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3017      +/-   ##
==========================================
- Coverage   87.97%   87.87%   -0.11%     
==========================================
  Files         287      287              
  Lines        9534     9542       +8     
==========================================
- Hits         8388     8385       -3     
- Misses       1146     1157      +11     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

github-actions bot commented Jun 27, 2025

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1262.18 ms 1267.09 ms 4.90 ms
Size 7.86 MiB 9.44 MiB 1.58 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
e2d675d 1238.48 ms 1242.76 ms 4.28 ms
9b99523 1256.06 ms 1270.33 ms 14.27 ms
640ad0c 1241.04 ms 1253.96 ms 12.92 ms
c8596a6 1234.11 ms 1241.19 ms 7.08 ms
6ba4675 1223.12 ms 1238.17 ms 15.04 ms
827bf09 1261.86 ms 1276.41 ms 14.55 ms
73dca78 1246.65 ms 1265.42 ms 18.76 ms
b6c8720 1252.65 ms 1266.61 ms 13.96 ms
2d34233 1258.19 ms 1268.92 ms 10.73 ms
ec78888 1251.37 ms 1269.40 ms 18.04 ms

App size

Revision Plain With Sentry Diff
e2d675d 7.86 MiB 9.44 MiB 1.58 MiB
9b99523 7.86 MiB 9.44 MiB 1.58 MiB
640ad0c 7.86 MiB 9.44 MiB 1.58 MiB
c8596a6 7.86 MiB 9.44 MiB 1.58 MiB
6ba4675 7.86 MiB 9.44 MiB 1.58 MiB
827bf09 7.86 MiB 9.44 MiB 1.58 MiB
73dca78 7.86 MiB 9.44 MiB 1.58 MiB
b6c8720 7.86 MiB 9.44 MiB 1.58 MiB
2d34233 7.86 MiB 9.44 MiB 1.58 MiB
ec78888 7.86 MiB 9.44 MiB 1.58 MiB

Previous results on branch: enhancements/use-lifecycle-hook-before-send-event

Startup times

Revision Plain With Sentry Diff
4e720b9 1265.15 ms 1272.98 ms 7.83 ms
9d51684 1245.62 ms 1249.02 ms 3.40 ms
9e774c1 1263.31 ms 1280.24 ms 16.93 ms
e052838 1254.76 ms 1263.79 ms 9.04 ms

App size

Revision Plain With Sentry Diff
4e720b9 7.85 MiB 9.45 MiB 1.59 MiB
9d51684 7.85 MiB 9.45 MiB 1.59 MiB
9e774c1 7.86 MiB 9.44 MiB 1.58 MiB
e052838 7.85 MiB 9.45 MiB 1.59 MiB

Copy link
Contributor

github-actions bot commented Jun 27, 2025

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 487.57 ms 567.46 ms 79.89 ms
Size 6.54 MiB 7.69 MiB 1.15 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
93b7728 475.28 ms 489.13 ms 13.86 ms
ec78888 457.94 ms 519.96 ms 62.02 ms
827bf09 475.40 ms 547.14 ms 71.74 ms
73dca78 476.53 ms 522.21 ms 45.68 ms
640ad0c 466.00 ms 552.67 ms 86.67 ms
6ba4675 499.80 ms 632.43 ms 132.63 ms
b6c8720 457.41 ms 519.04 ms 61.63 ms
c8596a6 474.00 ms 492.96 ms 18.96 ms
2d34233 470.54 ms 558.90 ms 88.36 ms
e2d675d 457.92 ms 529.17 ms 71.25 ms

App size

Revision Plain With Sentry Diff
93b7728 6.54 MiB 7.69 MiB 1.15 MiB
ec78888 6.54 MiB 7.69 MiB 1.15 MiB
827bf09 6.54 MiB 7.53 MiB 1015.27 KiB
73dca78 6.54 MiB 7.69 MiB 1.15 MiB
640ad0c 6.54 MiB 7.69 MiB 1.15 MiB
6ba4675 6.54 MiB 7.53 MiB 1015.26 KiB
b6c8720 6.54 MiB 7.69 MiB 1.15 MiB
c8596a6 6.54 MiB 7.53 MiB 1015.27 KiB
2d34233 6.54 MiB 7.55 MiB 1.01 MiB
e2d675d 6.54 MiB 7.69 MiB 1.15 MiB

Previous results on branch: enhancements/use-lifecycle-hook-before-send-event

Startup times

Revision Plain With Sentry Diff
9d51684 517.34 ms 569.74 ms 52.40 ms
4e720b9 469.48 ms 517.15 ms 47.67 ms
e052838 457.27 ms 485.24 ms 27.97 ms
9e774c1 458.33 ms 486.46 ms 28.12 ms

App size

Revision Plain With Sentry Diff
9d51684 6.54 MiB 7.53 MiB 1017.60 KiB
4e720b9 6.54 MiB 7.53 MiB 1017.60 KiB
e052838 6.54 MiB 7.53 MiB 1017.60 KiB
9e774c1 6.54 MiB 7.69 MiB 1.15 MiB

@buenaflor
Copy link
Contributor Author

@denrase can you have a early look pls

Copy link
Collaborator

@denrase denrase left a comment

Choose a reason for hiding this comment

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

Approach looking good to me. 👍

  • Missing hint
  • Not sure if we should remove the methods from the options or just deprecate them.
  • CI complains about missing test coverage

@internal
void registerCallback<T extends SdkLifecycleEvent>(
SdkLifecycleCallback<T> callback) {
final item = _peek();
item.client.registerCallback<T>(callback);
}

@internal
void removeCallback<T extends SdkLifecycleEvent>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add a test if the warning is correct.

}

@internal
class OnBeforeSendEvent extends SdkLifecycleEvent {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The previous observer method also had the associated hint. We should add it as well.

@@ -29,7 +30,7 @@ import 'utils/regex_utils.dart';
import 'utils/stacktrace_utils.dart';
import 'sentry_log_batcher.dart';
import 'version.dart';
import 'lifecycle/on_before_capture_log.dart';
import 'sdk_lifecycle_hooks.dart';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicate import.

@buenaflor
Copy link
Contributor Author

Not sure if we should remove the methods from the options or just deprecate them.

we can remove them, they were never meant to be public

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.

2 participants