Skip to content

fix(wsgi): WSGI integrations respect SCRIPT_NAME env variable#2622

Merged
szokeasaurusrex merged 2 commits into
getsentry:masterfrom
sarvaSanjay:script-name-wsgi-fix
Jul 15, 2024
Merged

fix(wsgi): WSGI integrations respect SCRIPT_NAME env variable#2622
szokeasaurusrex merged 2 commits into
getsentry:masterfrom
sarvaSanjay:script-name-wsgi-fix

Conversation

@sarvaSanjay

Copy link
Copy Markdown
Contributor

URLs generated using Sentry's WSGI Middleware should include SCRIPT_NAME in the event's url

Fixes #2576

Noticed that the problem described in the above issue wasn't specific to Django per se but general to all WSGI applications which is why I have made modifications to the SentryWsgiMiddleware class that should resolve this issue for Django and other integrations as well. As far as I can tell this problem should not arise for ASGI applications as the root_path is accounted for.

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.

@sarvaSanjay

Copy link
Copy Markdown
Contributor Author

Hey, its my first contribution. It seems as if we need to add a label to this PR for any of the checks to execute, could any of the collaborators add the same?

@szokeasaurusrex

Copy link
Copy Markdown
Member

Hey, its my first contribution. It seems as if we need to add a label to this PR for any of the checks to execute, could any of the collaborators add the same?

I have approved most of the tests to run. For now, the AWS permissions check will still fail – we will add the necessary label once we have reviewed and approved the change

@szokeasaurusrex szokeasaurusrex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the PR! It looks good, but I think we should make a couple of improvements before we merge. Please see my inline comments

Comment thread sentry_sdk/integrations/wsgi.py Outdated
Comment thread tests/integrations/wsgi/test_wsgi.py Outdated
(event,) = events

assert event["transaction"] == "generic WSGI request"
print(event["request"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
print(event["request"])

This print statement should probably be removed

Comment thread tests/integrations/wsgi/test_wsgi.py Outdated
Comment thread tests/integrations/wsgi/test_wsgi.py Outdated
@szokeasaurusrex

Copy link
Copy Markdown
Member

Also, please address the linter and test failures (except the AWS Lambda tests – you can ignore these for now); we can only merge the changes once all these tests pass

@codecov

codecov Bot commented Jun 27, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.27%. Comparing base (c210ad6) to head (6f07450).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2622      +/-   ##
==========================================
- Coverage   79.33%   79.27%   -0.06%     
==========================================
  Files         132      132              
  Lines       14218    14218              
  Branches     2985     2985              
==========================================
- Hits        11280    11272       -8     
- Misses       2093     2106      +13     
+ Partials      845      840       -5     
Files Coverage Δ
sentry_sdk/integrations/wsgi.py 83.21% <ø> (ø)

... and 4 files with indirect coverage changes

URLs generated using Sentry's WSGI Middleware should include SCRIPT_NAME in the event's url

Fixes getsentryGH-2576
@szokeasaurusrex
szokeasaurusrex merged commit 855c15f into getsentry:master Jul 15, 2024
arjennienhuis pushed a commit to arjennienhuis/sentry-python that referenced this pull request Sep 30, 2024
…try#2622)

URLs generated using Sentry's WSGI Middleware should include SCRIPT_NAME in the event's url

Fixes getsentry#2576

---------

Co-authored-by: Daniel Szoke <daniel.szoke@sentry.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Django integration does not respect SCRIPT_NAME

3 participants