-
Notifications
You must be signed in to change notification settings - Fork 642
fix(tracing): Handle traces_sampler raising by falling back #6850
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
Changes from all commits
7541460
5e9f610
a590c8e
16ed0c8
486f0bc
7d14a81
bb98334
61d1618
951c408
a19be39
620e222
ec6f520
4dd3ba6
d0bae90
a6c4688
d7b378b
52c2da1
aa645d7
8b6e3ad
d717172
c7f590f
293a291
530e83c
326d796
e9f0e20
48f7c7b
621d79b
3d7bddb
fad2292
40d9f38
e6e7148
1f9bce7
fad0c9a
21cf40b
3f0bc2a
eee4ea2
3b17dd3
96e0ac0
c3baf08
ea22fc5
14652a9
57ef596
6918529
0f58e13
8c9f43d
b308065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,11 @@ | |
| from enum import Enum | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import sentry_sdk | ||
| from sentry_sdk.data_collection import _apply_data_collection_filtering_to_query_string | ||
| from sentry_sdk.integrations._wsgi_common import _filter_headers | ||
| from sentry_sdk.scope import should_send_default_pii | ||
| from sentry_sdk.utils import has_data_collection_enabled | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Any, Dict, Optional, Union | ||
|
|
@@ -75,7 +78,7 @@ | |
| return path | ||
|
|
||
|
|
||
| def _get_query(asgi_scope: "Any") -> "Any": | ||
| def _get_query(asgi_scope: "Any") -> "Optional[str]": | ||
| """ | ||
| Extract querystring from the ASGI scope, in the format that the Sentry protocol expects. | ||
| """ | ||
|
|
@@ -112,13 +115,30 @@ | |
| """ | ||
| request_data: "Dict[str, Any]" = {} | ||
| ty = asgi_scope["type"] | ||
| client_options = sentry_sdk.get_client().options | ||
| if ty in ("http", "websocket"): | ||
| request_data["method"] = asgi_scope.get("method") | ||
|
|
||
| request_data["headers"] = headers = _filter_headers( | ||
| _get_headers(asgi_scope), | ||
| headers = _get_headers(asgi_scope) | ||
|
|
||
| request_data["headers"] = _filter_headers( | ||
| headers, | ||
| use_annotated_value=False, | ||
| ) | ||
| request_data["query_string"] = _get_query(asgi_scope) | ||
|
|
||
| if has_data_collection_enabled(client_options): | ||
| qs = _get_query(asgi_scope) | ||
| if qs: | ||
| filtered_query_string = ( | ||
| _apply_data_collection_filtering_to_query_string( | ||
| query_string=qs, | ||
| behaviour=client_options["data_collection"]["url_query_params"], | ||
| ) | ||
| ) | ||
| if filtered_query_string: | ||
| request_data["query_string"] = filtered_query_string | ||
| else: | ||
| request_data["query_string"] = _get_query(asgi_scope) | ||
|
|
||
| request_data["url"] = _get_url( | ||
| asgi_scope, | ||
|
|
@@ -128,8 +148,12 @@ | |
| ) | ||
|
|
||
| client = asgi_scope.get("client") | ||
| if client and should_send_default_pii(): | ||
| request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)} | ||
| if client: | ||
| if has_data_collection_enabled(client_options): | ||
| if client_options["data_collection"]["user_info"]: | ||
| request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)} | ||
| elif should_send_default_pii(): | ||
| request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)} | ||
|
|
||
| return request_data | ||
|
|
||
|
|
@@ -148,34 +172,72 @@ | |
| if asgi_scope.get("method"): | ||
| attributes["http.request.method"] = asgi_scope["method"].upper() | ||
|
|
||
| headers = _filter_headers(_get_headers(asgi_scope), use_annotated_value=False) | ||
| for header, value in headers.items(): | ||
| headers = _get_headers(asgi_scope) | ||
|
|
||
| filtered_headers = _filter_headers(headers, use_annotated_value=False) | ||
| for header, value in filtered_headers.items(): | ||
| attributes[f"http.request.header.{header.lower()}"] = value | ||
|
|
||
| if should_send_default_pii(): | ||
| client_options = sentry_sdk.get_client().options | ||
| if has_data_collection_enabled(client_options): | ||
| filtered_query_string = None | ||
| query = _get_query(asgi_scope) | ||
|
|
||
| if query: | ||
| filtered_query_string = ( | ||
| _apply_data_collection_filtering_to_query_string( | ||
| query_string=query, | ||
| behaviour=client_options["data_collection"]["url_query_params"], | ||
| ) | ||
| ) | ||
| if filtered_query_string: | ||
| attributes["http.query"] = filtered_query_string | ||
|
|
||
| path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path) | ||
| attributes["url.path"] = path | ||
|
|
||
| url_without_query_string = _get_url( | ||
| asgi_scope, | ||
| "http" if ty == "http" else "ws", | ||
| headers.get("host"), | ||
| path=path, | ||
| ) | ||
|
|
||
| attributes["url.full"] = ( | ||
| f"{url_without_query_string}?{filtered_query_string}" | ||
| if filtered_query_string is not None | ||
| else url_without_query_string | ||
| ) | ||
|
|
||
| elif should_send_default_pii(): | ||
| query = _get_query(asgi_scope) | ||
| if query: | ||
| attributes["http.query"] = query | ||
|
|
||
| path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path) | ||
| attributes["url.path"] = path | ||
|
|
||
| url_without_query_string = _get_url( | ||
| asgi_scope, | ||
| "http" if ty == "http" else "ws", | ||
| headers.get("host"), | ||
| path=path, | ||
| ) | ||
| query_string = _get_query(asgi_scope) | ||
| attributes["url.full"] = ( | ||
| f"{url_without_query_string}?{query_string}" | ||
| if query_string is not None | ||
|
Check warning on line 229 in sentry_sdk/integrations/_asgi_common.py
|
||
| else url_without_query_string | ||
| ) | ||
|
|
||
| client = asgi_scope.get("client") | ||
| if client and should_send_default_pii(): | ||
| ip = _get_ip(asgi_scope) | ||
| attributes["client.address"] = ip | ||
| asgi_scope_client = asgi_scope.get("client") | ||
| if asgi_scope_client: | ||
| if has_data_collection_enabled(client_options): | ||
| if client_options["data_collection"]["user_info"]: | ||
| ip = _get_ip(asgi_scope) | ||
| attributes["client.address"] = ip | ||
| elif should_send_default_pii(): | ||
| ip = _get_ip(asgi_scope) | ||
| attributes["client.address"] = ip | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unbound client_options on non-HTTP ASGIHigh Severity In Reviewed by Cursor Bugbot for commit b308065. Configure here. |
||
|
|
||
| return attributes | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query string rebuilt without encoding
Medium Severity
_apply_data_collection_filtering_to_query_stringparses withparse_qsthen rejoins as rawkey=valuepairs without quoting. Values containing reserved characters such as spaces,&, or=are corrupted, so filteredquery_string/url.queryattributes can be invalid or misleading.Reviewed by Cursor Bugbot for commit b308065. Configure here.