Skip to content

Commit 0b8ea93

Browse files
committed
chore(agent): update logging
1 parent 42f71df commit 0b8ea93

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

agent/entrypoint.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,24 @@ def write_result(
10371037
)
10381038

10391039

1040+
# Values under these keys may contain tool stderr, paths, or incidental secrets.
1041+
_METRICS_REDACT_KEYS = frozenset({"error"})
1042+
1043+
1044+
def _metrics_payload_for_logging(metrics: dict) -> dict:
1045+
"""Build metrics dict for stdout / CloudWatch JSON (redacts sensitive fields)."""
1046+
out: dict = {}
1047+
for k, v in metrics.items():
1048+
if k in _METRICS_REDACT_KEYS:
1049+
out[k] = None if v is None else "[redacted]"
1050+
continue
1051+
if isinstance(v, (bool, int, float, type(None))):
1052+
out[k] = v
1053+
else:
1054+
out[k] = str(v)
1055+
return out
1056+
1057+
10401058
def print_metrics(metrics: dict):
10411059
"""Emit a METRICS_REPORT event and print a human-readable summary.
10421060
@@ -1046,15 +1064,10 @@ def print_metrics(metrics: dict):
10461064
10471065
Native types (int, float, bool, None) are preserved in the JSON payload.
10481066
None values become JSON ``null`` and are excluded by ``ispresent()``
1049-
filters in the dashboard queries.
1067+
filters in the dashboard queries. Raw ``error`` text is never logged verbatim.
10501068
"""
1051-
# Build JSON payload preserving native types
1052-
json_payload: dict = {"event": "METRICS_REPORT"}
1053-
for k, v in metrics.items():
1054-
if isinstance(v, (bool, int, float, type(None))):
1055-
json_payload[k] = v
1056-
else:
1057-
json_payload[k] = str(v)
1069+
safe = _metrics_payload_for_logging(metrics)
1070+
json_payload: dict = {"event": "METRICS_REPORT", **safe}
10581071

10591072
# Write directly to CloudWatch Logs (reliable — doesn't depend on stdout capture)
10601073
_emit_metrics_to_cloudwatch(json_payload)
@@ -1066,10 +1079,9 @@ def print_metrics(metrics: dict):
10661079
print("\n" + "=" * 60)
10671080
print("METRICS REPORT")
10681081
print("=" * 60)
1069-
for key, value in metrics.items():
1082+
for key in metrics:
10701083
# Avoid printing raw metric values to stdout; values may include
10711084
# error text from downstream tools.
1072-
_ = value
10731085
print(f" {key:30s}: [redacted]")
10741086
print("=" * 60)
10751087

0 commit comments

Comments
 (0)