breakpoints/debug printing for Django ASGI investigation #3164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem (see #3142) is as follows: We expect there to be three events in the test, but right now (in master), the test verifies only that we have two events, with the transaction missing. So, we want to find out what happens with the transaction.
The lack of transaction seems unique to the testing environment – when I tried to reproduce with a similar setup outside of a testing environment, I saw transactions as expected in Sentry. Therefore, it appears that either no transaction is created during testing, or we somehow fail to capture the transaction in the TestTransport that we use for the
capture_events
fixture.I have tried placing breakpoints in many different places, but have still struggled to figure out the root cause for the strange behavior. In this PR, I have included two breakpoints that cause unexpected behavior. The first breakpoint we have is one in the
__exit__
of a span; if the code is run as is withtox -e py3.12-django-latest -- tests/integrations/django/asgi/test_asgi.py::test_trace_from_headers_if_performance_enabled
, we hit that breakpoint three times (perhaps, because we have spans as well as a transaction). Then, we will end up inside the second breakpoint incapture_event
. Since this breakpoint is inside anif is_transaction
block, we know that we are about to capture the transaction. If we step through the transportcapture_envelope
call, we see that we correctly add the transaction event to the events list. However, when we continue from this last breakpoint, the test fails with an asyncioTimeoutError
.If we comment out the breakpoint in
Span.__exit__
, however, we do not hit the breakpoint incapture_event
at all, suggesting that for whatever reason the transaction does not get captured in this case. We end up failing with the assertion error, since there are only two, rather than three, events in the test. No asyncio TimeoutError in this case.I am not really sure yet what to make of all this strange behavior, but I guess asyncio somehow prevents the transaction from being captured in our tests