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

Improved handling of span status #3261

Merged
merged 2 commits into from
Jul 10, 2024
Merged

Conversation

antonpirker
Copy link
Member

Having the Sentry span statuses in a class and introducing get_span_status_from_http_code(). This will be used in our new OpenTelementry instrumentation.


General Notes

Thank you for contributing to sentry-python!

Please add tests to validate your changes, and lint your code using tox -e linters.

Running the test suite on your PR might require maintainer approval. Some tests (AWS Lambda) additionally require a maintainer to add a special label to run and will fail if the label is not present.

For maintainers

Sensitive test suites require maintainer review to ensure that tests do not compromise our secrets. This review must be repeated after any code revisions.

Before running sensitive test suites, please carefully check the PR. Then, apply the Trigger: tests using secrets label. The label will be removed after any code changes to enforce our policy requiring maintainers to review all code revisions before running sensitive tests.

@antonpirker antonpirker marked this pull request as ready for review July 9, 2024 13:37
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

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

Looks good, please consider suggestions before merging

@@ -386,6 +386,32 @@ class SPANDATA:
"""


class SPANSTATUS:
Copy link
Member

Choose a reason for hiding this comment

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

How about we make this an enum?

Comment on lines +164 to +188
elif 400 <= http_status_code < 500:
if http_status_code == 403:
return SPANSTATUS.PERMISSION_DENIED
elif http_status_code == 404:
return SPANSTATUS.NOT_FOUND
elif http_status_code == 429:
return SPANSTATUS.RESOURCE_EXHAUSTED
elif http_status_code == 413:
return SPANSTATUS.FAILED_PRECONDITION
elif http_status_code == 401:
return SPANSTATUS.UNAUTHENTICATED
elif http_status_code == 409:
return SPANSTATUS.ALREADY_EXISTS
else:
return SPANSTATUS.INVALID_ARGUMENT

elif 500 <= http_status_code < 600:
if http_status_code == 504:
return SPANSTATUS.DEADLINE_EXCEEDED
elif http_status_code == 501:
return SPANSTATUS.UNIMPLEMENTED
elif http_status_code == 503:
return SPANSTATUS.UNAVAILABLE
else:
return SPANSTATUS.INTERNAL_ERROR
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to sort the if statements in increasing order by status code. Although, perhaps this would better belong in a separate PR

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 87.87879% with 8 lines in your changes missing coverage. Please review.

Project coverage is 79.39%. Comparing base (ee84c81) to head (de40403).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3261      +/-   ##
==========================================
+ Coverage   79.36%   79.39%   +0.03%     
==========================================
  Files         132      132              
  Lines       14227    14247      +20     
  Branches     2987     2988       +1     
==========================================
+ Hits        11291    11312      +21     
  Misses       2092     2092              
+ Partials      844      843       -1     
Files Coverage Δ
sentry_sdk/consts.py 91.62% <100.00%> (+0.76%) ⬆️
sentry_sdk/integrations/aiohttp.py 79.64% <100.00%> (ø)
sentry_sdk/integrations/arq.py 86.29% <100.00%> (ø)
sentry_sdk/integrations/celery/__init__.py 87.01% <100.00%> (ø)
sentry_sdk/integrations/huey.py 91.66% <100.00%> (ø)
...y_sdk/integrations/opentelemetry/span_processor.py 76.52% <100.00%> (ø)
sentry_sdk/integrations/pymongo.py 84.03% <100.00%> (ø)
sentry_sdk/integrations/sqlalchemy.py 60.43% <100.00%> (ø)
sentry_sdk/tracing.py 73.66% <72.41%> (+0.11%) ⬆️

... and 3 files with indirect coverage changes

@antonpirker
Copy link
Member Author

Thanks for the quick review @szokeasaurusrex
I will keep it as is for now and just merge, do not want to change to much right now, we can always improve later.

@antonpirker antonpirker enabled auto-merge (squash) July 10, 2024 07:07
@antonpirker antonpirker merged commit b7fd54a into master Jul 10, 2024
122 checks passed
@antonpirker antonpirker deleted the antonpirker-status-codes branch July 10, 2024 07:17
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.

None yet

2 participants