Skip to content

Commit a7f5d9e

Browse files
feat: Add telemetry support for browser pools with BAA enforcement
1 parent 5a2b67d commit a7f5d9e

7 files changed

Lines changed: 298 additions & 8 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 127
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-92c776855f978ae03a778fbbac49bf1edc65852530644772c382838b6eab9fe5.yml
3-
openapi_spec_hash: 4a9fbcb607be408ad646e207fe90687f
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-e04362b2c82b88f4f7fb43209c764fa9fdf37fe98932e142547be43a1e99c50b.yml
3+
openapi_spec_hash: b16e79bfd6cac36090c815a8184b9e09
44
config_hash: 77ee715aa17061166f9a02b264a21b8d

src/kernel/resources/browser_pools.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, Iterable
5+
from typing import Dict, Iterable, Optional
66

77
import httpx
88

@@ -72,6 +72,7 @@ def create(
7272
refresh_on_profile_update: bool | Omit = omit,
7373
start_url: str | Omit = omit,
7474
stealth: bool | Omit = omit,
75+
telemetry: Optional[browser_pool_create_params.Telemetry] | Omit = omit,
7576
timeout_seconds: int | Omit = omit,
7677
viewport: BrowserViewport | Omit = omit,
7778
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -134,6 +135,13 @@ def create(
134135
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
135136
mechanisms. Defaults to false.
136137
138+
telemetry: Telemetry configuration applied to browsers warmed into this pool. Set enabled
139+
to true to start capture using the default set, or provide browser category
140+
settings. If omitted, null, set to an empty object ({}), set to enabled: false
141+
without browser category settings, or all four CDP categories are explicitly
142+
disabled, no telemetry is configured on the pool. Only applied to newly-warmed
143+
browsers.
144+
137145
timeout_seconds: Default idle timeout in seconds for browsers acquired from this pool before they
138146
are destroyed. Defaults to 600 seconds. Minimum 10, maximum 259200 (72 hours).
139147
@@ -174,6 +182,7 @@ def create(
174182
"refresh_on_profile_update": refresh_on_profile_update,
175183
"start_url": start_url,
176184
"stealth": stealth,
185+
"telemetry": telemetry,
177186
"timeout_seconds": timeout_seconds,
178187
"viewport": viewport,
179188
},
@@ -235,6 +244,7 @@ def update(
235244
size: int | Omit = omit,
236245
start_url: str | Omit = omit,
237246
stealth: bool | Omit = omit,
247+
telemetry: Optional[browser_pool_update_params.Telemetry] | Omit = omit,
238248
timeout_seconds: int | Omit = omit,
239249
viewport: BrowserViewport | Omit = omit,
240250
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -306,6 +316,14 @@ def update(
306316
307317
stealth: If provided, replaces whether browsers launch in stealth mode.
308318
319+
telemetry: If provided, updates the pool's telemetry configuration. Omit, set to null, or
320+
set to an empty object ({}) to leave the existing configuration unchanged. Set
321+
enabled to true to enable capture using the default set. Set enabled to false to
322+
clear the pool's telemetry. Provide browser category settings for per-category
323+
updates, merged onto the pool's current configuration. Only applied to browsers
324+
warmed after the update; browsers already in the pool keep their configuration
325+
until discarded.
326+
309327
timeout_seconds: If provided, replaces the default idle timeout in seconds for browsers acquired
310328
from this pool before they are destroyed. Minimum 10, maximum 259200 (72 hours).
311329
@@ -349,6 +367,7 @@ def update(
349367
"size": size,
350368
"start_url": start_url,
351369
"stealth": stealth,
370+
"telemetry": telemetry,
352371
"timeout_seconds": timeout_seconds,
353372
"viewport": viewport,
354373
},
@@ -468,6 +487,7 @@ def acquire(
468487
name: str | Omit = omit,
469488
start_url: str | Omit = omit,
470489
tags: TagsParam | Omit = omit,
490+
telemetry: Optional[browser_pool_acquire_params.Telemetry] | Omit = omit,
471491
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
472492
# The extra values given here take precedence over values defined on the client or passed to this method.
473493
extra_headers: Headers | None = None,
@@ -500,6 +520,15 @@ def acquire(
500520
find and group sessions later. Applies to this lease only and are cleared when
501521
the browser is released back to the pool. Up to 50 pairs.
502522
523+
telemetry: Telemetry override for the acquired browser, applied to this lease only. Merges
524+
onto the browser's current (pool-inherited) telemetry using the same
525+
per-category semantics as PATCH /browsers: provided categories override the
526+
current configuration, omitted categories are inherited. Set enabled to true to
527+
resolve the config fresh from the default set, or enabled to false to stop
528+
capture. When the browser is released back to the pool with reuse, its telemetry
529+
is reset to the pool's baseline, so the override does not carry over to the next
530+
lease.
531+
503532
extra_headers: Send extra headers
504533
505534
extra_query: Add additional query parameters to the request
@@ -518,6 +547,7 @@ def acquire(
518547
"name": name,
519548
"start_url": start_url,
520549
"tags": tags,
550+
"telemetry": telemetry,
521551
},
522552
browser_pool_acquire_params.BrowserPoolAcquireParams,
523553
),
@@ -650,6 +680,7 @@ async def create(
650680
refresh_on_profile_update: bool | Omit = omit,
651681
start_url: str | Omit = omit,
652682
stealth: bool | Omit = omit,
683+
telemetry: Optional[browser_pool_create_params.Telemetry] | Omit = omit,
653684
timeout_seconds: int | Omit = omit,
654685
viewport: BrowserViewport | Omit = omit,
655686
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -712,6 +743,13 @@ async def create(
712743
stealth: If true, launches the browser in stealth mode to reduce detection by anti-bot
713744
mechanisms. Defaults to false.
714745
746+
telemetry: Telemetry configuration applied to browsers warmed into this pool. Set enabled
747+
to true to start capture using the default set, or provide browser category
748+
settings. If omitted, null, set to an empty object ({}), set to enabled: false
749+
without browser category settings, or all four CDP categories are explicitly
750+
disabled, no telemetry is configured on the pool. Only applied to newly-warmed
751+
browsers.
752+
715753
timeout_seconds: Default idle timeout in seconds for browsers acquired from this pool before they
716754
are destroyed. Defaults to 600 seconds. Minimum 10, maximum 259200 (72 hours).
717755
@@ -752,6 +790,7 @@ async def create(
752790
"refresh_on_profile_update": refresh_on_profile_update,
753791
"start_url": start_url,
754792
"stealth": stealth,
793+
"telemetry": telemetry,
755794
"timeout_seconds": timeout_seconds,
756795
"viewport": viewport,
757796
},
@@ -813,6 +852,7 @@ async def update(
813852
size: int | Omit = omit,
814853
start_url: str | Omit = omit,
815854
stealth: bool | Omit = omit,
855+
telemetry: Optional[browser_pool_update_params.Telemetry] | Omit = omit,
816856
timeout_seconds: int | Omit = omit,
817857
viewport: BrowserViewport | Omit = omit,
818858
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -884,6 +924,14 @@ async def update(
884924
885925
stealth: If provided, replaces whether browsers launch in stealth mode.
886926
927+
telemetry: If provided, updates the pool's telemetry configuration. Omit, set to null, or
928+
set to an empty object ({}) to leave the existing configuration unchanged. Set
929+
enabled to true to enable capture using the default set. Set enabled to false to
930+
clear the pool's telemetry. Provide browser category settings for per-category
931+
updates, merged onto the pool's current configuration. Only applied to browsers
932+
warmed after the update; browsers already in the pool keep their configuration
933+
until discarded.
934+
887935
timeout_seconds: If provided, replaces the default idle timeout in seconds for browsers acquired
888936
from this pool before they are destroyed. Minimum 10, maximum 259200 (72 hours).
889937
@@ -927,6 +975,7 @@ async def update(
927975
"size": size,
928976
"start_url": start_url,
929977
"stealth": stealth,
978+
"telemetry": telemetry,
930979
"timeout_seconds": timeout_seconds,
931980
"viewport": viewport,
932981
},
@@ -1046,6 +1095,7 @@ async def acquire(
10461095
name: str | Omit = omit,
10471096
start_url: str | Omit = omit,
10481097
tags: TagsParam | Omit = omit,
1098+
telemetry: Optional[browser_pool_acquire_params.Telemetry] | Omit = omit,
10491099
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
10501100
# The extra values given here take precedence over values defined on the client or passed to this method.
10511101
extra_headers: Headers | None = None,
@@ -1078,6 +1128,15 @@ async def acquire(
10781128
find and group sessions later. Applies to this lease only and are cleared when
10791129
the browser is released back to the pool. Up to 50 pairs.
10801130
1131+
telemetry: Telemetry override for the acquired browser, applied to this lease only. Merges
1132+
onto the browser's current (pool-inherited) telemetry using the same
1133+
per-category semantics as PATCH /browsers: provided categories override the
1134+
current configuration, omitted categories are inherited. Set enabled to true to
1135+
resolve the config fresh from the default set, or enabled to false to stop
1136+
capture. When the browser is released back to the pool with reuse, its telemetry
1137+
is reset to the pool's baseline, so the override does not carry over to the next
1138+
lease.
1139+
10811140
extra_headers: Send extra headers
10821141
10831142
extra_query: Add additional query parameters to the request
@@ -1096,6 +1155,7 @@ async def acquire(
10961155
"name": name,
10971156
"start_url": start_url,
10981157
"tags": tags,
1158+
"telemetry": telemetry,
10991159
},
11001160
browser_pool_acquire_params.BrowserPoolAcquireParams,
11011161
),

src/kernel/types/browser_pool.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .._models import BaseModel
77
from .shared.browser_viewport import BrowserViewport
88
from .shared.browser_extension import BrowserExtension
9+
from .browsers.browser_telemetry_config import BrowserTelemetryConfig
910

1011
__all__ = ["BrowserPool", "BrowserPoolConfig", "BrowserPoolConfigProfile"]
1112

@@ -110,6 +111,12 @@ class BrowserPoolConfig(BaseModel):
110111
mechanisms.
111112
"""
112113

114+
telemetry: Optional[BrowserTelemetryConfig] = None
115+
"""
116+
Active telemetry configuration applied to browsers warmed into this pool, if
117+
any.
118+
"""
119+
113120
timeout_seconds: Optional[int] = None
114121
"""
115122
Default idle timeout in seconds for browsers acquired from this pool before they

src/kernel/types/browser_pool_acquire_params.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from __future__ import annotations
44

5+
from typing import Optional
56
from typing_extensions import TypedDict
67

78
from .tags_param import TagsParam
9+
from .browsers.browser_telemetry_categories_config_param import BrowserTelemetryCategoriesConfigParam
810

9-
__all__ = ["BrowserPoolAcquireParams"]
11+
__all__ = ["BrowserPoolAcquireParams", "Telemetry"]
1012

1113

1214
class BrowserPoolAcquireParams(TypedDict, total=False):
@@ -38,3 +40,49 @@ class BrowserPoolAcquireParams(TypedDict, total=False):
3840
find and group sessions later. Applies to this lease only and are cleared when
3941
the browser is released back to the pool. Up to 50 pairs.
4042
"""
43+
44+
telemetry: Optional[Telemetry]
45+
"""Telemetry override for the acquired browser, applied to this lease only.
46+
47+
Merges onto the browser's current (pool-inherited) telemetry using the same
48+
per-category semantics as PATCH /browsers: provided categories override the
49+
current configuration, omitted categories are inherited. Set enabled to true to
50+
resolve the config fresh from the default set, or enabled to false to stop
51+
capture. When the browser is released back to the pool with reuse, its telemetry
52+
is reset to the pool's baseline, so the override does not carry over to the next
53+
lease.
54+
"""
55+
56+
57+
class Telemetry(TypedDict, total=False):
58+
"""Telemetry override for the acquired browser, applied to this lease only.
59+
60+
Merges onto the browser's current (pool-inherited) telemetry using the same per-category semantics as PATCH /browsers: provided categories override the current configuration, omitted categories are inherited. Set enabled to true to resolve the config fresh from the default set, or enabled to false to stop capture. When the browser is released back to the pool with reuse, its telemetry is reset to the pool's baseline, so the override does not carry over to the next lease.
61+
"""
62+
63+
browser: BrowserTelemetryCategoriesConfigParam
64+
"""Per-category capture flags.
65+
66+
The operational categories (control, connection, system, captcha) are captured
67+
whenever telemetry is enabled; set one to enabled=false to opt out. The CDP
68+
categories (console, network, page, interaction) and screenshot are off by
69+
default; set enabled=true to opt in. On create, provided categories layer onto
70+
the default set. On update, provided categories merge onto the session's current
71+
config; when no telemetry is active this falls back to the default set (matching
72+
create). If browser is omitted or empty, the default set is used. A browser
73+
config that disables every category stops capture on update and starts no
74+
capture on create.
75+
"""
76+
77+
enabled: bool
78+
"""Request shortcut for browser telemetry capture.
79+
80+
True enables capture; with no browser category settings it captures the default
81+
set (control, connection, system, captcha), and any browser category settings
82+
are layered onto that default set. On update, enabled=true resolves the config
83+
fresh from the default set plus any provided categories, replacing the session's
84+
current selection rather than merging onto it; omit enabled to merge categories
85+
onto the current selection instead. False stops capture on update and starts no
86+
capture on create. enabled=false cannot be combined with browser category
87+
settings.
88+
"""

src/kernel/types/browser_pool_create_params.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, Iterable
5+
from typing import Dict, Iterable, Optional
66
from typing_extensions import Required, TypedDict
77

88
from .shared_params.browser_viewport import BrowserViewport
99
from .shared_params.browser_extension import BrowserExtension
10+
from .browsers.browser_telemetry_categories_config_param import BrowserTelemetryCategoriesConfigParam
1011

11-
__all__ = ["BrowserPoolCreateParams", "Profile"]
12+
__all__ = ["BrowserPoolCreateParams", "Profile", "Telemetry"]
1213

1314

1415
class BrowserPoolCreateParams(TypedDict, total=False):
@@ -90,6 +91,16 @@ class BrowserPoolCreateParams(TypedDict, total=False):
9091
mechanisms. Defaults to false.
9192
"""
9293

94+
telemetry: Optional[Telemetry]
95+
"""Telemetry configuration applied to browsers warmed into this pool.
96+
97+
Set enabled to true to start capture using the default set, or provide browser
98+
category settings. If omitted, null, set to an empty object ({}), set to
99+
enabled: false without browser category settings, or all four CDP categories are
100+
explicitly disabled, no telemetry is configured on the pool. Only applied to
101+
newly-warmed browsers.
102+
"""
103+
93104
timeout_seconds: int
94105
"""
95106
Default idle timeout in seconds for browsers acquired from this pool before they
@@ -130,3 +141,37 @@ class Profile(TypedDict, total=False):
130141
131142
Must be 1-255 characters, using letters, numbers, dots, underscores, or hyphens.
132143
"""
144+
145+
146+
class Telemetry(TypedDict, total=False):
147+
"""Telemetry configuration applied to browsers warmed into this pool.
148+
149+
Set enabled to true to start capture using the default set, or provide browser category settings. If omitted, null, set to an empty object ({}), set to enabled: false without browser category settings, or all four CDP categories are explicitly disabled, no telemetry is configured on the pool. Only applied to newly-warmed browsers.
150+
"""
151+
152+
browser: BrowserTelemetryCategoriesConfigParam
153+
"""Per-category capture flags.
154+
155+
The operational categories (control, connection, system, captcha) are captured
156+
whenever telemetry is enabled; set one to enabled=false to opt out. The CDP
157+
categories (console, network, page, interaction) and screenshot are off by
158+
default; set enabled=true to opt in. On create, provided categories layer onto
159+
the default set. On update, provided categories merge onto the session's current
160+
config; when no telemetry is active this falls back to the default set (matching
161+
create). If browser is omitted or empty, the default set is used. A browser
162+
config that disables every category stops capture on update and starts no
163+
capture on create.
164+
"""
165+
166+
enabled: bool
167+
"""Request shortcut for browser telemetry capture.
168+
169+
True enables capture; with no browser category settings it captures the default
170+
set (control, connection, system, captcha), and any browser category settings
171+
are layered onto that default set. On update, enabled=true resolves the config
172+
fresh from the default set plus any provided categories, replacing the session's
173+
current selection rather than merging onto it; omit enabled to merge categories
174+
onto the current selection instead. False stops capture on update and starts no
175+
capture on create. enabled=false cannot be combined with browser category
176+
settings.
177+
"""

0 commit comments

Comments
 (0)