Skip to content

Commit 2c3eea7

Browse files
Merge pull request #1183 from roboflow/feat/remove-uuid-validator-from-request-correlation-middleware-for-gcp-and-dd
Feat/remove UUID validator from request correlation middleware for gcp and dd
2 parents d3f1da8 + 412b807 commit 2c3eea7

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

inference/core/env.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@
231231
# Whether is's GCP serverless service
232232
GCP_SERVERLESS = str2bool(os.getenv("GCP_SERVERLESS", "False"))
233233

234+
# Header where correlaction ID for logging is stored
235+
CORRELACTION_ID_HEADER = os.getenv("CORRELACTION_ID_HEADER", "X-Request-ID")
236+
234237
# Flag to enable legacy route, default is True
235238
LEGACY_ROUTE_ENABLED = str2bool(os.getenv("LEGACY_ROUTE_ENABLED", True))
236239

inference/core/interfaces/http/http_api.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from functools import partial, wraps
66
from time import sleep
77
from typing import Any, Dict, List, Optional, Union
8+
from uuid import uuid4
89

910
import asgi_correlation_id
1011
import uvicorn
@@ -108,6 +109,8 @@
108109
CORE_MODEL_TROCR_ENABLED,
109110
CORE_MODEL_YOLO_WORLD_ENABLED,
110111
CORE_MODELS_ENABLED,
112+
CORRELACTION_ID_HEADER,
113+
DEDICATED_DEPLOYMENT_ID,
111114
DEDICATED_DEPLOYMENT_WORKSPACE_URL,
112115
DISABLE_WORKFLOW_ENDPOINTS,
113116
DOCKER_SOCKET_PATH,
@@ -630,7 +633,17 @@ async def on_shutdown():
630633
strip_dirs=False,
631634
sort_by="cumulative",
632635
)
633-
app.add_middleware(asgi_correlation_id.CorrelationIdMiddleware)
636+
if DEDICATED_DEPLOYMENT_ID or GCP_SERVERLESS:
637+
app.add_middleware(
638+
asgi_correlation_id.CorrelationIdMiddleware,
639+
header_name=CORRELACTION_ID_HEADER,
640+
update_request_header=True,
641+
generator=lambda: uuid4().hex,
642+
validator=lambda a: True,
643+
transformer=lambda a: a,
644+
)
645+
else:
646+
app.add_middleware(asgi_correlation_id.CorrelationIdMiddleware)
634647

635648
if METRICS_ENABLED:
636649

0 commit comments

Comments
 (0)