Skip to content

Let SentryAsgiMiddleware work with Starlette and FastAPI integrations#1594

Merged
antonpirker merged 5 commits intomasterfrom
antonpirker/asgi-middleware-noop
Sep 1, 2022
Merged

Let SentryAsgiMiddleware work with Starlette and FastAPI integrations#1594
antonpirker merged 5 commits intomasterfrom
antonpirker/asgi-middleware-noop

Conversation

@antonpirker
Copy link
Copy Markdown
Contributor

@antonpirker antonpirker commented Sep 1, 2022

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

@antonpirker
Copy link
Copy Markdown
Contributor Author

Needs proper testing before we can release.

…multiple instances of this middleware are applied.
@antonpirker antonpirker marked this pull request as ready for review September 1, 2022 15:23
@antonpirker antonpirker merged commit d0b70df into master Sep 1, 2022
@antonpirker antonpirker deleted the antonpirker/asgi-middleware-noop branch September 1, 2022 15:50
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.

Minor update 1.9.6 introduces breaking change

2 participants