I have a FastAPI application where the docs are disabled:
from fastapi import FastAPI
import rollbar
from rollbar.contrib.fastapi import add_to as rollbar_add_to
rollbar.init(
...,
environment='test',
handler="async",
include_request_body=True,
)
app = FastAPI(docs_url=None, redoc_url=None)
rollbar_add_to(app)
Which gives me the error ERROR:rollbar.contrib.fastapi.routing:RollbarLoggingRoute must to be added to a bare router (before adding routes). See docs for more details.
I have a FastAPI application where the docs are disabled:
Which gives me the error
ERROR:rollbar.contrib.fastapi.routing:RollbarLoggingRoute must to be added to a bare router (before adding routes). See docs for more details.
I dug a bit, and the issue seems to be in this section https://github.com/rollbar/pyrollbar/blob/77cbffaa7447f04f653135e1d7f615ce41fcc4e9/rollbar/contrib/fastapi/utils.py#L69-L82 where the number of expected routes for a bare app is hardwired to 4 (meaning it expects
/openapi.json
,/docs
,/docs/oauth2-redirect
, and/redoc
), but my app only has one of those (/openapi.json
).Depending on the FastAPI setup, there might be anywhere between 0 and 4 available routes for a "bare" app. I might create a PR for this later, but my suggestion would be checking that there are no available routes other than the ones in the fields
openapi_url
,docs_url
,redoc_url
, andswagger_ui_oauth2_redirect_url
on theFastAPI
object https://github.com/tiangolo/fastapi/blob/3efb4f7edff99fdc12802a85ae9d140ec4772497/fastapi/applications.py#L107-L121