Skip to content

Commit

Permalink
trace: record pid
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Dec 26, 2024
1 parent 99423c5 commit ef2bcf2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/inspect_ai/_util/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def trace_action(
trace_id = uuid()
start_monotonic = time.monotonic()
start_wall = time.time()
pid = os.getpid()
formatted_message = (
message % args if args else message % kwargs if kwargs else message
)
Expand All @@ -47,6 +48,7 @@ def trace_message(event: str) -> str:
"event": "enter",
"trace_id": str(trace_id),
"start_time": start_wall,
"pid": pid,
},
)

Expand All @@ -61,6 +63,7 @@ def trace_message(event: str) -> str:
"event": "exit",
"trace_id": str(trace_id),
"duration": duration,
"pid": pid,
},
)
except (KeyboardInterrupt, asyncio.CancelledError):
Expand All @@ -73,6 +76,7 @@ def trace_message(event: str) -> str:
"event": "cancel",
"trace_id": str(trace_id),
"duration": duration,
"pid": pid,
},
)
raise
Expand All @@ -86,6 +90,7 @@ def trace_message(event: str) -> str:
"event": "timeout",
"trace_id": str(trace_id),
"duration": duration,
"pid": pid,
},
)
raise
Expand All @@ -102,6 +107,7 @@ def trace_message(event: str) -> str:
"error": getattr(ex, "message", str(ex)) or repr(ex),
"error_type": type(ex).__name__,
"stacktrace": traceback.format_exc(),
"pid": pid,
},
)
raise
Expand Down Expand Up @@ -143,6 +149,7 @@ def format(self, record: logging.LogRecord) -> str:
"error",
"error_type",
"stacktrace",
"pid",
]:
if hasattr(record, key):
output[key] = getattr(record, key)
Expand Down Expand Up @@ -203,6 +210,7 @@ class ActionTraceRecord(TraceRecord):
error: str | None = Field(default=None)
error_type: str | None = Field(default=None)
stacktrace: str | None = Field(default=None)
pid: int | None = Field(default=None)


def read_trace_file(file: Path) -> list[TraceRecord]:
Expand Down

0 comments on commit ef2bcf2

Please sign in to comment.