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

Support Starlette/FastAPI app.host #4157

Merged
merged 2 commits into from
Mar 18, 2025
Merged

Conversation

sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Mar 18, 2025

In Starlette/FastAPI you're able to create subapps. When using transaction_style="url" in our integration, this would throw an exception because we try to access route.path to determine the transaction name, but Host routes have no path attribute.

Closes #2631

Verified

This commit was signed with the committer’s verified signature.
sentrivana Ivana Kellyer

Verified

This commit was signed with the committer’s verified signature.
sentrivana Ivana Kellyer
@sentrivana sentrivana marked this pull request as ready for review March 18, 2025 13:29
Copy link

codecov bot commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.58%. Comparing base (5dcda1d) to head (312f857).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4157      +/-   ##
==========================================
+ Coverage   79.57%   79.58%   +0.01%     
==========================================
  Files         141      141              
  Lines       15711    15714       +3     
  Branches     2671     2671              
==========================================
+ Hits        12502    12506       +4     
  Misses       2367     2367              
+ Partials      842      841       -1     
Files with missing lines Coverage Δ
sentry_sdk/integrations/starlette.py 84.22% <100.00%> (+0.13%) ⬆️

... and 1 file with indirect coverage changes

return route.path
except AttributeError:
# routes added via app.host() won't have a path attribute
return scope.get("path")
Copy link
Member

Choose a reason for hiding this comment

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

[question] could we just use scope.get("path") in all cases, instead? Or, are there times where route.path is defined, but scope.get("path") is not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, so I'm opting for the least invasive approach that will only affect host routes to avoid potentially breaking existing functionality.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough – I suppose we could look into this as a future improvement but tbh it's probs not worth much effort

Copy link
Member

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

@sentrivana sentrivana merged commit e85715a into master Mar 18, 2025
140 checks passed
@sentrivana sentrivana deleted the ivana/support-starlette-host branch March 18, 2025 15:07
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.

Support hosted/mounted sub applications on FastAPI
3 participants