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

Set error status if http has exception and ok status. #1143

Merged
merged 6 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines +163 to +165
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
else if (status == SpanStatus.Ok)
{
transaction.Finish(exception);
// 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 && exception is not null)
{
transaction.Finish(exception);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doesn't the previous lines guarantee that you don't have a null exception?

                    if (exception is null)
                    {
                        transaction.Finish(status);
                    }
                    else if (status == SpanStatus.Ok)
                    {
                        transaction.Finish(exception);
                    }
                    else
                    {
                        transaction.Finish(exception, status);
                    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Slightly edited the test Transaction_binds_exception_thrown for checking if the Span was set as Internal Error.
Without the changes in this PR, the test was returning a span with the Status Ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah it already checks for null

Copy link
Member

Choose a reason for hiding this comment

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

OK, please add the comments

}
else
{
transaction.Finish(exception, status);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCOREAPP2_1
#if !NETCOREAPP2_1
Copy link
Member

Choose a reason for hiding this comment

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

BOM?

Copy link
Collaborator Author

@lucas-zimerman lucas-zimerman Jul 27, 2021

Choose a reason for hiding this comment

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

not sure what has changed, at least, vs code doesn't spot it https://github1s.com/getsentry/sentry-dotnet/pull/1143

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