File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
tests/integrations/fastapi Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -693,7 +693,11 @@ def _transaction_name_from_router(scope):
693693 for route in router .routes :
694694 match = route .matches (scope )
695695 if match [0 ] == Match .FULL :
696- return getattr (route , "path" , None )
696+ try :
697+ return route .path
698+ except AttributeError :
699+ # routes added via app.host() won't have a path attribute
700+ return scope .get ("path" )
697701
698702 return None
699703
Original file line number Diff line number Diff line change @@ -682,3 +682,38 @@ async def _error():
682682 client .get ("/error" )
683683
684684 assert len (events ) == int (expected_error )
685+
686+
687+ @pytest .mark .parametrize ("transaction_style" , ["endpoint" , "url" ])
688+ def test_app_host (sentry_init , capture_events , transaction_style ):
689+ sentry_init (
690+ traces_sample_rate = 1.0 ,
691+ integrations = [
692+ StarletteIntegration (transaction_style = transaction_style ),
693+ FastApiIntegration (transaction_style = transaction_style ),
694+ ],
695+ )
696+
697+ app = FastAPI ()
698+ subapp = FastAPI ()
699+
700+ @subapp .get ("/subapp" )
701+ async def subapp_route ():
702+ return {"message" : "Hello world!" }
703+
704+ app .host ("subapp" , subapp )
705+
706+ events = capture_events ()
707+
708+ client = TestClient (app )
709+ client .get ("/subapp" , headers = {"Host" : "subapp" })
710+
711+ assert len (events ) == 1
712+
713+ (event ,) = events
714+ assert "transaction" in event
715+
716+ if transaction_style == "url" :
717+ assert event ["transaction" ] == "/subapp"
718+ else :
719+ assert event ["transaction" ].endswith ("subapp_route" )
You can’t perform that action at this time.
0 commit comments