The FastAPI integration adds support for the FastAPI Framework.


Install sentry-sdk from PyPI with the fastapi extra:

pip install --upgrade 'sentry-sdk[fastapi]'


To configure the Sentry SDK, initialize it before your app has been initialized:

from fastapi import FastAPI

import sentry_sdk


    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    # We recommend adjusting this value in production,

app = FastAPI()


This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:

from fastapi import FastAPI

app = FastAPI()

async def trigger_error():
    division_by_zero = 1 / 0

Visiting "/sentry-debug" will trigger an error that will be captured by Sentry.


Issue Reporting

The following information about your FastAPI project will be available to you on

  • All exceptions leading to an Internal Server Error are captured and reported.
  • Request data such as URL, HTTP method, headers, form data, and JSON payloads is attached to all issues.
  • Sentry excludes raw bodies and multipart file uploads.
  • Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set send_default_pii to True.

Issues List

Monitor Performance

The following parts of your FastAPI project are monitored:

  • Middleware stack
  • Middleware send and receive callbacks
  • Database queries
  • Redis commands

Performance details are shown as waterfall diagram

Integration Options

If you want to change the default behavior of the FastAPI integration, you need to instantiate the integration manually and then pass it to Sentry's init function. Because FastAPI is based on the Starlette framework, both integrations, StarletteIntegration and FastApiIntegration, must be instantiated.


You can pass the keyword argument transaction_style to StarletteIntegration() and FastApiIntegration().

With this option, you can influence how the transactions are named in Sentry. For example:

from sentry_sdk.integrations.starlette import StarletteIntegration
from sentry_sdk.integrations.fastapi import FastApiIntegration

    # ...

app = FastAPI()

async def product_detail(product_id):
    return {...}

In the above code, the transaction name will be:

  • "/catalog/product/{product_id}" if you set transaction_style="url"
  • "product_detail" if you set transaction_style="endpoint"

The default is "url".

Supported Versions

  • FastAPI: 0.79.0+
  • Python: 3.7+
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").