Skip to content

Commit

Permalink
Set error status if http has exception and ok status. (#1143)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
  • Loading branch information
lucas-zimerman and bruno-garcia authored Jul 27, 2021
1 parent b08a831 commit b551e59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## Unreleased

## Fixes
### Fixes

- Set error status to transaction if http has exception and ok status ([#1143](https://github.com/getsentry/sentry-dotnet/pull/1143))
- Fix max breadcrumbs limit when MaxBreadcrumbs is zero or lower ([#1145](https://github.com/getsentry/sentry-dotnet/pull/1145))

## 3.8.3
Expand Down
9 changes: 8 additions & 1 deletion src/Sentry.AspNetCore/SentryTracingMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
Expand Down Expand Up @@ -157,6 +157,13 @@ public async Task InvokeAsync(HttpContext context)
{
transaction.Finish(status);
}
// Status code not yet changed to 500 but an exception does exist
// so lets avoid passing the misleading 200 down and close only with
// the exception instance that will be inferred as errored.
else if (status == SpanStatus.Ok)
{
transaction.Finish(exception);
}
else
{
transaction.Finish(exception, status);
Expand Down
5 changes: 3 additions & 2 deletions test/Sentry.AspNetCore.Tests/SentryTracingMiddlewareTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCOREAPP2_1
#if !NETCOREAPP2_1
using System;
using System.Collections.Generic;
using System.Net.Http;
Expand Down Expand Up @@ -338,7 +338,8 @@ public async Task Transaction_binds_exception_thrown()
await client.GetAsync("/person/13");

// Assert
Assert.True(hub.ExceptionToSpanMap.TryGetValue(exception, out _));
Assert.True(hub.ExceptionToSpanMap.TryGetValue(exception, out var span));
Assert.Equal(SpanStatus.InternalError, span.Status);
}
}
}
Expand Down

0 comments on commit b551e59

Please sign in to comment.