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

Conversation

lucas-zimerman
Copy link
Collaborator

InvokeAsync middleware doesn't receive the correct status code during an error, setting a transaction with an error as "OK", this PR sets the default status code based on the received Exception and if the status code is Ok.

Before
image

After
image

@Tyrrrz
Copy link
Contributor

Tyrrrz commented Jul 26, 2021

Does this happen because the status code is set after the middleware?

@lucas-zimerman
Copy link
Collaborator Author

Does this happen because the status code is set after the middleware?

yup

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

I think we need to check if we have an instance because passing null as exception could behave as unknown status or as ok or that can change in the future.

There are no tests for this so sounds like we can change this and nothing validates the change.

Comment on lines +160 to +162
else if (status == SpanStatus.Ok)
{
transaction.Finish(exception);
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

@codecov-commenter
Copy link

codecov-commenter commented Jul 26, 2021

Codecov Report

Merging #1143 (0ab7f56) into main (b08a831) will decrease coverage by 0.00%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1143      +/-   ##
==========================================
- Coverage   80.58%   80.57%   -0.01%     
==========================================
  Files         203      203              
  Lines        6675     6677       +2     
  Branches     1477     1478       +1     
==========================================
+ Hits         5379     5380       +1     
- Misses        816      817       +1     
  Partials      480      480              
Impacted Files Coverage Δ
src/Sentry.AspNetCore/SentryTracingMiddleware.cs 73.07% <50.00%> (-1.93%) ⬇️
src/Sentry/GlobalSessionManager.cs 71.20% <0.00%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b08a831...0ab7f56. Read the comment docs.

Comment on lines +160 to +162
else if (status == SpanStatus.Ok)
{
transaction.Finish(exception);
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

@@ -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

@bruno-garcia bruno-garcia enabled auto-merge (squash) July 27, 2021 19:40
@bruno-garcia bruno-garcia merged commit b551e59 into main Jul 27, 2021
@bruno-garcia bruno-garcia deleted the ref/internal-error-on-transaction-with-exception branch July 27, 2021 19:41
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.

4 participants