Skip to content

fix(integrations): ASGI integration not capture transactions in Websocket #4293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2025

Conversation

guodong000
Copy link
Contributor

fix(integrations): ASGI integration not capture transactions in Websocket

In ASGI Specs, method is not in Websocket Connection Scope.

@guodong000 guodong000 requested a review from a team as a code owner April 14, 2025 17:16
@guodong000 guodong000 changed the title Fix ASGI integration not capture transactions in Websocket fix(integrations): ASGI integration not capture transactions in Websocket Apr 14, 2025
@sentrivana
Copy link
Contributor

Hey @guodong000, thank you for this fix -- the current behavior definitely looks incorrect.

I'd strongly suggest we add a test case for this so that we don't regress (if we had this in the first place, this never would have broken). Do you have some time to add one to tests/integrations/test_asgi.py? There's already a test_websocket in the file that tests whether we capture errors -- this can likely be used as a base to create a new test case for testing transactions with some small effort.

Let me know -- if you don't have the time we can take care of it.

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.30%. Comparing base (a3d4b89) to head (c963b6f).
Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
sentry_sdk/integrations/asgi.py 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4293      +/-   ##
==========================================
+ Coverage   79.50%   80.30%   +0.79%     
==========================================
  Files         142      142              
  Lines       15907    15926      +19     
  Branches     2723     2725       +2     
==========================================
+ Hits        12647    12789     +142     
+ Misses       2391     2262     -129     
- Partials      869      875       +6     
Files with missing lines Coverage Δ
sentry_sdk/integrations/asgi.py 85.91% <40.00%> (+0.09%) ⬆️

... and 11 files with indirect coverage changes

@guodong000
Copy link
Contributor Author

guodong000 commented Apr 15, 2025

I found that the test_websocket has some issues and fixed it.

I checked the code of async-asgi-testclient, The TestClient actually uses the Lifespan protocol in context manager methods.

Then I added some related assertions.

@sentrivana
Copy link
Contributor

Can't comment on the specific line because it's not part of the diff but you probably need to change the sentry_init in the test to

sentry_init(send_default_pii=True, traces_sample_rate=1.0)

And then you should (if everything is working) actually get a separate transaction event here in addition to the message and the error. As is, the test is checking whether the message is associated with a transaction, but not if a transaction event is actually being emitted.

@guodong000
Copy link
Contributor Author

@sentrivana I have made the changes according to your suggestions. Please take a look.

Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

Thank you @guodong000!

@sentrivana sentrivana merged commit b96e2b6 into getsentry:master Apr 22, 2025
140 of 141 checks passed
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