Skip to content

Commit 6b7e41c

Browse files
authored
Merge branch 'master' into romaingd-spi/strip-log-record-name
2 parents c76fc10 + 4420c4d commit 6b7e41c

File tree

19 files changed

+194
-89
lines changed

19 files changed

+194
-89
lines changed

.github/workflows/test-integrations-tasks.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ jobs:
4646
allow-prereleases: true
4747
- name: Start Redis
4848
uses: supercharge/[email protected]
49+
- name: Install Java
50+
uses: actions/setup-java@v4
51+
with:
52+
distribution: 'temurin'
53+
java-version: '21'
4954
- name: Setup Test Env
5055
run: |
5156
pip install "coverage[toml]" tox
@@ -135,6 +140,11 @@ jobs:
135140
allow-prereleases: true
136141
- name: Start Redis
137142
uses: supercharge/[email protected]
143+
- name: Install Java
144+
uses: actions/setup-java@v4
145+
with:
146+
distribution: 'temurin'
147+
java-version: '21'
138148
- name: Setup Test Env
139149
run: |
140150
pip install "coverage[toml]" tox

scripts/populate_tox/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@
5858
"pytest-django",
5959
"Werkzeug",
6060
],
61-
">=3.0": ["pytest-asyncio"],
61+
">=2.0": ["channels[daphne]"],
6262
">=2.2,<3.1": ["six"],
63+
">=3.0": ["pytest-asyncio"],
6364
"<3.3": [
6465
"djangorestframework>=3.0,<4.0",
6566
"Werkzeug<2.1.0",
6667
],
6768
"<3.1": ["pytest-django<4.0"],
68-
">=2.0": ["channels[daphne]"],
6969
},
7070
},
7171
"dramatiq": {

scripts/populate_tox/tox.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ deps =
172172
# for justification of the upper bound on pytest
173173
{py3.6,py3.7}-gevent: pytest<7.0.0
174174
{py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: pytest
175+
gevent: pytest-asyncio
175176
176177
# === Integrations ===
177178
@@ -362,6 +363,7 @@ setenv =
362363
py3.6: COVERAGE_RCFILE=.coveragerc36
363364
364365
django: DJANGO_SETTINGS_MODULE=tests.integrations.django.myapp.settings
366+
spark-v{3.0.3,3.5.6}: JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64
365367
366368
common: TESTPATH=tests
367369
gevent: TESTPATH=tests

scripts/split_tox_gh_actions/split_tox_gh_actions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
"aws_lambda",
4848
}
4949

50+
FRAMEWORKS_NEEDING_JAVA = {
51+
"spark",
52+
}
53+
5054
# Frameworks grouped here will be tested together to not hog all GitHub runners.
5155
# If you add or remove a group, make sure to git rm the generated YAML file as
5256
# well.
@@ -288,6 +292,7 @@ def render_template(group, frameworks, py_versions_pinned, py_versions_latest):
288292
"needs_docker": bool(set(frameworks) & FRAMEWORKS_NEEDING_DOCKER),
289293
"needs_postgres": bool(set(frameworks) & FRAMEWORKS_NEEDING_POSTGRES),
290294
"needs_redis": bool(set(frameworks) & FRAMEWORKS_NEEDING_REDIS),
295+
"needs_java": bool(set(frameworks) & FRAMEWORKS_NEEDING_JAVA),
291296
"py_versions": {
292297
category: [f'"{version}"' for version in _normalize_py_versions(versions)]
293298
for category, versions in py_versions.items()

scripts/split_tox_gh_actions/templates/test_group.jinja

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
with:
4949
python-version: {% raw %}${{ matrix.python-version }}{% endraw %}
5050
allow-prereleases: true
51+
5152
{% if needs_clickhouse %}
5253
- name: "Setup ClickHouse Server"
5354
uses: getsentry/[email protected]
@@ -58,6 +59,14 @@
5859
uses: supercharge/[email protected]
5960
{% endif %}
6061

62+
{% if needs_java %}
63+
- name: Install Java
64+
uses: actions/setup-java@v4
65+
with:
66+
distribution: 'temurin'
67+
java-version: '21'
68+
{% endif %}
69+
6170
- name: Setup Test Env
6271
run: |
6372
pip install "coverage[toml]" tox

sentry_sdk/_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class SDKInfo(TypedDict):
170170
"contexts": dict[str, dict[str, object]],
171171
"dist": str,
172172
"duration": Optional[float],
173-
"environment": str,
173+
"environment": Optional[str],
174174
"errors": list[dict[str, Any]], # TODO: We can expand on this type
175175
"event_id": str,
176176
"exception": dict[
@@ -188,7 +188,7 @@ class SDKInfo(TypedDict):
188188
"monitor_slug": Optional[str],
189189
"platform": Literal["python"],
190190
"profile": object, # Should be sentry_sdk.profiler.Profile, but we can't import that here due to circular imports
191-
"release": str,
191+
"release": Optional[str],
192192
"request": dict[str, object],
193193
"sdk": Mapping[str, object],
194194
"server_name": str,

sentry_sdk/client.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import TYPE_CHECKING, List, Dict, cast, overload
99
import warnings
1010

11+
import sentry_sdk
1112
from sentry_sdk._compat import PY37, check_uwsgi_thread_support
1213
from sentry_sdk.utils import (
1314
AnnotatedValue,
@@ -215,8 +216,8 @@ def capture_event(self, *args, **kwargs):
215216
# type: (*Any, **Any) -> Optional[str]
216217
return None
217218

218-
def _capture_experimental_log(self, scope, log):
219-
# type: (Scope, Log) -> None
219+
def _capture_experimental_log(self, log):
220+
# type: (Log) -> None
220221
pass
221222

222223
def capture_session(self, *args, **kwargs):
@@ -893,12 +894,14 @@ def capture_event(
893894

894895
return return_value
895896

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
898899
logs_enabled = self.options["_experiments"].get("enable_logs", False)
899900
if not logs_enabled:
900901
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()
902905

903906
log["attributes"]["sentry.sdk.name"] = SDK_INFO["name"]
904907
log["attributes"]["sentry.sdk.version"] = SDK_INFO["version"]
@@ -927,6 +930,21 @@ def _capture_experimental_log(self, current_scope, log):
927930
elif propagation_context is not None:
928931
log["trace_id"] = propagation_context.trace_id
929932

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+
930948
# If debug is enabled, log the log to the console
931949
debug = self.options.get("debug", False)
932950
if debug:

sentry_sdk/integrations/arq.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ def _sentry_create_worker(*args, **kwargs):
214214
]
215215
if hasattr(settings_cls, "cron_jobs"):
216216
settings_cls.cron_jobs = [
217-
_get_arq_cron_job(cron_job) for cron_job in settings_cls.cron_jobs
217+
_get_arq_cron_job(cron_job)
218+
for cron_job in (settings_cls.cron_jobs or [])
218219
]
219220

220221
if "functions" in kwargs:

sentry_sdk/integrations/django/asgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ async def __acall__(self, *args, **kwargs):
237237
middleware_span = _check_middleware_span(old_method=f)
238238

239239
if middleware_span is None:
240-
return await f(*args, **kwargs)
240+
return await f(*args, **kwargs) # type: ignore
241241

242242
with middleware_span:
243-
return await f(*args, **kwargs)
243+
return await f(*args, **kwargs) # type: ignore
244244

245245
return SentryASGIMixin

sentry_sdk/integrations/logging.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ def emit(self, record):
355355

356356
def _capture_log_from_record(self, client, record):
357357
# type: (BaseClient, LogRecord) -> None
358-
scope = sentry_sdk.get_current_scope()
359358
otel_severity_number, otel_severity_text = _python_level_to_otel(record.levelno)
360359
project_root = client.options["project_root"]
361360
attrs = self._extra_from_record(record) # type: Any
@@ -397,7 +396,6 @@ def _capture_log_from_record(self, client, record):
397396

398397
# noinspection PyProtectedMember
399398
client._capture_experimental_log(
400-
scope,
401399
{
402400
"severity_text": otel_severity_text,
403401
"severity_number": otel_severity_number,

0 commit comments

Comments
 (0)