File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed 
packages/service-library/src/servicelib/fastapi Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 22
33
44from  fastapi  import  FastAPI 
5+ from  prometheus_client  import  CollectorRegistry 
56from  prometheus_fastapi_instrumentator  import  Instrumentator 
67
78
89def  setup_prometheus_instrumentation (app : FastAPI ) ->  Instrumentator :
9- 
10+     # NOTE: use that registry to prevent having a global one 
11+     registry  =  CollectorRegistry (auto_describe = True )
1012    instrumentator  =  Instrumentator (
11-         should_instrument_requests_inprogress = True , inprogress_labels = False 
13+         should_instrument_requests_inprogress = True ,
14+         inprogress_labels = False ,
15+         registry = registry ,
1216    ).instrument (app )
1317
14-     async  def  on_startup (app : FastAPI ) ->  None :
18+     async  def  _on_startup (app : FastAPI ) ->  None :
1519        instrumentator .expose (app , include_in_schema = False )
1620
1721    def  _unregister () ->  None :
@@ -21,6 +25,6 @@ def _unregister() -> None:
2125        ):
2226            instrumentator .registry .unregister (collector )
2327
24-     app .add_event_handler ("startup" , on_startup )
28+     app .add_event_handler ("startup" , _on_startup )
2529    app .add_event_handler ("shutdown" , _unregister )
2630    return  instrumentator 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments