Skip to content

feat(wsgi): Migrate to span first#5988

Draft
sentrivana wants to merge 30 commits intomasterfrom
ivana/migrate-wsgi-to-span-first
Draft

feat(wsgi): Migrate to span first#5988
sentrivana wants to merge 30 commits intomasterfrom
ivana/migrate-wsgi-to-span-first

Conversation

@sentrivana
Copy link
Copy Markdown
Contributor

@sentrivana sentrivana commented Apr 13, 2026

Description

Make the WSGI integration span first ready.

Also, set an additional attribute (user.ip_address) in ASGI.

Issues

Reminders

Base automatically changed from ivana/migrate-asgi-event-processor to master April 13, 2026 13:41
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Codecov Results 📊

25 failed | Total: 25 | Pass Rate: 0% | Execution Time: 1m 23s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +20
Passed Tests 📉 -5
Failed Tests 📈 +25
Skipped Tests

➕ New Tests (25)

View new tests
  • test_basic_no_exception
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_basic_exception
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_init_error
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_timeout_error
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_timeout_error_scope_modified
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_non_dict_event[event as integer]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_non_dict_event[event as float]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_non_dict_event[event as string]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_non_dict_event[event as bool]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_non_dict_event[event as list of dicts]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_non_dict_event[event as dict]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_non_dict_event[event as empty list]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_request_data
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_trace_continuation
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_headers[no headers]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_headers[none headers]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_headers[empty string headers]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_headers[empty dict headers]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_headers[empty list headers]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_span_origin
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_traces_sampler_has_correct_sampling_context
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_error_has_new_trace_context[RaiseErrorPerformanceEnabled]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_error_has_new_trace_context[RaiseErrorPerformanceDisabled]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_error_has_existing_trace_context[RaiseErrorPerformanceEnabled]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing
  • test_error_has_existing_trace_context[RaiseErrorPerformanceDisabled]
    • File: tests.integrations.aws_lambda.test_aws_lambda
    • Status: ❌ Failing

❌ Failed Tests

test_basic_no_exception

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 1, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:118: in test_basic_no_exception
    (transaction_event,) = envelopes
    ^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 1, got 0)

test_basic_exception

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:158: in test_basic_exception
    (error_event, _) = envelopes
    ^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_init_error

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:197: in test_init_error
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_timeout_error

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 1, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:212: in test_timeout_error
    (error_event,) = envelopes
    ^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 1, got 0)

test_timeout_error_scope_modified

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 1, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:233: in test_timeout_error_scope_modified
    (error_event,) = envelopes
    ^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 1, got 0)

test_non_dict_event[event as integer]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:323: in test_non_dict_event
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_non_dict_event[event as float]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:323: in test_non_dict_event
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_non_dict_event[event as string]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:323: in test_non_dict_event
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_non_dict_event[event as bool]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:323: in test_non_dict_event
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_non_dict_event[event as list of dicts]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:323: in test_non_dict_event
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_non_dict_event[event as dict]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:323: in test_non_dict_event
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_non_dict_event[event as empty list]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:323: in test_non_dict_event
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_request_data

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 1, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:392: in test_request_data
    (transaction_event,) = envelopes
    ^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 1, got 0)

test_trace_continuation

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:426: in test_trace_continuation
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_headers[no headers]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:459: in test_headers
    (error_event, _) = envelopes
    ^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_headers[none headers]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:459: in test_headers
    (error_event, _) = envelopes
    ^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_headers[empty string headers]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:459: in test_headers
    (error_event, _) = envelopes
    ^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_headers[empty dict headers]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:459: in test_headers
    (error_event, _) = envelopes
    ^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_headers[empty list headers]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:459: in test_headers
    (error_event, _) = envelopes
    ^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_span_origin

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 1, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:473: in test_span_origin
    (transaction_event,) = envelopes
    ^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 1, got 0)

test_traces_sampler_has_correct_sampling_context

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: KeyError: 'body'

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:491: in test_traces_sampler_has_correct_sampling_context
    sampling_context_data = json.loads(response_payload["body"])[
                                       ^^^^^^^^^^^^^^^^^^^^^^^^
E   KeyError: 'body'

test_error_has_new_trace_context[RaiseErrorPerformanceEnabled]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:513: in test_error_has_new_trace_context
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_error_has_new_trace_context[RaiseErrorPerformanceDisabled]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 1, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:515: in test_error_has_new_trace_context
    (error_event,) = envelopes
    ^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 1, got 0)

test_error_has_existing_trace_context[RaiseErrorPerformanceEnabled]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 2, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:557: in test_error_has_existing_trace_context
    (error_event, transaction_event) = envelopes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 2, got 0)

test_error_has_existing_trace_context[RaiseErrorPerformanceDisabled]

File: tests.integrations.aws_lambda.test_aws_lambda
Suite: py3.13-aws_lambda
Error: ValueError: not enough values to unpack (expected 1, got 0)

Stack Trace
tests/integrations/aws_lambda/test_aws_lambda.py:559: in test_error_has_existing_trace_context
    (error_event,) = envelopes
    ^^^^^^^^^^^^^^
E   ValueError: not enough values to unpack (expected 1, got 0)

❌ Patch coverage is 0.00%. Project has 19222 uncovered lines.
❌ Project coverage is 9.9%. Comparing base (base) to head (head).

Files with missing lines (4)
File Patch % Lines
scope.py 26.73% ⚠️ 636 Missing and 10 partials
_wsgi_common.py 0.00% ⚠️ 160 Missing
wsgi.py 0.00% ⚠️ 155 Missing
_asgi_common.py 0.00% ⚠️ 73 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    21.06%     9.90%   -11.16%
==========================================
  Files          191       191         —
  Lines        21281     21334       +53
  Branches      7006      7034       +28
==========================================
+ Hits          4481      2112     -2369
- Misses       16800     19222     +2422
- Partials       345        22      -323

Generated by Codecov Action

@github-actions
Copy link
Copy Markdown
Contributor

Codecov Results 📊

49 passed | ⏭️ 3 skipped | Total: 52 | Pass Rate: 94.23% | Execution Time: 12.36s

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 7.81%. Project has 15640 uncovered lines.
❌ Project coverage is 26.7%. Comparing base (base) to head (head).

Files with missing lines (5)
File Patch % Lines
scope.py 61.75% ⚠️ 332 Missing and 73 partials
asgi.py 15.38% ⚠️ 176 Missing
wsgi.py 20.65% ⚠️ 123 Missing
_wsgi_common.py 23.75% ⚠️ 122 Missing
_asgi_common.py 13.70% ⚠️ 63 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    26.75%    26.70%    -0.05%
==========================================
  Files          191       191         —
  Lines        21281     21336       +55
  Branches      7006      7036       +30
==========================================
+ Hits          5692      5696        +4
- Misses       15589     15640       +51
- Partials       490       490         —

Generated by Codecov Action

import sentry_sdk
from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE
from sentry_sdk._werkzeug import _get_headers
from sentry_sdk.integrations.wsgi import get_client_ip, get_request_url
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Circular import between wsgi.py and _wsgi_common.py will cause ImportError at runtime

The new import from sentry_sdk.integrations.wsgi import get_client_ip, get_request_url creates a circular dependency. wsgi.py imports _get_request_attributes from _wsgi_common.py (line 12 in wsgi.py), while _wsgi_common.py now imports from wsgi.py. When wsgi.py is loaded first, it will fail because _wsgi_common.py will try to import symbols from wsgi.py before they're defined. This will cause an ImportError or AttributeError at runtime.

Verification

Read both wsgi.py (lines 1-20) and _wsgi_common.py (lines 1-15) to confirm the import structure. wsgi.py imports _get_request_attributes from _wsgi_common.py at line 12. _wsgi_common.py now imports get_client_ip and get_request_url from wsgi.py at line 8. This is a classic circular import pattern that will fail at runtime.

Identified by Warden code-review · RW9-LXB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant