|
22 | 22 | ``DeprecationWarning`` is emitted for ``send_default_pii``. |
23 | 23 | """ |
24 | 24 |
|
25 | | -import warnings |
26 | | -from typing import TYPE_CHECKING, List, Mapping, Optional, Union, cast |
| 25 | +from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, Union, cast |
27 | 26 | from urllib.parse import parse_qs, urlencode |
28 | 27 |
|
29 | 28 | from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE |
| 29 | +from sentry_sdk.utils import deprecation_warning |
30 | 30 |
|
31 | 31 | if TYPE_CHECKING: |
32 | | - from typing import Any, Dict |
33 | | - |
34 | 32 | from sentry_sdk._types import ( |
35 | 33 | DataCollection, |
36 | 34 | GenAICollectionBehaviour, |
@@ -190,29 +188,33 @@ def _map_from_send_default_pii( |
190 | 188 |
|
191 | 189 | def _resolve_explicit( |
192 | 190 | d: "dict[str, Any]", |
193 | | - include_local_variables: bool, |
194 | | - include_source_context: bool, |
195 | 191 | ) -> "DataCollection": |
196 | 192 | """ |
197 | 193 | Build a fully-resolved ``DataCollection`` from a user-supplied |
198 | 194 | ``data_collection`` dict, filling in spec defaults for any omitted or |
199 | | - partially-specified field. Frame fields fall back to the legacy |
200 | | - ``include_local_variables`` / ``include_source_context`` options when unset. |
| 195 | + partially-specified field. |
201 | 196 | """ |
202 | 197 | # frame_context_lines accepts an integer or a boolean fallback (spec: True |
203 | 198 | # -> platform default of 5, False -> 0). bool is a subclass of int, so |
204 | 199 | # coerce explicitly before treating it as a line count. |
205 | 200 | frame_context_lines = d.get("frame_context_lines") |
206 | 201 | if frame_context_lines is None: |
207 | | - frame_context_lines = ( |
208 | | - _DEFAULT_FRAME_CONTEXT_LINES if include_source_context else 0 |
209 | | - ) |
| 202 | + frame_context_lines = _DEFAULT_FRAME_CONTEXT_LINES |
210 | 203 | elif isinstance(frame_context_lines, bool): |
211 | 204 | frame_context_lines = _DEFAULT_FRAME_CONTEXT_LINES if frame_context_lines else 0 |
| 205 | + else: |
| 206 | + if not isinstance(frame_context_lines, int) or frame_context_lines < 0: |
| 207 | + raise ValueError( |
| 208 | + "Invalid `frame_context_lines` value: Must be 0 or greater." |
| 209 | + ) |
| 210 | + |
| 211 | + raw_stack_frame_variables = d.get("stack_frame_variables", True) |
| 212 | + stack_frame_variables: "Union[bool, KeyValueCollectionBehaviour]" |
212 | 213 |
|
213 | | - stack_frame_variables = d.get("stack_frame_variables") |
214 | | - if stack_frame_variables is None: |
215 | | - stack_frame_variables = include_local_variables |
| 214 | + if isinstance(raw_stack_frame_variables, dict): |
| 215 | + stack_frame_variables = _kvcb_from_value(raw_stack_frame_variables) |
| 216 | + else: |
| 217 | + stack_frame_variables = bool(raw_stack_frame_variables) |
216 | 218 |
|
217 | 219 | # http_bodies: omitted means "all valid types"; [] is the explicit opt-out. |
218 | 220 | http_bodies = d.get("http_bodies") |
@@ -315,16 +317,12 @@ def _resolve_data_collection(options: "Dict[str, Any]") -> "DataCollection": |
315 | 317 | ) |
316 | 318 | ) |
317 | 319 | if send_default_pii is not None: |
318 | | - warnings.warn( |
| 320 | + deprecation_warning( |
319 | 321 | "`send_default_pii` is deprecated and ignored when " |
320 | 322 | "`data_collection` is set.", |
321 | | - DeprecationWarning, |
322 | | - stacklevel=2, |
323 | 323 | ) |
324 | 324 | return _resolve_explicit( |
325 | 325 | user_dc, |
326 | | - include_local_variables, |
327 | | - include_source_context, |
328 | 326 | ) |
329 | 327 |
|
330 | 328 | return _map_from_send_default_pii( |
|
0 commit comments