feat(diagnostics): carry trace context through hooks

Pass immutable diagnostic trace contexts through agent and tool hook surfaces, emit model usage with the run trace, and parent OTEL spans/logs from validated trace context without retained global state.\n\nThanks @vincentkoc.
This commit is contained in:
Vincent Koc
2026-04-24 00:24:32 -07:00
committed by GitHub
parent 33c0cd1378
commit bcdacfa1b3
18 changed files with 229 additions and 35 deletions

View File

@@ -106,7 +106,7 @@ const handler = async (event) => {
export default handler;
```
Each event includes: `type`, `action`, `sessionKey`, `timestamp`, `messages` (push to send to user), and `context` (event-specific data).
Each event includes: `type`, `action`, `sessionKey`, `timestamp`, `messages` (push to send to user), and `context` (event-specific data). Agent and tool plugin hook contexts can also include `trace`, a read-only W3C-compatible diagnostic trace context that plugins may pass into structured logs for OTEL correlation.
### Event context highlights