Skip to content

Commit 43777b0

Browse files
Merge pull request #1205 from roboflow/fix/correlation-id-env-typo
Add CORRELATION_ID_LOG_KEY; fix typo for CORRELATION_ID_HEADER; control logging across modules with single env variable API_LOGGING_ENABLED
2 parents d72e089 + 5871ca1 commit 43777b0

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

inference/core/env.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,14 @@
242242
# Whether is's GCP serverless service
243243
GCP_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
249255
LEGACY_ROUTE_ENABLED = str2bool(os.getenv("LEGACY_ROUTE_ENABLED", True))

inference/core/interfaces/http/http_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
from 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,
@@ -111,8 +112,7 @@
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,

inference/core/logger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from rich.logging import RichHandler
77
from 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
1010
from inference.core.utils.environment import str2bool
1111

1212
if 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(

0 commit comments

Comments
 (0)