Skip to content

Commit 01ddfb6

Browse files
committed
feat(sdk-ts): add watchLogs with loss-aware resume
Signed-off-by: letv1nnn <[email protected]>
1 parent eef8bec commit 01ddfb6

6 files changed

Lines changed: 679 additions & 3 deletions

File tree

‎docs/sdk/typescript.mdx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ SSH sessions, sandbox provider attachment, configuration, and policy. Close
9797
operation-scoped streams and forwarding handles when finished. The root client
9898
does not retain a dedicated session and has no `close()` method.
9999

100+
## Watch Logs and Events
101+
102+
`watchLogs` streams a sandbox's log lines and platform events with automatic
103+
reconnect and loss-aware resume. Pass a previous item's `cursor` back in as
104+
`resumeAfterCursor` to continue after a restart without gaps or duplicates:
105+
106+
```ts
107+
for await (const item of client.sandbox.watchLogs(sandbox.name, { followLogs: true })) {
108+
if (item.kind === 'log') {
109+
console.log(`${item.line.level} ${item.line.message}`)
110+
} else if (item.kind === 'warning') {
111+
console.warn(`gap: ${item.message}`)
112+
}
113+
}
114+
```
115+
116+
See [Accessing Logs](/observability/accessing-logs) for the cursor and resume
117+
contract this method implements.
118+
100119
## Use the Raw Client
101120

102121
Use `client.raw` for RPCs that the curated clients do not yet wrap. Import

0 commit comments

Comments
 (0)