Skip to content

Commit da2866d

Browse files
committed
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 <[email protected]>
1 parent de69216 commit da2866d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

llama_stack/log.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# Default log level
2121
DEFAULT_LOG_LEVEL = logging.INFO
22+
DEFAULT_TELEMETRY_LEVEL = logging.WARN
2223

2324
# Predefined categories
2425
CATEGORIES = [
@@ -35,8 +36,10 @@
3536
"openai_responses",
3637
]
3738

38-
# Initialize category levels with default level
39-
_category_levels: dict[str, int] = dict.fromkeys(CATEGORIES, DEFAULT_LOG_LEVEL)
39+
# Initialize category levels with default level, except for telemetry which gets WARN
40+
_category_levels: dict[str, int] = {
41+
category: DEFAULT_TELEMETRY_LEVEL if category == "telemetry" else DEFAULT_LOG_LEVEL for category in CATEGORIES
42+
}
4043

4144

4245
def config_to_category_levels(category: str, level: str):
@@ -99,6 +102,7 @@ def parse_environment_config(env_config: str) -> dict[str, int]:
99102
Returns:
100103
Dict[str, int]: A dictionary mapping categories to their log levels.
101104
"""
105+
102106
category_levels = {}
103107
delimiter = ","
104108
for pair in env_config.split(delimiter):
@@ -193,6 +197,7 @@ def filter(self, record):
193197
"filename": log_file,
194198
"mode": "a",
195199
"encoding": "utf-8",
200+
"filters": ["category_filter"],
196201
}
197202

198203
logging_config = {
@@ -213,7 +218,9 @@ def filter(self, record):
213218
"loggers": {
214219
category: {
215220
"handlers": list(handlers.keys()), # Apply all handlers
216-
"level": category_levels.get(category, DEFAULT_LOG_LEVEL),
221+
"level": category_levels.get(
222+
category, (DEFAULT_LOG_LEVEL if category != "telemetry" else DEFAULT_TELEMETRY_LEVEL)
223+
),
217224
"propagate": False, # Disable propagation to root logger
218225
}
219226
for category in CATEGORIES
@@ -237,6 +244,7 @@ def get_logger(
237244
"""
238245
Returns a logger with the specified name and category.
239246
If no category is provided, defaults to 'uncategorized'.
247+
Note: telemetry category defaults to WARN as the default level
240248
241249
Parameters:
242250
name (str): The name of the logger (e.g., module or filename).

llama_stack/providers/inline/telemetry/meta_reference/console_span_processor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ def __init__(self, print_attributes: bool = False):
2121
self.print_attributes = print_attributes
2222

2323
def on_start(self, span: ReadableSpan, parent_context=None) -> None:
24-
if span.attributes and span.attributes.get("__autotraced__"):
25-
return
26-
2724
timestamp = datetime.fromtimestamp(span.start_time / 1e9, tz=UTC).strftime("%H:%M:%S.%f")[:-3]
2825
logger.info(f"[dim]{timestamp}[/dim] [bold magenta][START][/bold magenta] [dim]{span.name}[/dim]")
2926

0 commit comments

Comments
 (0)