Skip to content

Commit e06f55d

Browse files
committed
Merge branch 'master' into py-2534-identify-db-ops-related-to-cursor-iteration
2 parents 8674d1f + 1164b18 commit e06f55d

6 files changed

Lines changed: 5385 additions & 4415 deletions

File tree

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 833 additions & 422 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/populate_tox/populate_tox.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,13 @@ def fetch_package_dependencies(
202202
python_version: ThreadedVersion,
203203
) -> dict:
204204
"""Fetch package dependencies metadata from cache or, failing that, PyPI."""
205+
target = TEST_SUITE_CONFIG[integration]["package"]
205206
constraints = _get_dependency_probe_constraints(
206207
integration, version, python_version
207208
)
208-
constraints_hash = hashlib.md5("\n".join(constraints).encode("utf-8")).hexdigest()
209+
constraints_hash = hashlib.md5(
210+
"\n".join([target, *constraints]).encode("utf-8")
211+
).hexdigest()
209212
package_dependencies = _fetch_package_dependencies_from_cache(
210213
package, version, python_version, constraints_hash
211214
)
@@ -226,7 +229,7 @@ def fetch_package_dependencies(
226229
"-m",
227230
"pip",
228231
"install",
229-
f"{package}=={version}",
232+
f"{target}=={version}",
230233
"--only-binary",
231234
"grpcio-tools", # Prevent source builds that hang CI. grpcio-tools is a build-time dependency pinned by apache-beam.
232235
"--dry-run",

scripts/populate_tox/releases.jsonl

Lines changed: 27 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sentry_sdk/integrations/pyramid.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,22 @@ def setup_once() -> None:
7575
def sentry_patched_call_view(
7676
registry: "Any", request: "Request", *args: "Any", **kwargs: "Any"
7777
) -> "Response":
78-
integration = sentry_sdk.get_client().get_integration(PyramidIntegration)
78+
client = sentry_sdk.get_client()
79+
integration = client.get_integration(PyramidIntegration)
7980
if integration is None:
8081
return old_call_view(registry, request, *args, **kwargs)
8182

8283
_set_transaction_name_and_source(
8384
sentry_sdk.get_current_scope(), integration.transaction_style, request
8485
)
86+
8587
scope = sentry_sdk.get_isolation_scope()
88+
89+
if should_send_default_pii() and has_span_streaming_enabled(client.options):
90+
user_id = authenticated_userid(request)
91+
if user_id:
92+
scope.set_user({"id": user_id})
93+
8694
scope.add_event_processor(
8795
_make_event_processor(weakref.ref(request), integration)
8896
)

tests/integrations/pyramid/test_pyramid.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,12 @@ def tracing_error(request):
527527

528528
@pytest.mark.parametrize("span_streaming", [True, False])
529529
def test_span_origin(
530-
sentry_init, capture_events, capture_items, get_client, span_streaming
530+
sentry_init,
531+
pyramid_config,
532+
capture_events,
533+
capture_items,
534+
get_client,
535+
span_streaming,
531536
):
532537
sentry_init(
533538
integrations=[PyramidIntegration()],
@@ -552,3 +557,42 @@ def test_span_origin(
552557
else:
553558
(_, event) = events
554559
assert event["contexts"]["trace"]["origin"] == "auto.http.pyramid"
560+
561+
562+
@pytest.mark.parametrize("send_default_pii", [True, False])
563+
def test_span_sets_user_id_on_segment(
564+
sentry_init,
565+
pyramid_config,
566+
capture_items,
567+
get_client,
568+
send_default_pii,
569+
):
570+
sentry_init(
571+
integrations=[PyramidIntegration()],
572+
traces_sample_rate=1.0,
573+
send_default_pii=send_default_pii,
574+
_experiments={"trace_lifecycle": "stream"},
575+
)
576+
577+
class AuthenticationPolicy:
578+
def authenticated_userid(self, request):
579+
return "123-abc"
580+
581+
pyramid_config.set_authorization_policy(ACLAuthorizationPolicy())
582+
pyramid_config.set_authentication_policy(AuthenticationPolicy())
583+
584+
items = capture_items("span")
585+
586+
client = get_client()
587+
client.get("/message")
588+
589+
sentry_sdk.flush()
590+
spans = [i.payload for i in items if i.type == "span"]
591+
592+
assert len(spans) == 1
593+
(segment,) = spans
594+
595+
if send_default_pii:
596+
assert segment["attributes"]["user.id"] == "123-abc"
597+
else:
598+
assert "user.id" not in segment["attributes"]

0 commit comments

Comments
 (0)