File tree Expand file tree Collapse file tree 3 files changed +7
-10
lines changed
Expand file tree Collapse file tree 3 files changed +7
-10
lines changed Original file line number Diff line number Diff line change 66from health_checks .fastapi_healthcheck import build_fastapi_health_check_router
77from opentelemetry .instrumentation .fastapi import FastAPIInstrumentor
88from prometheus_fastapi_instrumentator import Instrumentator
9- from sentry_sdk .integrations .fastapi import FastApiIntegration
9+ from sentry_sdk .integrations .asgi import SentryAsgiMiddleware
1010
1111from microbootstrap .bootstrappers .base import ApplicationBootstrapper
1212from microbootstrap .config .fastapi import FastApiConfig
@@ -40,13 +40,9 @@ def bootstrap_before(self) -> dict[str, typing.Any]:
4040
4141@FastApiBootstrapper .use_instrument ()
4242class FastApiSentryInstrument (SentryInstrument ):
43- def bootstrap (self ) -> None :
44- for sentry_integration in self .instrument_config .sentry_integrations :
45- if isinstance (sentry_integration , FastApiIntegration ):
46- break
47- else :
48- self .instrument_config .sentry_integrations .append (FastApiIntegration ())
49- super ().bootstrap ()
43+ def bootstrap_after (self , application : ApplicationT ) -> ApplicationT :
44+ application .add_middleware (SentryAsgiMiddleware )
45+ return application
5046
5147
5248@FastApiBootstrapper .use_instrument ()
Original file line number Diff line number Diff line change @@ -40,8 +40,7 @@ def write_status(self, console_writer: ConsoleWriter) -> None:
4040 )
4141
4242 @abc .abstractmethod
43- def is_ready (self ) -> bool :
44- raise NotImplementedError
43+ def is_ready (self ) -> bool : ...
4544
4645 @classmethod
4746 @abc .abstractmethod
Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ async def error_handler() -> None:
6666def test_fastapi_sentry_bootstrap (minimal_sentry_config : SentryConfig ) -> None :
6767 sentry_instrument : typing .Final = FastApiSentryInstrument (minimal_sentry_config )
6868 sentry_instrument .bootstrap ()
69+ app = fastapi .FastAPI ()
70+ assert sentry_instrument .bootstrap_after (app ) is app
6971 assert sentry_instrument .bootstrap_before () == {}
7072
7173
You can’t perform that action at this time.
0 commit comments