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

POC: Move package:web access to separate package #2110

Closed
wants to merge 9 commits into from

Conversation

denrase
Copy link
Collaborator

@denrase denrase commented Jun 18, 2024

📜 Description

  • Evaluate if we can move package:web access to it's own library

💡 Motivation and Context

Provide a path to support compilation via WASM without bumping Dart/Flutter SDKs in main sentry package

Relates to #2104

💚 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 18, 2024

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

- Move `package:web` access to separate package ([#2110](https://github.com/getsentry/sentry-dart/pull/2110))

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 bd8e02d


try {
final config = optionsConfiguration(sentryOptions);
if (config is Future) {
await config;
}
await _initDefaultValues(sentryOptions);
Copy link
Collaborator Author

@denrase denrase Jun 18, 2024

Choose a reason for hiding this comment

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

Changing this order probably breaks stuff in unpredictable ways...

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to change the ordering?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok nvm I understand.

We'll have to think further about this. Like you said this might break stuff / have side effects

Copy link
Contributor

@buenaflor buenaflor Jun 19, 2024

Choose a reason for hiding this comment

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

We can have a static setWindow() function which sets an internal window and then assign that to options when calling init.

Window _window = NoopWindow();
void setWindow(Window window) {
  if (!PlatformChecker().isWeb) {
    return;
  }
  _window = window;
}

// and then inside init()
final sentryOptions = options ?? SentryOptions();

options?.window = _window;

The user just needs to call the setWindow function before SentryFlutter.init if they wanna do wasm

Sentry.setWindow(...)
SentryFlutter.init(...)

at least that way we can keep the ordering. maybe there's better ways

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is still a breaking change, isn't it? As in, things that worked before for users won't work anymore unless they change their code.

Copy link
Contributor

@buenaflor buenaflor Jun 20, 2024

Choose a reason for hiding this comment

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

This is still a breaking change, isn't it? As in, things that worked before for users won't work anymore unless they change their code.

tbh I'm not sure, wasm compilation only works on the latest stable channel so they all have to upgrade flutter afaik and it's not working right now for them anyway.

non-wasm users won't have to care about this stuff

Copy link
Collaborator

Choose a reason for hiding this comment

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

What I meant is that it would be breaking for existing users targeting web? Or am I missing something.

Copy link

codecov bot commented Jun 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.25%. Comparing base (c3b8a98) to head (bd8e02d).
Report is 4 commits behind head on main.

Current head bd8e02d differs from pull request most recent head 5c0480b

Please upload reports for the commit 5c0480b to get more accurate results.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2110   +/-   ##
=======================================
  Coverage   95.25%   95.25%           
=======================================
  Files          54       54           
  Lines        1791     1791           
=======================================
  Hits         1706     1706           
  Misses         85       85           

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

Copy link
Contributor

github-actions bot commented Jun 18, 2024

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 373.73 ms 468.98 ms 95.25 ms
Size 6.35 MiB 7.34 MiB 1008.27 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
e893df5 310.60 ms 380.58 ms 69.98 ms
6aab859 306.27 ms 377.92 ms 71.65 ms
50bdfad 395.22 ms 461.21 ms 65.98 ms
5cc82a0 400.35 ms 474.52 ms 74.17 ms
0f067d3 359.56 ms 431.28 ms 71.72 ms
1a93825 347.31 ms 424.54 ms 77.23 ms
b8562d0 362.31 ms 437.27 ms 74.96 ms
3e5ee37 317.56 ms 366.84 ms 49.28 ms
3a69405 334.34 ms 369.19 ms 34.85 ms
379d7a8 327.10 ms 355.39 ms 28.29 ms

App size

Revision Plain With Sentry Diff
e893df5 6.06 MiB 7.09 MiB 1.03 MiB
6aab859 6.15 MiB 7.13 MiB 999.97 KiB
50bdfad 6.33 MiB 7.30 MiB 987.47 KiB
5cc82a0 6.34 MiB 7.28 MiB 966.66 KiB
0f067d3 6.33 MiB 7.30 MiB 992.08 KiB
1a93825 6.27 MiB 7.20 MiB 956.36 KiB
b8562d0 6.35 MiB 7.33 MiB 1005.53 KiB
3e5ee37 5.94 MiB 6.92 MiB 1001.19 KiB
3a69405 5.94 MiB 6.95 MiB 1.01 MiB
379d7a8 5.94 MiB 6.95 MiB 1.01 MiB

@denrase
Copy link
Collaborator Author

denrase commented Jun 18, 2024

@buenaflor This might just work, i build with WebAssembly and triggered an issue. Before, I set some sample values in the separate package.

Dummy values in package:

Bildschirmfoto 2024-06-18 um 17 56 34

Code

Removed all dependencies that hindered building for WebAssembly in the sample app. Removed a flutter event processor so that the web values would be taken as fallback.

flutter build web --wasm
flutter pub global activate dhttpd
cd build/web
dart pub global run dhttpd '--headers=Cross-Origin-Embedder-Policy=credentialless;Cross-Origin-Opener-Policy=same-origin'

Result

https://sentry-sdks.sentry.io/issues/5503776648/?project=5428562&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D&referrer=issue-stream&statsPeriod=1h&stream_index=0

Bildschirmfoto 2024-06-18 um 17 58 06

@buenaflor
Copy link
Contributor

did some quick tests and works well on dart 3.2.0 and flutter 16.0


// Get window from options or noop
Window createWindow(SentryOptions options) {
return options.window() ?? NoopWindow();
Copy link
Contributor

Choose a reason for hiding this comment

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

We create the versions.dart that contains the package version and name and add it to the options like here

since we don't use the options inside the sentry_web package, maybe we can set it here?

technically the user could provide their own Window implementation but I don't think it's likely that they do that


try {
final config = optionsConfiguration(sentryOptions);
if (config is Future) {
await config;
}
await _initDefaultValues(sentryOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok nvm I understand.

We'll have to think further about this. Like you said this might break stuff / have side effects


try {
final config = optionsConfiguration(sentryOptions);
if (config is Future) {
await config;
}
await _initDefaultValues(sentryOptions);
Copy link
Contributor

@buenaflor buenaflor Jun 19, 2024

Choose a reason for hiding this comment

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

We can have a static setWindow() function which sets an internal window and then assign that to options when calling init.

Window _window = NoopWindow();
void setWindow(Window window) {
  if (!PlatformChecker().isWeb) {
    return;
  }
  _window = window;
}

// and then inside init()
final sentryOptions = options ?? SentryOptions();

options?.window = _window;

The user just needs to call the setWindow function before SentryFlutter.init if they wanna do wasm

Sentry.setWindow(...)
SentryFlutter.init(...)

at least that way we can keep the ordering. maybe there's better ways

@vaind vaind closed this in #2113 Jun 25, 2024
@denrase denrase deleted the test/web-package-in-external-lib branch June 25, 2024 09:23
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.

3 participants