-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from roboflow/feature/add_lambda_logger
Add structured API logger
- Loading branch information
Showing
21 changed files
with
85 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,56 @@ | ||
import logging | ||
import os | ||
import warnings | ||
from typing import Any | ||
|
||
from rich.logging import RichHandler | ||
from structlog.processors import CallsiteParameter | ||
|
||
from inference.core.env import LOG_LEVEL | ||
|
||
logger = logging.getLogger("inference") | ||
logger.setLevel(LOG_LEVEL) | ||
logger.addHandler(RichHandler()) | ||
logger.propagate = False | ||
from inference.core.utils.environment import str2bool | ||
|
||
if LOG_LEVEL == "ERROR" or LOG_LEVEL == "FATAL": | ||
warnings.filterwarnings("ignore", category=UserWarning, module="onnxruntime.*") | ||
|
||
|
||
def add_correlation( | ||
logger: logging.Logger, method_name: str, event_dict: dict[str, Any] | ||
) -> dict[str, Any]: | ||
from asgi_correlation_id import correlation_id | ||
|
||
request_id = correlation_id.get() | ||
if request_id: | ||
event_dict["request_id"] = request_id | ||
return event_dict | ||
|
||
|
||
if str2bool(os.getenv("API_LOGGING_ENABLED", "False")): | ||
import structlog | ||
|
||
structlog.configure( | ||
processors=[ | ||
add_correlation, | ||
structlog.stdlib.filter_by_level, | ||
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M.%S"), | ||
structlog.processors.StackInfoRenderer(), | ||
structlog.processors.format_exc_info, | ||
structlog.processors.CallsiteParameterAdder( | ||
[ | ||
CallsiteParameter.FILENAME, | ||
CallsiteParameter.FUNC_NAME, | ||
CallsiteParameter.LINENO, | ||
], | ||
), | ||
structlog.processors.JSONRenderer(), | ||
], | ||
wrapper_class=structlog.stdlib.BoundLogger, | ||
logger_factory=structlog.stdlib.LoggerFactory(), | ||
cache_logger_on_first_use=True, | ||
) | ||
logger = structlog.get_logger("inference") | ||
logger.setLevel(LOG_LEVEL) | ||
else: | ||
logger = logging.getLogger("inference") | ||
logger.setLevel(LOG_LEVEL) | ||
logger.addHandler(RichHandler()) | ||
logger.propagate = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = "0.9.14" | ||
__version__ = "0.9.15rc1" | ||
|
||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
uvicorn[standard]<=0.22.0 | ||
python-multipart<=0.0.6 | ||
fastapi-cprofile<=0.0.2 | ||
orjson>=3.9.10 | ||
orjson>=3.9.10 | ||
asgi_correlation_id>=4.3.1 | ||
structlog>=24.1.0 |