Skip to content

Commit 2ccedc6

Browse files
feat: Filter the telemetry SSE stream by event type
Stainless-Generated-From: 00f1045bd90b91a504bf1868b37a912460d03ac1
1 parent 41f4980 commit 2ccedc6

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎src/resources/browsers/telemetry.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export class Telemetry extends APIResource {
4747
* stream closes when the browser session terminates. Each event frame includes an
4848
* id: field containing a monotonically increasing sequence number; pass it as
4949
* Last-Event-ID on reconnect to resume without gaps. The event: field is never
50-
* set; all frames carry JSON in the data: field. A keepalive comment frame is sent
50+
* set; event frames carry JSON in the data: field. A frame with an id: field and
51+
* no data: field moves Last-Event-ID past events that were not delivered, because
52+
* a type filter excluded them or they could not be decoded or exceeded the size
53+
* limit; SSE clients dispatch no event for it. A keepalive comment frame is sent
5154
* every 15 seconds when no events arrive. Returns 404 if the browser session does
5255
* not exist. If telemetry was not enabled on the session, the stream opens but no
5356
* events are delivered. Fresh connections only see new events; pass replay=all to
@@ -4996,6 +4999,17 @@ export interface TelemetryStreamParams {
49964999
*/
49975000
replay?: string;
49985001

5002+
/**
5003+
* Query param: Deliver only these event types, such as captcha_solve_started or
5004+
* captcha_challenge_result. Repeat the parameter or pass comma-separated values
5005+
* for multiple types. Keepalive frames are always delivered. Filtered-out events
5006+
* are not sent. An id-only frame carrying the latest skipped id is sent about
5007+
* every 15 seconds while skipped events keep arriving, and otherwise with the next
5008+
* keepalive or when the stream ends, so the connection stays active and
5009+
* Last-Event-ID moves past them; a reconnect resumes after the skipped events.
5010+
*/
5011+
type?: Array<string>;
5012+
49995013
/**
50005014
* Header param: Last event sequence number for SSE reconnection (sent by SSE
50015015
* clients on reconnect). Takes precedence over replay when both are present, so

‎tests/api-resources/browsers/telemetry.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ describe('resource telemetry', () => {
5858
await expect(
5959
client.browsers.telemetry.stream(
6060
'htzv5orfit78e1m2biiifpbv',
61-
{ replay: 'replay', 'Last-Event-ID': 'Last-Event-ID' },
61+
{
62+
replay: 'replay',
63+
type: ['string'],
64+
'Last-Event-ID': 'Last-Event-ID',
65+
},
6266
{ path: '/_stainless_unknown_path' },
6367
),
6468
).rejects.toThrow(Kernel.NotFoundError);

0 commit comments

Comments
 (0)