mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-08-15 06:00:48 +00:00
feat: telemetry logging fixes
this does a few things: 1. fixes `on_start` so that all span [START] and [END] is printed. not just [END] 2. change `log.py` to set the default `telemetry` category to WARN not INFO This allows us to keep the metric logging and the verbosity of seeing the span [START] and [END] but by default hides it from normal users. This conforms to our logging system since a user just need to switch the category to INFO to see the logs Signed-off-by: Charlie Doern <cdoern@redhat.com>
This commit is contained in:
parent
61582f327c
commit
8e78478f9a
2 changed files with 11 additions and 6 deletions
|
@ -19,6 +19,7 @@ from llama_stack.core.datatypes import LoggingConfig
|
||||||
|
|
||||||
# Default log level
|
# Default log level
|
||||||
DEFAULT_LOG_LEVEL = logging.INFO
|
DEFAULT_LOG_LEVEL = logging.INFO
|
||||||
|
DEFAULT_TELEMETRY_LEVEL = logging.WARN
|
||||||
|
|
||||||
# Predefined categories
|
# Predefined categories
|
||||||
CATEGORIES = [
|
CATEGORIES = [
|
||||||
|
@ -35,8 +36,10 @@ CATEGORIES = [
|
||||||
"openai_responses",
|
"openai_responses",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Initialize category levels with default level
|
# Initialize category levels with default level, except for telemetry which gets WARN
|
||||||
_category_levels: dict[str, int] = dict.fromkeys(CATEGORIES, DEFAULT_LOG_LEVEL)
|
_category_levels: dict[str, int] = {
|
||||||
|
category: DEFAULT_TELEMETRY_LEVEL if category == "telemetry" else DEFAULT_LOG_LEVEL for category in CATEGORIES
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def config_to_category_levels(category: str, level: str):
|
def config_to_category_levels(category: str, level: str):
|
||||||
|
@ -99,6 +102,7 @@ def parse_environment_config(env_config: str) -> dict[str, int]:
|
||||||
Returns:
|
Returns:
|
||||||
Dict[str, int]: A dictionary mapping categories to their log levels.
|
Dict[str, int]: A dictionary mapping categories to their log levels.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
category_levels = {}
|
category_levels = {}
|
||||||
delimiter = ","
|
delimiter = ","
|
||||||
for pair in env_config.split(delimiter):
|
for pair in env_config.split(delimiter):
|
||||||
|
@ -193,6 +197,7 @@ def setup_logging(category_levels: dict[str, int], log_file: str | None) -> None
|
||||||
"filename": log_file,
|
"filename": log_file,
|
||||||
"mode": "a",
|
"mode": "a",
|
||||||
"encoding": "utf-8",
|
"encoding": "utf-8",
|
||||||
|
"filters": ["category_filter"],
|
||||||
}
|
}
|
||||||
|
|
||||||
logging_config = {
|
logging_config = {
|
||||||
|
@ -213,7 +218,9 @@ def setup_logging(category_levels: dict[str, int], log_file: str | None) -> None
|
||||||
"loggers": {
|
"loggers": {
|
||||||
category: {
|
category: {
|
||||||
"handlers": list(handlers.keys()), # Apply all handlers
|
"handlers": list(handlers.keys()), # Apply all handlers
|
||||||
"level": category_levels.get(category, DEFAULT_LOG_LEVEL),
|
"level": category_levels.get(
|
||||||
|
category, (DEFAULT_LOG_LEVEL if category != "telemetry" else DEFAULT_TELEMETRY_LEVEL)
|
||||||
|
),
|
||||||
"propagate": False, # Disable propagation to root logger
|
"propagate": False, # Disable propagation to root logger
|
||||||
}
|
}
|
||||||
for category in CATEGORIES
|
for category in CATEGORIES
|
||||||
|
@ -237,6 +244,7 @@ def get_logger(
|
||||||
"""
|
"""
|
||||||
Returns a logger with the specified name and category.
|
Returns a logger with the specified name and category.
|
||||||
If no category is provided, defaults to 'uncategorized'.
|
If no category is provided, defaults to 'uncategorized'.
|
||||||
|
Note: telemetry category defaults to WARN as the default level
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
name (str): The name of the logger (e.g., module or filename).
|
name (str): The name of the logger (e.g., module or filename).
|
||||||
|
|
|
@ -21,9 +21,6 @@ class ConsoleSpanProcessor(SpanProcessor):
|
||||||
self.print_attributes = print_attributes
|
self.print_attributes = print_attributes
|
||||||
|
|
||||||
def on_start(self, span: ReadableSpan, parent_context=None) -> None:
|
def on_start(self, span: ReadableSpan, parent_context=None) -> None:
|
||||||
if span.attributes and span.attributes.get("__autotraced__"):
|
|
||||||
return
|
|
||||||
|
|
||||||
timestamp = datetime.fromtimestamp(span.start_time / 1e9, tz=UTC).strftime("%H:%M:%S.%f")[:-3]
|
timestamp = datetime.fromtimestamp(span.start_time / 1e9, tz=UTC).strftime("%H:%M:%S.%f")[:-3]
|
||||||
logger.info(f"[dim]{timestamp}[/dim] [bold magenta][START][/bold magenta] [dim]{span.name}[/dim]")
|
logger.info(f"[dim]{timestamp}[/dim] [bold magenta][START][/bold magenta] [dim]{span.name}[/dim]")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue