Coverage for backend/idaes_service/settings.py: 43%
25 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
1import logging
2import os
3from logging.config import dictConfig
6OTLP_ENDPOINT = os.getenv("OTLP_ENDPOINT", "http://localhost:4318/v1/traces")
7OTLP_SERVICE_NAME = os.getenv("OTLP_SERVICE_NAME", "idaes")
8CODE_COVERAGE_ENABLED = os.getenv("CODE_COVERAGE_ENABLED", "False").lower() in ('true', '1')
9DEBUG = os.getenv("PRODUCTION", "False").lower() in ('false', '0')
11def set_dapr_endpoints():
12 # Monkey-patch Dapr SDK config to avoid the need to set environment variables externally when
13 # running the API server. We still check for environment variables to allow for overriding.
14 from dapr.conf import settings
16 if os.getenv("DAPR_HTTP_ENDPOINT") is None:
17 settings.DAPR_HTTP_ENDPOINT = "http://localhost:3502"
19 if os.getenv("DAPR_GRPC_ENDPOINT") is None:
20 settings.DAPR_GRPC_ENDPOINT = "localhost:50002"
22def log_code_coverage_status():
23 if os.getenv("COVERAGE_PROCESS_CONFIG"):
24 logging.info("Detected code coverage instrumentation.")
26 if not DEBUG:
27 logging.warning("Code coverage already running in production mode. This may impact performance.")
29def load():
30 log_config = {
31 "version": 1,
32 "disable_existing_loggers": False,
33 "formatters": {
34 "default": {
35 "format": "[%(asctime)s] %(levelname)s [%(filename)s:%(lineno)d] [trace_id=%(otelTraceID)s span_id=%(otelSpanID)s] [%(funcName)s] %(message)s",
36 "datefmt": "%Y-%m-%d %H:%M:%S",
37 "defaults": {"otelTraceID": "0", "otelSpanID": "0"}
38 },
39 },
40 "handlers": {
41 "console": {
42 "class": "logging.StreamHandler",
43 "level": "INFO",
44 "formatter": "default",
45 "stream": "ext://sys.stdout",
46 },
47 },
48 "loggers": {
49 "app": {"handlers": ["console"], "level": "INFO", "propagate": True},
50 },
51 "root": {"handlers": ["console"], "level": "INFO"},
52 }
54 dictConfig(log_config)
56 if DEBUG: 56 ↛ 57line 56 didn't jump to line 57 because the condition on line 56 was never true
57 set_dapr_endpoints()
58 log_code_coverage_status()
60load()