-
-
Notifications
You must be signed in to change notification settings - Fork 226
fix: Ensure profiling is disabled in Blazor WebAssembly #4507
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
804cd0f
1adda76
7347afa
3825367
6450f44
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| <ItemGroup> | ||||||||||||||||||||||||
| <ProjectReference Include="..\Sentry.Extensions.Logging\Sentry.Extensions.Logging.csproj" /> | ||||||||||||||||||||||||
| <ProjectReference Include="..\Sentry.Profiling\Sentry.Profiling.csproj" /> | ||||||||||||||||||||||||
|
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. thought: new dependency I'm a bit hesitant of adding this new dependency, as we might paint ourselves into a (potential) breaking change corner in the future: The other thought that I had is that adding this dependency is increasing the size of the consuming Application, which especially for WASM apps is a concern where bundle sizes and download speeds to the Browser are worth a consideration ... because now every WASM app will depend on 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 am wondering if there is another way to signal and/or force-disable Profiling for WASM-apps 🤔.
Hmmm ... perhaps there is another, more elegant solution. What do you think? 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. Great points Stefan, I'll go over some of the points that you made:
Yes, I was also hesitant to make this dependency, since we really only use
I think the MSBuild warning is an interesting idea, we already do have custom Targets in sentry-dotnet/src/Sentry.Profiling/buildTransitive/Sentry.Profiling.targets Lines 6 to 11 in 1a6d7e7
However, from a chat with @jamescrosswell, I learned that WASM doesn't really have a platform of it's own since it runs on the browser. So it will have to check for something entirely different, not platform. I will try to explore more about custom Targets and how we can possibly use them in this context.
Yes, this would definitely be a valid solution, and would keep the dependency away from the WASM project. I'll use this as a fallback in case I can't solve this problem with MSBuild solution that you mentioned. While I also do not particularly like the raw string check with types, I don't think there's a way around it, and it sounds like the lesser evil than creating another dependency. I'll definitely add tests around that if I do end up going down this route! 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. hmmm ... re checked grep.app ... the .NET Runtime has some usages If that works, it would be then a consistent solution with 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 just noticed this additional dependency when chatting with @Flash0ver last night... @alexsohn1126 I agree it's pretty weird to add a dependency on Profiling just to call a method that removes the profiling integration. This could potentially increase the size of our WASM integration (which would increase the size of the resulting WASM assemblies that our SDK users ship). I think we either find another way to detect whether someone has tried to enable profiling in WASM or we don't add this logic (we just leave it in the troubleshooting section of the docs instead). 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. Another option might be to find a way to do this differently (so that we don't need to have access to the sentry-dotnet/src/Sentry/SentryOptions.cs Lines 1342 to 1346 in eadf5f2
We could, for example, add an internal 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. From what I've tested so far, I did find out we can use I will make a change to the pull request whenever I can confirm that we can stop a user from building a wasm app with profiling. Though this would mean that they will be blocked from building the app which may not be the best experience. Then again, it makes sense to just not allow the user to use profiling in the first place if we don't support it 🤷♂️ If the method mentioned above doesn't work, what @jamescrosswell suggested looks pretty clean! |
||||||||||||||||||||||||
| <ProjectReference Include="..\Sentry\Sentry.csproj" /> | ||||||||||||||||||||||||
| </ItemGroup> | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| using Microsoft.Extensions.Logging; | ||
| using Sentry; | ||
| using Sentry.Extensibility; | ||
| using Sentry.Extensions.Logging; | ||
| using Sentry.Profiling; | ||
|
|
||
| // ReSharper disable once CheckNamespace - Discoverability | ||
| namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
|
|
@@ -28,10 +30,27 @@ public static WebAssemblyHostBuilder UseSentry(this WebAssemblyHostBuilder build | |
| blazorOptions.RequestBodyCompressionLevel = CompressionLevel.NoCompression; | ||
| // Since the WebAssemblyHost is a client-side application | ||
| blazorOptions.IsGlobalModeEnabled = true; | ||
| // If profiling enabled, disable it. | ||
| RemoveBlazorProfilingIntegration(blazorOptions); | ||
| }); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| private static void RemoveBlazorProfilingIntegration(SentryBlazorOptions options) | ||
| { | ||
| if (!options.IsProfilingEnabled) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| options.SetupLogging(); | ||
alexsohn1126 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| options.LogDebug("Detected Sentry profiling initialization in Blazor WebAssembly. " + | ||
|
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. question: level Since we are force-disabling an explicit opt-in from user code, I wonder if this may be of a higher Log-Level. Perhaps even Warning. 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 was thinking about putting this message under |
||
| "Sentry does not support Blazor WebAssembly profiling. Removing profiling integration. " + | ||
| "Check https://github.com/getsentry/sentry-dotnet/issues/4506 for more information."); | ||
| // Ensure project doesn't have Profiling Integration | ||
| options.RemoveIntegration<ProfilingIntegration>(); | ||
|
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. Nice - thanks @alexsohn1126 ! We could also add a unit test to |
||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: needs to be updated after publishing release