|
24 | 24 | ClientConstructor, |
25 | 25 | ) |
26 | 26 | from sentry_sdk.data_collection import ( |
27 | | - OFF_DATA_COLLECTION, |
28 | | - DataCollection, |
29 | 27 | _map_from_send_default_pii, |
30 | 28 | resolve_data_collection, |
31 | 29 | ) |
|
76 | 74 | from sentry_sdk._log_batcher import LogBatcher |
77 | 75 | from sentry_sdk._metrics_batcher import MetricsBatcher |
78 | 76 | from sentry_sdk._types import ( |
| 77 | + DataCollection, |
79 | 78 | Event, |
80 | 79 | EventDataCategory, |
81 | 80 | Hint, |
@@ -355,7 +354,7 @@ def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]": |
355 | 354 |
|
356 | 355 | if rv["event_scrubber"] is None: |
357 | 356 | rv["event_scrubber"] = EventScrubber( |
358 | | - send_default_pii=rv["data_collection"].user_info |
| 357 | + send_default_pii=rv["data_collection"]["user_info"] |
359 | 358 | ) |
360 | 359 |
|
361 | 360 | if rv["socket_options"] and not isinstance(rv["socket_options"], list): |
@@ -392,6 +391,12 @@ def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]": |
392 | 391 | # Older Python versions |
393 | 392 | module_not_found_error = ImportError # type: ignore |
394 | 393 |
|
| 394 | +_DISABLED_DATA_COLLECTION_CONFIG = _map_from_send_default_pii( |
| 395 | + send_default_pii=False, |
| 396 | + include_local_variables=True, |
| 397 | + include_source_context=True, |
| 398 | +) |
| 399 | + |
395 | 400 |
|
396 | 401 | class BaseClient: |
397 | 402 | """ |
@@ -433,20 +438,7 @@ def should_send_default_pii(self) -> bool: |
433 | 438 |
|
434 | 439 | @property |
435 | 440 | def data_collection(self) -> "DataCollection": |
436 | | - return OFF_DATA_COLLECTION |
437 | | - |
438 | | - def should_collect_user_info(self) -> bool: |
439 | | - return False |
440 | | - |
441 | | - def should_collect_gen_ai_inputs( |
442 | | - self, include_prompts: "Optional[bool]" = None |
443 | | - ) -> bool: |
444 | | - return False |
445 | | - |
446 | | - def should_collect_gen_ai_outputs( |
447 | | - self, include_prompts: "Optional[bool]" = None |
448 | | - ) -> bool: |
449 | | - return False |
| 441 | + return _DISABLED_DATA_COLLECTION_CONFIG |
450 | 442 |
|
451 | 443 | def is_active(self) -> bool: |
452 | 444 | """ |
@@ -639,14 +631,16 @@ def _record_lost_event( |
639 | 631 | self.options["profiles_sampler"] = sample_all |
640 | 632 | # data_collection was resolved in _get_options() before this |
641 | 633 | # spotlight override flipped send_default_pii on. Re-derive it so |
642 | | - # the should_collect_* accessors agree with should_send_default_pii() |
643 | | - # in DSN-less spotlight mode (only when the user did not set |
| 634 | + # data_collection agrees with should_send_default_pii() in |
| 635 | + # DSN-less spotlight mode (only when the user did not set |
644 | 636 | # data_collection explicitly). |
645 | | - if not self.options["data_collection"].explicit: |
| 637 | + if not self.options["data_collection"]["provided_by_user"]: |
646 | 638 | self.options["data_collection"] = _map_from_send_default_pii( |
647 | | - True, |
648 | | - self.options["include_local_variables"] is not False, |
649 | | - self.options["include_source_context"] is not False, |
| 639 | + send_default_pii=True, |
| 640 | + include_local_variables=self.options["include_local_variables"] |
| 641 | + is not False, |
| 642 | + include_source_context=self.options["include_source_context"] |
| 643 | + is not False, |
650 | 644 | ) |
651 | 645 |
|
652 | 646 | self.session_flusher = SessionFlusher(capture_func=_capture_envelope) |
@@ -764,52 +758,7 @@ def data_collection(self) -> "DataCollection": |
764 | 758 | Returns the resolved :class:`~sentry_sdk.data_collection.DataCollection` |
765 | 759 | config for this client. |
766 | 760 | """ |
767 | | - dc = self.options.get("data_collection") |
768 | | - return dc if dc is not None else OFF_DATA_COLLECTION |
769 | | - |
770 | | - def should_collect_user_info(self) -> bool: |
771 | | - """ |
772 | | - Returns whether the SDK should automatically populate ``user.*`` fields |
773 | | - (id, email, username, ip_address) from instrumentation. |
774 | | - """ |
775 | | - return bool(self.data_collection.user_info) |
776 | | - |
777 | | - def should_collect_gen_ai_inputs( |
778 | | - self, include_prompts: "Optional[bool]" = None |
779 | | - ) -> bool: |
780 | | - """ |
781 | | - Returns whether the SDK should collect generative AI input content. |
782 | | -
|
783 | | - ``include_prompts`` is the integration-level override (if set, it takes |
784 | | - precedence over the global ``data_collection.gen_ai.inputs`` setting). |
785 | | - """ |
786 | | - return self._should_collect_gen_ai_content("inputs", include_prompts) |
787 | | - |
788 | | - def should_collect_gen_ai_outputs( |
789 | | - self, include_prompts: "Optional[bool]" = None |
790 | | - ) -> bool: |
791 | | - """ |
792 | | - Returns whether the SDK should collect generative AI output content. |
793 | | -
|
794 | | - ``include_prompts`` is the integration-level override (if set, it takes |
795 | | - precedence over the global ``data_collection.gen_ai.outputs`` setting). |
796 | | - """ |
797 | | - return self._should_collect_gen_ai_content("outputs", include_prompts) |
798 | | - |
799 | | - def _should_collect_gen_ai_content( |
800 | | - self, direction: str, include_prompts: "Optional[bool]" |
801 | | - ) -> bool: |
802 | | - dc = self.data_collection |
803 | | - if dc.explicit: |
804 | | - # Integration-level override wins over the global gen_ai setting. |
805 | | - if include_prompts is not None: |
806 | | - return include_prompts |
807 | | - return bool(getattr(dc.gen_ai, direction)) |
808 | | - # Legacy (data_collection not set): preserve the historical gate |
809 | | - # `should_send_default_pii() and integration.include_prompts`. |
810 | | - # `include_prompts is None` means "no integration-level override", which |
811 | | - # falls back to the legacy default of True (collect when PII is on). |
812 | | - return self.should_send_default_pii() and (include_prompts is not False) |
| 761 | + return self.options["data_collection"] |
813 | 762 |
|
814 | 763 | @property |
815 | 764 | def dsn(self) -> "Optional[str]": |
|
0 commit comments