Files
posthog.com/contents/docs/libraries/python/_snippets/python-fastapi-exception-autocapture.mdx
Vincent (Wen Yu) Ge 9622fbe001 Stepped installation guide for error tracking (#12220)
Co-authored-by: Vincent (Wen Yu) Ge <gewenyu99@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: David Newell <david@posthog.com>
Co-authored-by: edwinyjlim <edwinyjlim@gmail.com>
Co-authored-by: Edwin Lim <edwin@posthog.com>
2025-07-30 13:33:17 -04:00

11 lines
346 B
Plaintext

```python
from fastapi.responses import JSONResponse
from posthog import Posthog
posthog = Posthog('<ph_project_api_key>', host='<ph_client_api_host>')
@app.exception_handler(Exception)
async def http_exception_handler(request, exc):
posthog.capture_exception(exc)
return JSONResponse(status_code=500, content={'message': str(exc)})
```