Skip to content

feat(sanic): Gate user info behind data_collection config#6870

Merged
ericapisani merged 6 commits into
masterfrom
py-2583-sanic-user-info
Jul 24, 2026
Merged

feat(sanic): Gate user info behind data_collection config#6870
ericapisani merged 6 commits into
masterfrom
py-2583-sanic-user-info

Conversation

@ericapisani

@ericapisani ericapisani commented Jul 23, 2026

Copy link
Copy Markdown
Member

Apply the data_collection.user_info setting to the Sanic integration's user IP collection, giving it precedence over the legacy send_default_pii boolean when explicitly configured. This covers both the user.ip_address scope attribute applied to all spans and the client.address span attribute, mirroring the behavior already shipped for Flask, WSGI, ASGI, and Django.

The user IP span test is reparametrized with the shared DATA_COLLECTION_USER_INFO_CASES matrix from tests/integrations/utils.py, and a new test covers the previously untested client.address span attribute.

Refs PY-2583
Refs #6746

@linear-code

linear-code Bot commented Jul 23, 2026

Copy link
Copy Markdown

PY-2583

@ericapisani ericapisani changed the title py 2583 sanic user info feat(sanic): Gate user info behind data_collection config Jul 23, 2026
@ericapisani
ericapisani marked this pull request as ready for review July 23, 2026 14:44
@ericapisani
ericapisani requested a review from a team as a code owner July 23, 2026 14:44
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

97062 passed | ⏭️ 6410 skipped | Total: 103472 | Pass Rate: 93.81% | Execution Time: 345m 52s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +110
Passed Tests 📈 +70
Failed Tests
Skipped Tests 📈 +40

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2510 uncovered lines.
❌ Project coverage is 89.69%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    89.70%    89.69%    -0.01%
==========================================
  Files          193       193         —
  Lines        24346     24353        +7
  Branches      8592      8602       +10
==========================================
+ Hits         21838     21843        +5
- Misses        2508      2510        +2
- Partials      1395      1395         —

Generated by Codecov Action

Apply the data_collection.user_info setting to Django user identity (id, email, username) collection, giving it precedence over the legacy send_default_pii boolean when explicitly configured. This mirrors the existing behavior for client IP/user info already shipped for Flask, WSGI, and ASGI.

The user extraction logic in _after_get_response is pulled into a shared helper used by both the WSGI and ASGI event processors, and the parametrized send_default_pii/data_collection test matrix is extracted into tests/integrations/django/utils.py for reuse across the WSGI and ASGI test suites.

Refs PY-2583
The new test was the only DB-touching test without @pytest.mark.forked. Running in the parent process leaked the created user into the shared in-memory sqlite DB (UNIQUE constraint failures in test_basic) and caused the parent to hold the session-scoped django_db_setup fixture, so forked children skipped postgres test DB creation but still destroyed it on teardown (database does not exist errors).
Move the identical USER_INFO_INIT_KWARGS parametrization from the flask, wsgi, and django test suites into tests/integrations/utils.py as DATA_COLLECTION_USER_INFO_CASES, documenting that the second element of each case is whether user info is expected to be collected.
Apply the data_collection.user_info setting to the Sanic integration's user IP collection, giving it precedence over the legacy send_default_pii boolean when explicitly configured. This covers both the user.ip_address scope attribute applied to all spans and the client.address span attribute, mirroring the behavior already shipped for Flask, WSGI, ASGI, and Django.

The user IP span test is reparametrized with the shared DATA_COLLECTION_USER_INFO_CASES matrix from tests/integrations/utils.py, and a new test covers the previously untested client.address span attribute.

Refs PY-2583
@ericapisani
ericapisani force-pushed the py-2583-django-user-info branch from 615580f to 4ee42d0 Compare July 23, 2026 18:15
@ericapisani
ericapisani force-pushed the py-2583-sanic-user-info branch from 4a557fc to 057caa4 Compare July 23, 2026 18:15
Base automatically changed from py-2583-django-user-info to master July 24, 2026 14:12

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b66f97a. Configure here.

Comment thread tests/integrations/django/test_data_scrubbing.py
@ericapisani
ericapisani merged commit 9c58360 into master Jul 24, 2026
140 checks passed
@ericapisani
ericapisani deleted the py-2583-sanic-user-info branch July 24, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants