@@ -1904,7 +1904,8 @@ def tearDown(self) -> None:
19041904            otel_fastapi .FastAPIInstrumentor ().uninstrument_app (self .app )
19051905
19061906    def  test_error_handler_context (self ):
1907-         """OTEL tracing contexts must be available during error handler execution""" 
1907+         """OTEL tracing contexts must be available during error handler 
1908+         execution, and handlers must only be executed once""" 
19081909
19091910        status_code  =  501 
19101911
@@ -1913,6 +1914,7 @@ async def _(*_):
19131914            self .error_trace_id  =  (
19141915                trace .get_current_span ().get_span_context ().trace_id 
19151916            )
1917+             self .executed  +=  1 
19161918            return  PlainTextResponse ("" , status_code )
19171919
19181920        @self .app .get ("/foobar" ) 
@@ -1947,25 +1949,6 @@ async def _():
19471949            event .attributes .get (EXCEPTION_TYPE ),
19481950            f"{ __name__ }  .UnhandledException" ,
19491951        )
1950- 
1951-     def  test_error_handler_side_effects (self ):
1952-         """FastAPI default exception handlers (aka error handlers) must be executed exactly once per exception""" 
1953- 
1954-         @self .app .exception_handler (Exception ) 
1955-         async  def  _ (* _ ):
1956-             self .executed  +=  1 
1957- 
1958-         @self .app .get ("/foobar" ) 
1959-         async  def  _ ():
1960-             raise  UnhandledException ("Test Exception" )
1961- 
1962-         try :
1963-             self .client .get (
1964-                 "/foobar" ,
1965-             )
1966-         except  Exception :  # pylint: disable=W0718 
1967-             pass 
1968- 
19691952        self .assertEqual (self .executed , 1 )
19701953
19711954    def  test_exception_span_recording (self ):
@@ -1979,7 +1962,7 @@ async def _():
19791962            self .client .get (
19801963                "/foobar" ,
19811964            )
1982-         except  Exception :   # pylint: disable=W0718 
1965+         except  UnhandledException : 
19831966            pass 
19841967
19851968        spans  =  self .memory_exporter .get_finished_spans ()
@@ -2013,7 +1996,7 @@ async def _(*_):
20131996            self .client .get (
20141997                "/foobar" ,
20151998            )
2016-         except  Exception :   # pylint: disable=W0718 
1999+         except  UnhandledException : 
20172000            pass 
20182001
20192002        spans  =  self .memory_exporter .get_finished_spans ()
0 commit comments