Starlette

Starlette

Scout supports Starlette 0.12+. General instructions for a Starlette app:

1. Install the scout-apm package:

pip install scout-apm

2. Configure Scout and attach its middleware to your Starlette app:

from scout_apm.api import Config
from scout_apm.async_.starlette import ScoutMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware

Config.set(
    key="[AVAILABLE IN THE SCOUT UI]",
    name="A FRIENDLY NAME FOR YOUR APP",
    monitor=True,
)

middleware = [
 # Should be *first* in your stack, so it's the outermost and can
 # track all requests
 Middleware(ScoutMiddleware),
]

app = Starlette(middleware=middleware)

If you’re using Starlette <0.13, which refactored the middleware API, instead use app.add_middleware(ScoutMiddleware). Make sure it’s the last call to add_middleware() so that Scout is the outermost middleware.

If you wish to configure Scout via environment variables, use SCOUT_MONITOR, SCOUT_NAME and SCOUT_KEY and remove the call to Config.set.

If you’ve installed Scout via the Heroku Addon, the provisioning process automatically sets SCOUT_MONITOR and SCOUT_KEY via config vars. Only SCOUT_NAME is required.

3. Deploy.

It takes approximatively five minutes for your data to first appear within the Scout UI.