File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 242242# Whether is's GCP serverless service
243243GCP_SERVERLESS = str2bool (os .getenv ("GCP_SERVERLESS" , "False" ))
244244
245+ # Flag to enable API logging, default is False
246+ API_LOGGING_ENABLED = str2bool (os .getenv ("API_LOGGING_ENABLED" , "False" ))
247+
248+ # Header where correlaction ID for logging is stored
249+ CORRELATION_ID_HEADER = os .getenv ("CORRELATION_ID_HEADER" , "X-Request-ID" )
250+
245251# Header where correlaction ID for logging is stored
246- CORRELACTION_ID_HEADER = os .getenv ("CORRELACTION_ID_HEADER " , "X-Request-ID " )
252+ CORRELATION_ID_LOG_KEY = os .getenv ("CORRELATION_ID_LOG_KEY " , "request_id " )
247253
248254# Flag to enable legacy route, default is True
249255LEGACY_ROUTE_ENABLED = str2bool (os .getenv ("LEGACY_ROUTE_ENABLED" , True ))
Original file line number Diff line number Diff line change 100100from inference .core .env import (
101101 ALLOW_ORIGINS ,
102102 API_KEY ,
103+ API_LOGGING_ENABLED ,
103104 BUILDER_ORIGIN ,
104105 CORE_MODEL_CLIP_ENABLED ,
105106 CORE_MODEL_DOCTR_ENABLED ,
111112 CORE_MODEL_TROCR_ENABLED ,
112113 CORE_MODEL_YOLO_WORLD_ENABLED ,
113114 CORE_MODELS_ENABLED ,
114- CORRELACTION_ID_HEADER ,
115- DEDICATED_DEPLOYMENT_ID ,
115+ CORRELATION_ID_HEADER ,
116116 DEDICATED_DEPLOYMENT_WORKSPACE_URL ,
117117 DEPTH_ESTIMATION_ENABLED ,
118118 DISABLE_WORKFLOW_ENDPOINTS ,
@@ -636,10 +636,10 @@ async def on_shutdown():
636636 strip_dirs = False ,
637637 sort_by = "cumulative" ,
638638 )
639- if DEDICATED_DEPLOYMENT_ID or GCP_SERVERLESS :
639+ if API_LOGGING_ENABLED :
640640 app .add_middleware (
641641 asgi_correlation_id .CorrelationIdMiddleware ,
642- header_name = CORRELACTION_ID_HEADER ,
642+ header_name = CORRELATION_ID_HEADER ,
643643 update_request_header = True ,
644644 generator = lambda : uuid4 ().hex ,
645645 validator = lambda a : True ,
Original file line number Diff line number Diff line change 66from rich .logging import RichHandler
77from structlog .processors import CallsiteParameter
88
9- from inference .core .env import LOG_LEVEL
9+ from inference .core .env import API_LOGGING_ENABLED , CORRELATION_ID_LOG_KEY , LOG_LEVEL
1010from inference .core .utils .environment import str2bool
1111
1212if LOG_LEVEL == "ERROR" or LOG_LEVEL == "FATAL" :
@@ -20,11 +20,11 @@ def add_correlation(
2020
2121 request_id = correlation_id .get ()
2222 if request_id :
23- event_dict ["request_id" ] = request_id
23+ event_dict [CORRELATION_ID_LOG_KEY ] = request_id
2424 return event_dict
2525
2626
27- if str2bool ( os . getenv ( " API_LOGGING_ENABLED" , "False" )) :
27+ if API_LOGGING_ENABLED :
2828 import structlog
2929
3030 structlog .configure (
You can’t perform that action at this time.
0 commit comments