Let SentryAsgiMiddleware work with Starlette and FastAPI integrations#1594
Merged
antonpirker merged 5 commits intomasterfrom Sep 1, 2022
Merged
Let SentryAsgiMiddleware work with Starlette and FastAPI integrations#1594antonpirker merged 5 commits intomasterfrom
antonpirker merged 5 commits intomasterfrom
Conversation
Contributor
Author
|
Needs proper testing before we can release. |
…multiple instances of this middleware are applied.
747b883 to
4a6a8fd
Compare
…ry/sentry-python into antonpirker/asgi-middleware-noop
sl0thentr0py
reviewed
Sep 1, 2022
sl0thentr0py
approved these changes
Sep 1, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
People where complaining (rightly so) that just raising an error when SentryAsgiMiddleware and Starlette/Fastapi is used is not a nice thing to do.
So we tried again to make this work together. To not break our users code.
The plan was to make SentryASGIMiddleware no-op when there is already one there. Turns out this works already on Starlette but on FastAPI it broke. (This was because of how FastAPI deals with middlewares)
We debugged the whole thing and it turns out that we where patching our own SentryAsgiMiddleware (like the FastAPI internal ones) to create spans when they are executed. This and the fact that we use
__slots__extensively made the integration break.We found out, that if we are not patching our own middleware this fixes the problem when initializing the middleware twice (once by our users and once by our auto-enabled FastAPI integration).
This should fix #1592