Skip to content
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

ref(toolbar): check queryReferrer from query param and refactor tests for readability #79220

Merged
merged 5 commits into from
Oct 17, 2024

Conversation

aliu39
Copy link
Member

@aliu39 aliu39 commented Oct 16, 2024

Follow-up to #78778

Confirmed with Ryan the toolbar sends queryReferrer as a query param, not a HTTP header. For ex, <path>/?queryReferrer=devtoolbar. For SQL query convenience, the analytics event will exclude this from the query string.

Also refactors tests for better readability, removing the helper in the unit test class completely.

Also marks some more fields as required=False in the event definition. We need this for user_id in case of unauthenticated or anonymous requests. Note events with null user_id won't be sent to amplitude. Fixes SENTRY-3GMT

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 16, 2024
@aliu39 aliu39 requested a review from ryan953 October 16, 2024 19:30
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #79220      +/-   ##
==========================================
- Coverage   78.27%   78.26%   -0.01%     
==========================================
  Files        7137     7136       -1     
  Lines      314581   314610      +29     
  Branches    51361    51368       +7     
==========================================
+ Hits       246225   246244      +19     
- Misses      61906    61915       +9     
- Partials     6450     6451       +1     

Comment on lines 48 to 53
query_string = get_query_string(request) or None
if query_string:
params = query_string.lstrip("?").split("&")
params = list(filter(lambda s: s != "queryReferrer=devtoolbar", params))
query_string = f"?{'&'.join(params)}" if params else None

Copy link
Member

Choose a reason for hiding this comment

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

what's going on here?

Copy link
Member Author

Choose a reason for hiding this comment

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

From description:

For SQL query convenience, the analytics event will exclude this from the query string.

It finds the "queryReferrer=devtoolbar" in the query string and scrubs it out

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need that for query convenience? What will queries look like with or without it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm ok thinking about it now, I don't think there's a guarantee on the positioning of params, so our queries would look like WHERE query_string LIKE '%key=val%' regardless. So this doesn't make queries more convenient.

This does reduce the amount of data stored though. Lmk if you want to keep it or not, I don't have a preference anymore

Copy link
Member

Choose a reason for hiding this comment

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

we could chop it out and keep the code simple. if we need something like that later it can be added back in.

@aliu39 aliu39 merged commit 20495aa into master Oct 17, 2024
50 checks passed
@aliu39 aliu39 deleted the aliu/ref-api-analytics branch October 17, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants