|
8 | 8 | from typing import TYPE_CHECKING, List, Dict, cast, overload |
9 | 9 | import warnings |
10 | 10 |
|
| 11 | +import sentry_sdk |
11 | 12 | from sentry_sdk._compat import PY37, check_uwsgi_thread_support |
12 | 13 | from sentry_sdk.utils import ( |
13 | 14 | AnnotatedValue, |
@@ -215,8 +216,8 @@ def capture_event(self, *args, **kwargs): |
215 | 216 | # type: (*Any, **Any) -> Optional[str] |
216 | 217 | return None |
217 | 218 |
|
218 | | - def _capture_experimental_log(self, scope, log): |
219 | | - # type: (Scope, Log) -> None |
| 219 | + def _capture_experimental_log(self, log): |
| 220 | + # type: (Log) -> None |
220 | 221 | pass |
221 | 222 |
|
222 | 223 | def capture_session(self, *args, **kwargs): |
@@ -893,12 +894,14 @@ def capture_event( |
893 | 894 |
|
894 | 895 | return return_value |
895 | 896 |
|
896 | | - def _capture_experimental_log(self, current_scope, log): |
897 | | - # type: (Scope, Log) -> None |
| 897 | + def _capture_experimental_log(self, log): |
| 898 | + # type: (Log) -> None |
898 | 899 | logs_enabled = self.options["_experiments"].get("enable_logs", False) |
899 | 900 | if not logs_enabled: |
900 | 901 | return |
901 | | - isolation_scope = current_scope.get_isolation_scope() |
| 902 | + |
| 903 | + current_scope = sentry_sdk.get_current_scope() |
| 904 | + isolation_scope = sentry_sdk.get_isolation_scope() |
902 | 905 |
|
903 | 906 | log["attributes"]["sentry.sdk.name"] = SDK_INFO["name"] |
904 | 907 | log["attributes"]["sentry.sdk.version"] = SDK_INFO["version"] |
@@ -927,6 +930,21 @@ def _capture_experimental_log(self, current_scope, log): |
927 | 930 | elif propagation_context is not None: |
928 | 931 | log["trace_id"] = propagation_context.trace_id |
929 | 932 |
|
| 933 | + # The user, if present, is always set on the isolation scope. |
| 934 | + if self.should_send_default_pii() and isolation_scope._user is not None: |
| 935 | + for log_attribute, user_attribute in ( |
| 936 | + ("user.id", "id"), |
| 937 | + ("user.name", "username"), |
| 938 | + ("user.email", "email"), |
| 939 | + ): |
| 940 | + if ( |
| 941 | + user_attribute in isolation_scope._user |
| 942 | + and log_attribute not in log["attributes"] |
| 943 | + ): |
| 944 | + log["attributes"][log_attribute] = isolation_scope._user[ |
| 945 | + user_attribute |
| 946 | + ] |
| 947 | + |
930 | 948 | # If debug is enabled, log the log to the console |
931 | 949 | debug = self.options.get("debug", False) |
932 | 950 | if debug: |
|
0 commit comments