-
Notifications
You must be signed in to change notification settings - Fork 16
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
FastAPI support #251
Comments
Per @apotterri FastAPI is built on Starlette, HTTP framework that implements ASGI. The 'A' in ASGI stands for "Asynchronous", and there's no requirement that there be a single thread that processes an entire request. Adding support for it is almost certainly going to be more complicated than just hooking a couple of framework methods. |
@apotterri
Please let me know if you think this might work. I haven't had a chance to go through |
Another thing to note is, appmap still supports Python 3.7.2, but FastAPI requires >=3.8 |
@apotterri @kgilpin FastAPI supports middlewares, but injecting them like flask and django doesn't seem to be possible, SO FAR. Since FastAPI is run using uvicorn, there is no common fixed entry point inside Starlette or FastAPI. Need to explore if we can somehow inject directly inside uvicorn. Else, we can create middleware and would need the dev to do something like
https://semaphoreci.com/blog/custom-middleware-fastapi |
@virajkanwade welcome back, and thanks a lot for digging into this! I think it would be better to implement an ASGI middleware to manage request recording, rather than tying ourselves to FastAPI specifically. This would mean that we'd work with any ASGI server, and so also support all the frameworks that run on them. It might also mean that we won't be limited by FastAPI's 3.8 requirement (though that will depend on how we test the new middleware, I guess). Implementing the middleware itself should be pretty straightforward, as it will look a lot like Maybe somewhat trickier will be changing the way the current appmap-python/_appmap/utils.py Line 64 in 2c2025b
ContextVar instead of a threading.local will be sufficient, but I'm not 100% sure.
We should definitely see if we can hook something in uvicorn (and any other support we want to support) to inject the new middleware. The less the user has to do to get AppMaps, the better. |
@virajkanwade thanks for diving into this! FastAPI would be an awesome enhancement. |
@apotterri uvicorn injection
|
Nice! Thank for this. |
@apotterri hypercorn injection
This is slightly different from uvicorn since the Works with both |
@apotterri there seems to be weird issue with daphne and appmap-python. The startup log is not printed, but the daphne server works. Comment out this line https://github.com/getappmap/appmap-python/blob/master/_appmap/env.py#L168 and it starts printing the startup logs.
|
@apotterri daphne injection
Almost similar to uvicorn. Only differences are
|
@virajkanwade Thank you so much for the work on figuring out how to inject into the various servers. It's hugely helpful. I should have time today to get started the changes necessary to implement an ASGI middleware to manage recording. Thanks again. |
Temos alguma novidade sobre o tema ? Algo simplificado ? Ou a injeção é o único caminho ? |
@EwertonDCSilv thanks for your interest in AppMap! I'm continuing to work on FastAPI support. There's a PR open for it here: #282, which I'm expecting to update later today or tomorrow. I'm not sure when it will be finished, though I expect it should be soon. |
@apotterri alguma novidade ? |
@virajkanwade @EwertonDCSilv FastAPI integration is available in v1.20.0 of the Python agent, now available on PyPI: https://pypi.org/project/appmap/1.20.0/ |
@apotterri for some reason, test_fastapi is failing for me
|
Not sure why that would be, the CI builds are all green: https://app.travis-ci.com/github/getappmap/appmap-python/builds/269484671 Do the tests also fail if you run them using |
@apotterri seems like it was an env issue. After using the |
The warnings seem related to |
Como ficou a configuração para as chamadas http do Fastapi ? |
@apotterri ficaria muito grato com um exemplo básico ! |
@EwertonDCSilv The documentation for the Python agent has been updated to include a description of using it with a FastAPI application: https://appmap.io/docs/reference/appmap-python#web-framework-support . |
appmap-python will record AppMaps of FastAPI code via test case recording.
Enhance appmap-python to support requests recording and remote recording for FastAPI: https://fastapi.tiangolo.com/
Ensure that the output includes HTTP server requests and responses.
The text was updated successfully, but these errors were encountered: