|
2 | 2 | import os |
3 | 3 | import threading |
4 | 4 | from datetime import datetime, timezone |
5 | | -from typing import Optional, Any, Dict, List |
| 5 | +from typing import Optional, Any, Dict, List, cast |
6 | 6 |
|
7 | 7 | import requests |
8 | 8 |
|
@@ -33,27 +33,28 @@ def emit(self, record: logging.LogRecord) -> None: |
33 | 33 | self.handleError(record) |
34 | 34 |
|
35 | 35 | def _get_rollout_id(self, record: logging.LogRecord) -> Optional[str]: |
36 | | - if hasattr(record, "rollout_id") and record.rollout_id is not None: # type: ignore |
37 | | - return str(record.rollout_id) # type: ignore |
| 36 | + if hasattr(record, "rollout_id") and cast(Any, getattr(record, "rollout_id")) is not None: |
| 37 | + return str(cast(Any, getattr(record, "rollout_id"))) |
38 | 38 | return os.getenv(self.rollout_id_env) |
39 | 39 |
|
40 | 40 | def _build_payload(self, record: logging.LogRecord, rollout_id: str) -> Dict[str, Any]: |
41 | 41 | timestamp = datetime.fromtimestamp(record.created, tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ") |
42 | 42 | message = record.getMessage() |
43 | 43 | tags: List[str] = [f"rollout_id:{rollout_id}"] |
44 | 44 | # Optional additional tags |
45 | | - if hasattr(record, "experiment_id") and record.experiment_id: |
46 | | - tags.append(f"experiment_id:{record.experiment_id}") # type: ignore |
47 | | - if hasattr(record, "run_id") and record.run_id: |
48 | | - tags.append(f"run_id:{record.run_id}") # type: ignore |
49 | | - program = getattr(record, "program", None) or "eval_protocol" |
50 | | - status = getattr(record, "status", None) |
| 45 | + if hasattr(record, "experiment_id") and cast(Any, getattr(record, "experiment_id")): |
| 46 | + tags.append(f"experiment_id:{cast(Any, getattr(record, 'experiment_id'))}") |
| 47 | + if hasattr(record, "run_id") and cast(Any, getattr(record, "run_id")): |
| 48 | + tags.append(f"run_id:{cast(Any, getattr(record, 'run_id'))}") |
| 49 | + program = cast(Optional[str], getattr(record, "program", None)) or "eval_protocol" |
| 50 | + status_val = cast(Any, getattr(record, "status", None)) |
| 51 | + status = status_val if isinstance(status_val, str) else None |
51 | 52 | return { |
52 | 53 | "program": program, |
53 | | - "status": status if isinstance(status, str) else None, |
| 54 | + "status": status, |
54 | 55 | "message": message, |
55 | 56 | "tags": tags, |
56 | | - "metadata": getattr(record, "metadata", None), |
| 57 | + "metadata": cast(Any, getattr(record, "metadata", None)), |
57 | 58 | "extras": { |
58 | 59 | "logger_name": record.name, |
59 | 60 | "level": record.levelname, |
|
0 commit comments