Repository navigation
test: pin the multiple-container behaviour behind Func<IHub> - #5646
Merged
Merged
Conversation
The hub is registered as Func<IHub> returning HubAdapter.Instance so that nothing captures a hub instance. That shape fixed #103 (ObjectDisposedException when a second container was built and disposed) but shipped without a regression test. Adds tests that fail if the registration is simplified to a singleton IHub: - a second service provider built and disposed after the app is running must not stop the middleware capturing unhandled exceptions - IHub/ISentryClient resolved from DI follow SentrySdk's current hub - disposing the container does not dispose the SDK's hub Closes #5645 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5646 +/- ##
==========================================
+ Coverage 74.37% 74.91% +0.54%
==========================================
Files 501 515 +14
Lines 18566 18975 +409
Branches 3603 3695 +92
==========================================
+ Hits 13808 14216 +408
+ Misses 3883 3878 -5
- Partials 875 881 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ric-oliv
approved these changes
Oct 1, 2026
ric-oliv
added a commit
that referenced
this pull request
Oct 5, 2026
Brings 6.12.0 and main's changes since 4af9645 into version7, including #5640, #5643, #5646, #5656, #5659, #5661, #5662 and #5667. Conflict resolutions: - Directory.Build.props: keep version7's 7.0.0 / prerelease. - LoggingBuilderExtensions.cs: keep version7's side. #5595 removed the generic AddSentry<TOptions> that #5640 changed; version7 fixes the same Blazor bug in AddSentryBlazor. - LoggingBuilderExtensionsTests.cs: drop #5640's two AddSentry_DerivedOptions_* tests (merged cleanly, don't compile on version7). - ServiceCollectionExtensions.cs: keep version7's side and move #5646's issue 103 comment to the registrations in AddSentryHub. - ServiceCollectionExtensionsTests.cs: keep version7's tests and port #5646's two tests to run on both version7 init paths: the host (AddSentry<TestHostOptions>(initializeSdk: true)) and SentrySdk.Init plus Logging.AddSentry(). - .github/workflows/build.yml: keep version7's .NET 11 integration-test steps with #5662's integration-test 3.4.1 pin and #5667's ubuntu-24.04 runners. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The hub is registered in DI as
Func<IHub>returning() => HubAdapter.Instance, so nothing ever holds a concrete hub. That shape fixed #103 in #157, but nothing in the suite pinned it. This adds regression tests that fail if the registration is "simplified" to a singletonIHub, plus a one-line pointer to #103 at the registration.Sentry.AspNetCore.Tests): with the test server running, a second provider is built from the same services, a hub is resolved from it, and the provider is disposed. An unhandled exception on/throwmust still reach the background worker throughSentryMiddleware.Sentry.Extensions.Logging.Tests):IHubandISentryClientare resolved, then the SDK's hub is swapped withSentrySdk.UseHub. Captures through both references must reach the new hub.Sentry.Extensions.Logging.Tests): after the provider is disposed,SentrySdkstill captures. The test also resolvesILoggerFactory, becauseSentryLoggerProvider.Disposedisposes the hub when it isIDisposable.Notes for review
IHubholding the initialized hub,Func<IHub>closing over it) and it passes, because the real container's hub simply replaces the throwaway's. The failure only shows when the second container is built after the real one:SentrySdk.UseHubdisposes the hub the real container is still holding. The test uses that order.ServiceDescriptor.Lifetime, since a singletonHubAdapterwould be harmless and a descriptor check would reject it.LoggingTestsin the same assembly initializes the SDK concurrently, so they run in a newSentrySdkCollectionwithDisableParallelization = true(same approach asProfilingTestCollection).#skip-changelog
Issues
Closes #5645
🤖 Generated with Claude Code