mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-25 19:37:29 +02:00
More fetch_versioned_implementation logging (#1187)
--------- Co-authored-by: Kevin Shi <kevinshisvf@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ def log_function_time(
|
||||
func_name: str | None = None,
|
||||
print_only: bool = False,
|
||||
debug_only: bool = False,
|
||||
include_args: bool = False,
|
||||
) -> Callable[[F], F]:
|
||||
def decorator(func: F) -> F:
|
||||
@wraps(func)
|
||||
@@ -30,10 +31,12 @@ def log_function_time(
|
||||
result = func(*args, **kwargs)
|
||||
elapsed_time_str = str(time.time() - start_time)
|
||||
log_name = func_name or func.__name__
|
||||
args_str = f" args={args} kwargs={kwargs}" if include_args else ""
|
||||
final_log = f"{log_name}{args_str} took {elapsed_time_str} seconds"
|
||||
if debug_only:
|
||||
logger.debug(f"{log_name} took {elapsed_time_str} seconds")
|
||||
logger.debug(final_log)
|
||||
else:
|
||||
logger.info(f"{log_name} took {elapsed_time_str} seconds")
|
||||
logger.info(final_log)
|
||||
|
||||
if not print_only:
|
||||
optional_telemetry(
|
||||
|
@@ -2,6 +2,12 @@ import functools
|
||||
import importlib
|
||||
from typing import Any
|
||||
|
||||
from danswer.utils.logger import setup_logger
|
||||
from danswer.utils.timing import log_function_time
|
||||
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
|
||||
class DanswerVersion:
|
||||
def __init__(self) -> None:
|
||||
@@ -17,7 +23,9 @@ class DanswerVersion:
|
||||
global_version = DanswerVersion()
|
||||
|
||||
|
||||
@log_function_time(print_only=True, include_args=True)
|
||||
@functools.lru_cache(maxsize=128)
|
||||
def fetch_versioned_implementation(module: str, attribute: str) -> Any:
|
||||
logger.info("Fetching versioned implementation for %s.%s", module, attribute)
|
||||
module_full = f"ee.{module}" if global_version.get_is_ee_version() else module
|
||||
return getattr(importlib.import_module(module_full), attribute)
|
||||
|
Reference in New Issue
Block a user