Skip to content

Commit fe31606

Browse files
authored
feat(sdk-ts): add watchLogs with loss-aware resume (#3778)
Signed-off-by: letv1nnn <letv1n2007@icloud.com>
1 parent 01c249f commit fe31606

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
@@ -138,6 +138,25 @@ SSH sessions, sandbox provider attachment, configuration, and policy. Close
138138
operation-scoped streams and forwarding handles when finished. The root client
139139
does not retain a dedicated session and has no `close()` method.
140140

141+
## Watch Logs and Events
142+
143+
`watchLogs` streams a sandbox's log lines and platform events with automatic
144+
reconnect and loss-aware resume. Pass a previous item's `cursor` back in as
145+
`resumeAfterCursor` to continue after a restart without gaps or duplicates:
146+
147+
```ts
148+
for await (const item of client.sandbox.watchLogs(sandbox.name, { followLogs: true })) {
149+
if (item.kind === 'log') {
150+
console.log(`${item.line.level} ${item.line.message}`)
151+
} else if (item.kind === 'warning') {
152+
console.warn(`gap: ${item.message}`)
153+
}
154+
}
155+
```
156+
157+
See [Accessing Logs](/observability/accessing-logs) for the cursor and resume
158+
contract this method implements.
159+
141160
## Use the Raw Client
142161

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

0 commit comments

Comments
 (0)