Skip to content

Conversation

@jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Nov 18, 2025

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.70%. Comparing base (9a61615) to head (f27fb1c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4747      +/-   ##
==========================================
+ Coverage   73.69%   73.70%   +0.01%     
==========================================
  Files         476      476              
  Lines       17443    17441       -2     
  Branches     3453     3452       -1     
==========================================
+ Hits        12854    12855       +1     
+ Misses       3741     3738       -3     
  Partials      848      848              

☔ 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.

@jamescrosswell jamescrosswell changed the title fix: tracing in ASP.NET Core in .NET 10 fix: Sentry Tracing middlewar crasher ASP.NET Core in .NET 10 in version 6.0.0-rc1 and earlier Nov 18, 2025
@jamescrosswell jamescrosswell marked this pull request as ready for review November 18, 2025 08:14
@jamescrosswell jamescrosswell changed the title fix: Sentry Tracing middlewar crasher ASP.NET Core in .NET 10 in version 6.0.0-rc1 and earlier fix: Sentry Tracing middleware crasher ASP.NET Core in .NET 10 in version 6.0.0-rc1 and earlier Nov 18, 2025
@jamescrosswell jamescrosswell changed the title fix: Sentry Tracing middleware crasher ASP.NET Core in .NET 10 in version 6.0.0-rc1 and earlier fix: Sentry Tracing middleware crashes ASP.NET Core in .NET 10 in version 6.0.0-rc1 and earlier Nov 18, 2025
@Flash0ver
Copy link
Member

@sentry review

Comment on lines 619 to 669
{
var sentryClient = Substitute.For<ISentryClient>();
var options = new SentryAspNetCoreOptions
{
Dsn = ValidDsn,
TracesSampleRate = 1,
AutoRegisterTracing = false
};

var hub = new Hub(options, sentryClient);

var server = new TestServer(new WebHostBuilder()
.UseSentry()
.ConfigureServices(services =>
{
services.RemoveAll(typeof(Func<IHub>));
services.AddSingleton<Func<IHub>>(() => hub);
services.AddRouting();
}).Configure(app =>
{
app.UseRouting();
app.UseSentryTracing();
app.UseEndpoints(routes =>
{
routes.Map("/", _ => Task.CompletedTask);
routes.Map("/crash", async _ =>
{
await Task.Yield();
throw new Exception();
});
});
}));

var client = server.CreateClient();

// Act
try
{
await client.GetStringAsync("/crash");
}
// Expected error.
catch
{
// ignored
}

// Assert
// Make sure Kestrel is still alive by making another request
var response = await client.GetAsync("/");
response.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
}
Copy link

Choose a reason for hiding this comment

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

This test validates that the server remains responsive after an exception, which is good. However, it lacks assertions to verify that the exception was properly recorded in Sentry and bound to the transaction. Consider adding assertions similar to the existing Transaction_binds_exception_thrown test to ensure that hub.ExceptionToSpanMap contains the exception and that the transaction was finished with an error status. This would provide more comprehensive validation of the exception handling flow.
Severity: MEDIUM

🤖 Prompt for AI Agent

Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs#L619-L669

Potential issue: This test validates that the server remains responsive after an
exception, which is good. However, it lacks assertions to verify that the exception was
properly recorded in Sentry and bound to the transaction. Consider adding assertions
similar to the existing `Transaction_binds_exception_thrown` test to ensure that
`hub.ExceptionToSpanMap` contains the exception and that the transaction was finished
with an error status. This would provide more comprehensive validation of the exception
handling flow.

Did we get this right? 👍 / 👎 to inform future reviews.

Reference_id: 2766746

Copy link
Member

@Flash0ver Flash0ver Nov 18, 2025

Choose a reason for hiding this comment

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

True.
When removing the re-throw entirely

// Rethrow immediately so as not to disrupt the .net 10 pipeline behaviour
// See: https://github.com/getsentry/sentry-dotnet/issues/4735
ExceptionDispatchInfo.Capture(e).Throw();

no test in SentryTracingMiddlewareTests fails.

However, other tests are failing

  • Sentry.AspNetCore.Tests.IntegrationsTests.CaptureException_UseExceptionHandler_SetRouteDataFromInitialRequest
  • Sentry.Google.Cloud.Functions.Tests.IntegrationTests.SentryIntegrationTest_CaptureUnhandledException

Is it worth adding an assertion to SentryTracingMiddlewareTests, too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not really the point of this fix. We could address it separately if we think we're lacking test coverage.

@Flash0ver Flash0ver merged commit 96d9d6c into main Nov 19, 2025
31 checks passed
@Flash0ver Flash0ver deleted the asp_net10_tracing branch November 19, 2025 15:40
@tincann
Copy link

tincann commented Nov 24, 2025

@Flash0ver Do you happen to know when this fix will be included in a release (or release candidate)? We’re currently blocked on our .NET 10 upgrade because of this crash, so any timing info would really help.

@jamescrosswell
Copy link
Collaborator Author

@Flash0ver Do you happen to know when this fix will be included in a release (or release candidate)? We’re currently blocked on our .NET 10 upgrade because of this crash, so any timing info would really help.

This was included in RC2, which just went out today:

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.

SentryTracing crashes ASP.NET web apps on .NET 10

5 participants