-
Notifications
You must be signed in to change notification settings - Fork 658
chore(sanic): Remove transaction-based tracing #7369
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,7 +268,7 @@ async def task(i): | |
| "headers": {}, | ||
| "version": "1.1", | ||
| "method": "GET", | ||
| "transport": None, | ||
| "transport": Mock(spec=["get_extra_info"]), | ||
|
Contributor
Author
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. Without this, |
||
| } | ||
|
|
||
| if SANIC_VERSION >= (19,): | ||
|
|
@@ -360,7 +360,6 @@ def __init__( | |
| expected_status: int, | ||
| expected_transaction_name: "Optional[str]", | ||
| expected_source: "Optional[str]" = None, | ||
| streaming_compatible: bool = True, | ||
| ) -> None: | ||
| """ | ||
| expected_transaction_name of None indicates we expect to not receive a transaction | ||
|
|
@@ -370,11 +369,9 @@ def __init__( | |
| self.expected_status = expected_status | ||
| self.expected_transaction_name = expected_transaction_name | ||
| self.expected_source = expected_source | ||
| self.streaming_compatible = streaming_compatible | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("send_pii", [True, False]) | ||
| @pytest.mark.parametrize("span_streaming", [True, False]) | ||
| @pytest.mark.parametrize( | ||
| "test_config", | ||
| [ | ||
|
|
@@ -402,14 +399,6 @@ def __init__( | |
| expected_transaction_name="fivehundred", | ||
| expected_source=TransactionSource.COMPONENT, | ||
| ), | ||
| TransactionTestConfig( | ||
| # By default, no transaction when we have a 404 error | ||
| integration_args=(), | ||
| url="/404", | ||
| expected_status=404, | ||
| expected_transaction_name=None, | ||
| streaming_compatible=False, | ||
| ), | ||
| TransactionTestConfig( | ||
| # With no ignored HTTP statuses, we should get transactions for 404 errors | ||
| integration_args=(None,), | ||
|
|
@@ -418,40 +407,24 @@ def __init__( | |
| expected_transaction_name="/404", | ||
| expected_source=TransactionSource.URL, | ||
| ), | ||
| TransactionTestConfig( | ||
| # Transaction can be suppressed for other HTTP statuses, too, by passing config to the integration | ||
| integration_args=({200},), | ||
| url="/message", | ||
| expected_status=200, | ||
| expected_transaction_name=None, | ||
| streaming_compatible=False, | ||
| ), | ||
| ], | ||
| ) | ||
| def test_transactions( | ||
| test_config: "TransactionTestConfig", | ||
| sentry_init: "Any", | ||
| app: "Any", | ||
| capture_events: "Any", | ||
| capture_items: "Any", | ||
| span_streaming: bool, | ||
| send_pii: bool, | ||
| ) -> None: | ||
| if span_streaming and not test_config.streaming_compatible: | ||
| pytest.skip("unsampled_statuses is not supported in span streaming mode") | ||
|
|
||
| # Init the SanicIntegration with the desired arguments | ||
| sentry_init( | ||
| integrations=[SanicIntegration(*test_config.integration_args)], | ||
| traces_sample_rate=1.0, | ||
| send_default_pii=send_pii, | ||
| trace_lifecycle="stream" if span_streaming else "static", | ||
| trace_lifecycle="stream", | ||
| ) | ||
|
|
||
| if span_streaming: | ||
| items = capture_items("span") | ||
| else: | ||
| events = capture_events() | ||
| items = capture_items("span") | ||
|
|
||
| # Make request to the desired URL | ||
| c = get_client(app) | ||
|
|
@@ -461,106 +434,71 @@ def test_transactions( | |
|
|
||
| sentry_sdk.flush() | ||
|
|
||
| if span_streaming: | ||
| segments = [ | ||
| i.payload | ||
| for i in items | ||
| if i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" | ||
| and i.payload["is_segment"] | ||
| ] | ||
| assert len(segments) <= 1 | ||
| (segment, *_) = [*segments, None] | ||
|
|
||
| assert (segment is None) == (test_config.expected_transaction_name is None) | ||
|
|
||
| if segment is not None: | ||
| assert segment["name"] == test_config.expected_transaction_name | ||
| assert ( | ||
| segment["attributes"]["sentry.segment.name.source"] | ||
| == test_config.expected_source | ||
| ) | ||
|
|
||
| attrs = segment["attributes"] | ||
| assert attrs["http.request.method"] == "GET" | ||
| assert attrs["network.protocol.name"] == "http" | ||
| header_keys = { | ||
| key[len("http.request.header.") :] | ||
| for key in attrs | ||
| if key.startswith("http.request.header.") | ||
| } | ||
| assert header_keys >= {"accept", "accept-encoding", "host", "user-agent"} | ||
| assert attrs["http.response.status_code"] == test_config.expected_status | ||
| assert segment["status"] == ( | ||
| "error" if test_config.expected_status >= 400 else "ok" | ||
| ) | ||
|
|
||
| if send_pii: | ||
| assert attrs["url.full"].endswith(test_config.url) | ||
| assert attrs["url.path"] == test_config.url.split("?")[0] | ||
| if "?" in test_config.url: | ||
| assert attrs["http.query"] == test_config.url.split("?", 1)[1] | ||
|
|
||
| else: | ||
| assert "url.full" not in attrs | ||
| assert "url.path" not in attrs | ||
| assert "http.query" not in attrs | ||
| segments = [ | ||
| i.payload | ||
| for i in items | ||
| if i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" | ||
| and i.payload["is_segment"] | ||
| ] | ||
| assert len(segments) <= 1 | ||
| (segment, *_) = [*segments, None] | ||
|
|
||
| else: | ||
| # Extract the transaction events by inspecting the event types. We should at most have 1 transaction event. | ||
| transaction_events = [ | ||
| e for e in events if "type" in e and e["type"] == "transaction" | ||
| ] | ||
| assert len(transaction_events) <= 1 | ||
|
|
||
| # Get the only transaction event, or set to None if there are no transaction events. | ||
| (transaction_event, *_) = [*transaction_events, None] | ||
|
|
||
| # We should have no transaction event if and only if we expect no transactions | ||
| assert (transaction_event is None) == ( | ||
| test_config.expected_transaction_name is None | ||
| ) | ||
| assert (segment is None) == (test_config.expected_transaction_name is None) | ||
|
|
||
| # If a transaction was expected, ensure it is correct | ||
| assert ( | ||
| transaction_event is None | ||
| or transaction_event["transaction"] == test_config.expected_transaction_name | ||
| ) | ||
| if segment is not None: | ||
| assert segment["name"] == test_config.expected_transaction_name | ||
| assert ( | ||
| transaction_event is None | ||
| or transaction_event["transaction_info"]["source"] | ||
| segment["attributes"]["sentry.segment.name.source"] | ||
| == test_config.expected_source | ||
| ) | ||
|
|
||
| attrs = segment["attributes"] | ||
| assert attrs["http.request.method"] == "GET" | ||
| assert attrs["network.protocol.name"] == "http" | ||
| header_keys = { | ||
| key[len("http.request.header.") :] | ||
| for key in attrs | ||
| if key.startswith("http.request.header.") | ||
| } | ||
| assert header_keys >= {"accept", "accept-encoding", "host", "user-agent"} | ||
| assert attrs["http.response.status_code"] == test_config.expected_status | ||
| assert segment["status"] == ( | ||
| "error" if test_config.expected_status >= 400 else "ok" | ||
| ) | ||
|
|
||
| if send_pii: | ||
| assert attrs["url.full"].endswith(test_config.url) | ||
| assert attrs["url.path"] == test_config.url.split("?")[0] | ||
| if "?" in test_config.url: | ||
| assert attrs["http.query"] == test_config.url.split("?", 1)[1] | ||
|
|
||
| else: | ||
| assert "url.full" not in attrs | ||
| assert "url.path" not in attrs | ||
| assert "http.query" not in attrs | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("span_streaming", [True, False]) | ||
| def test_span_origin(sentry_init, app, capture_events, capture_items, span_streaming): | ||
| def test_span_origin(sentry_init, app, capture_items): | ||
| sentry_init( | ||
| integrations=[SanicIntegration()], | ||
| traces_sample_rate=1.0, | ||
| trace_lifecycle="stream" if span_streaming else "static", | ||
| trace_lifecycle="stream", | ||
| ) | ||
|
|
||
| if span_streaming: | ||
| items = capture_items("span") | ||
| else: | ||
| events = capture_events() | ||
| items = capture_items("span") | ||
|
|
||
| c = get_client(app) | ||
| with c as client: | ||
| client.get("/message?foo=bar") | ||
|
|
||
| sentry_sdk.flush() | ||
|
|
||
| if span_streaming: | ||
| (segment,) = [ | ||
| i.payload | ||
| for i in items | ||
| if i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" | ||
| ] | ||
| assert segment["attributes"]["sentry.origin"] == "auto.http.sanic" | ||
| else: | ||
| (_, event) = events | ||
| assert event["contexts"]["trace"]["origin"] == "auto.http.sanic" | ||
| (segment,) = [ | ||
| i.payload | ||
| for i in items | ||
| if i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" | ||
| ] | ||
| assert segment["attributes"]["sentry.origin"] == "auto.http.sanic" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) | ||
|
|
@@ -714,16 +652,14 @@ def test_client_address_span_attribute_data_collection( | |
| @pytest.mark.parametrize( | ||
| "init_kwargs, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES | ||
| ) | ||
| def test_url_query_data_collection_span_streaming( | ||
| def test_url_query_data_collection( | ||
| sentry_init, app, capture_items, init_kwargs, expected_query | ||
| ): | ||
| init_kwargs = dict(init_kwargs) | ||
| experiments = dict(init_kwargs.pop("_experiments", {})) | ||
| experiments["trace_lifecycle"] = "stream" | ||
| sentry_init( | ||
| integrations=[SanicIntegration()], | ||
| traces_sample_rate=1.0, | ||
| _experiments=experiments, | ||
| trace_lifecycle="stream", | ||
| **init_kwargs, | ||
| ) | ||
|
|
||
|
|
@@ -743,7 +679,9 @@ def test_url_query_data_collection_span_streaming( | |
| and i.payload["is_segment"] | ||
| ] | ||
|
|
||
| data_collection_enabled = "data_collection" in experiments | ||
| data_collection_enabled = "data_collection" in ( | ||
| init_kwargs.get("_experiments") or {} | ||
| ) | ||
| url_attrs_expected = data_collection_enabled or init_kwargs.get( | ||
| "send_default_pii", False | ||
| ) | ||
|
|
||
Oops, something went wrong.
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.
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.
Default option warns on every request
Medium Severity
The
unsampled_statuseswarning now runs on every request. The default is{404}, which is truthy, so defaultSanicIntegration()logs this warning for every incoming request. The message also claims span streaming is enabled even whentrace_lifecycleis notstream.Reviewed by Cursor Bugbot for commit b386c02. Configure here.
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.
Will fix in a follow-up