diff --git a/sentry_sdk/integrations/falcon.py b/sentry_sdk/integrations/falcon.py index 16a649cfb7..df00e2efa6 100644 --- a/sentry_sdk/integrations/falcon.py +++ b/sentry_sdk/integrations/falcon.py @@ -5,7 +5,6 @@ from sentry_sdk.integrations._wsgi_common import RequestExtractor from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware from sentry_sdk.tracing import SOURCE_FOR_STYLE -from sentry_sdk.tracing_utils import has_span_streaming_enabled from sentry_sdk.utils import ( capture_internal_exceptions, ensure_integration_enabled, @@ -94,7 +93,7 @@ def process_resource( """ client = sentry_sdk.get_client() integration = client.get_integration(FalconIntegration) - if integration is None or not has_span_streaming_enabled(client.options): + if integration is None: return name_for_style = { diff --git a/tests/integrations/falcon/test_falcon.py b/tests/integrations/falcon/test_falcon.py index 6550a7fc67..4de658b93d 100644 --- a/tests/integrations/falcon/test_falcon.py +++ b/tests/integrations/falcon/test_falcon.py @@ -60,34 +60,24 @@ def inner(): return inner -@pytest.mark.parametrize("span_streaming", [True, False]) def test_has_context( sentry_init, - capture_events, capture_items, make_client, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) client = make_client() - if span_streaming: - items = capture_items("event") + items = capture_items("event") - response = client.simulate_get("/message") - assert response.status == falcon.HTTP_200 + response = client.simulate_get("/message") + assert response.status == falcon.HTTP_200 - (event,) = (item.payload for item in items) - else: - events = capture_events() - - response = client.simulate_get("/message") - assert response.status == falcon.HTTP_200 + (event,) = (item.payload for item in items) - (event,) = events assert event["transaction"] == "/message" # Falcon URI template assert "data" not in event["request"] assert event["request"]["url"] == "http://falconframework.org/message" @@ -102,66 +92,49 @@ def test_has_context( ("/message/123456", "path", "/message/123456", "url"), ], ) -@pytest.mark.parametrize("span_streaming", [True, False]) def test_transaction_style( sentry_init, make_client, - capture_events, capture_items, url, transaction_style, expected_transaction, expected_source, - span_streaming, ): integration = FalconIntegration(transaction_style=transaction_style) sentry_init( integrations=[integration], traces_sample_rate=1.0, - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) client = make_client() - if span_streaming: - items = capture_items("event") - items = capture_items("event", "span") + items = capture_items("event", "span") - response = client.simulate_get(url) - assert response.status == falcon.HTTP_200 + response = client.simulate_get(url) + assert response.status == falcon.HTTP_200 - (event,) = (item.payload for item in items if item.type == "event") - - sentry_sdk.flush() - spans = [item.payload for item in items if item.type == "span"] - spans = [span for span in spans if span["name"] == expected_transaction] - assert len(spans) == 1 - assert spans[0]["attributes"]["sentry.segment.name.source"] == expected_source - else: - events = capture_events() + (event,) = (item.payload for item in items if item.type == "event") - response = client.simulate_get(url) - assert response.status == falcon.HTTP_200 + sentry_sdk.flush() - (event, transaction) = events - - assert transaction["transaction"] == expected_transaction - assert transaction["transaction_info"] == {"source": expected_source} + spans = [item.payload for item in items if item.type == "span"] + spans = [span for span in spans if span["name"] == expected_transaction] + assert len(spans) == 1 + assert spans[0]["attributes"]["sentry.segment.name.source"] == expected_source assert event["transaction"] == expected_transaction assert event["transaction_info"] == {"source": expected_source} -@pytest.mark.parametrize("span_streaming", [True, False]) def test_unhandled_errors( sentry_init, capture_exceptions, - capture_events, capture_items, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) class Resource: @@ -174,45 +147,30 @@ def on_get(self, req, resp): client = falcon.testing.TestClient(app) exceptions = capture_exceptions() - if span_streaming: - items = capture_items("event") - - try: - client.simulate_get("/") - except ZeroDivisionError: - pass + items = capture_items("event") - (exc,) = exceptions - assert isinstance(exc, ZeroDivisionError) - - (event,) = (item.payload for item in items) - else: - events = capture_events() + try: + client.simulate_get("/") + except ZeroDivisionError: + pass - try: - client.simulate_get("/") - except ZeroDivisionError: - pass + (exc,) = exceptions + assert isinstance(exc, ZeroDivisionError) - (exc,) = exceptions - assert isinstance(exc, ZeroDivisionError) + (event,) = (item.payload for item in items) - (event,) = events assert event["exception"]["values"][0]["mechanism"]["type"] == "falcon" assert " by zero" in event["exception"]["values"][0]["value"] -@pytest.mark.parametrize("span_streaming", [True, False]) def test_raised_5xx_errors( sentry_init, capture_exceptions, - capture_events, capture_items, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) class Resource: @@ -225,39 +183,27 @@ def on_get(self, req, resp): client = falcon.testing.TestClient(app) exceptions = capture_exceptions() - if span_streaming: - items = capture_items("event") + items = capture_items("event") - client.simulate_get("/") - - (exc,) = exceptions - assert isinstance(exc, falcon.HTTPError) - - (event,) = (item.payload for item in items) - else: - events = capture_events() + client.simulate_get("/") - client.simulate_get("/") + (exc,) = exceptions + assert isinstance(exc, falcon.HTTPError) - (exc,) = exceptions - assert isinstance(exc, falcon.HTTPError) + (event,) = (item.payload for item in items) - (event,) = events assert event["exception"]["values"][0]["mechanism"]["type"] == "falcon" assert event["exception"]["values"][0]["type"] == "HTTPError" -@pytest.mark.parametrize("span_streaming", [True, False]) def test_raised_4xx_errors( sentry_init, capture_exceptions, - capture_events, capture_items, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) class Resource: @@ -268,10 +214,7 @@ def on_get(self, req, resp): app.add_route("/", Resource()) exceptions = capture_exceptions() - if span_streaming: - events = capture_items("event") - else: - events = capture_events() + events = capture_items("event") client = falcon.testing.TestClient(app) client.simulate_get("/") @@ -280,13 +223,10 @@ def on_get(self, req, resp): assert len(events) == 0 -@pytest.mark.parametrize("span_streaming", [True, False]) def test_http_status( sentry_init, capture_exceptions, - capture_events, capture_items, - span_streaming, ): """ This just demonstrates, that if Falcon raises a HTTPStatus with code 500 @@ -294,7 +234,7 @@ def test_http_status( """ sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) class Resource: @@ -307,33 +247,25 @@ def on_get(self, req, resp): client = falcon.testing.TestClient(app) exceptions = capture_exceptions() - if span_streaming: - events = capture_items("event") + events = capture_items("event") - client.simulate_get("/") - else: - events = capture_events() - - client.simulate_get("/") + client.simulate_get("/") assert len(exceptions) == 0 assert len(events) == 0 @pytest.mark.parametrize("max_value_length", [1024, None]) -@pytest.mark.parametrize("span_streaming", [True, False]) def test_falcon_large_json_request( sentry_init, - capture_events, capture_items, max_value_length, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], max_request_body_size="always", max_value_length=max_value_length, - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) data = {"foo": {"bar": "a" * (1034)}} @@ -349,20 +281,12 @@ def on_post(self, req, resp): client = falcon.testing.TestClient(app) - if span_streaming: - items = capture_items("event") - - response = client.simulate_post("/", json=data) - assert response.status == falcon.HTTP_200 + items = capture_items("event") - (event,) = (item.payload for item in items) - else: - events = capture_events() - - response = client.simulate_post("/", json=data) - assert response.status == falcon.HTTP_200 + response = client.simulate_post("/", json=data) + assert response.status == falcon.HTTP_200 - (event,) = events + (event,) = (item.payload for item in items) if max_value_length: assert event["_meta"]["request"]["data"]["foo"]["bar"] == { "": { @@ -376,17 +300,14 @@ def on_post(self, req, resp): @pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"]) -@pytest.mark.parametrize("span_streaming", [True, False]) def test_falcon_empty_json_request( sentry_init, - capture_events, capture_items, data, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) class Resource: @@ -400,33 +321,22 @@ def on_post(self, req, resp): client = falcon.testing.TestClient(app) - if span_streaming: - items = capture_items("event") + items = capture_items("event") - response = client.simulate_post("/", json=data) - assert response.status == falcon.HTTP_200 - - (event,) = (item.payload for item in items) - else: - events = capture_events() + response = client.simulate_post("/", json=data) + assert response.status == falcon.HTTP_200 - response = client.simulate_post("/", json=data) - assert response.status == falcon.HTTP_200 - - (event,) = events + (event,) = (item.payload for item in items) assert event["request"]["data"] == data -@pytest.mark.parametrize("span_streaming", [True, False]) def test_falcon_raw_data_request( sentry_init, - capture_events, capture_items, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) class Resource: @@ -439,34 +349,23 @@ def on_post(self, req, resp): client = falcon.testing.TestClient(app) - if span_streaming: - items = capture_items("event") - - response = client.simulate_post("/", body="hi") - assert response.status == falcon.HTTP_200 + items = capture_items("event") - (event,) = (item.payload for item in items) - else: - events = capture_events() + response = client.simulate_post("/", body="hi") + assert response.status == falcon.HTTP_200 - response = client.simulate_post("/", body="hi") - assert response.status == falcon.HTTP_200 - - (event,) = events + (event,) = (item.payload for item in items) assert event["request"]["headers"]["Content-Length"] == "2" assert event["request"]["data"] == "" -@pytest.mark.parametrize("span_streaming", [True, False]) def test_logging( sentry_init, - capture_events, capture_items, - span_streaming, ): sentry_init( integrations=[FalconIntegration(), LoggingIntegration(event_level="ERROR")], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) logger = logging.getLogger() @@ -482,18 +381,11 @@ def on_get(self, req, resp): client = falcon.testing.TestClient(app) - if span_streaming: - items = capture_items("event") - - client.simulate_get("/") - - (event,) = (item.payload for item in items) - else: - events = capture_events() + items = capture_items("event") - client.simulate_get("/") + client.simulate_get("/") - (event,) = events + (event,) = (item.payload for item in items) assert event["level"] == "error" @@ -520,16 +412,13 @@ def http500_handler(ex, req, resp, params): assert response.json == {"message": "Sentry error."} -@pytest.mark.parametrize("span_streaming", [True, False]) def test_error_in_errorhandler( sentry_init, - capture_events, capture_items, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) app = falcon.API() @@ -546,36 +435,25 @@ def http500_handler(ex, req, resp, params): app.add_error_handler(Exception, http500_handler) client = falcon.testing.TestClient(app) - if span_streaming: - items = capture_items("event") - - with pytest.raises(ZeroDivisionError): - client.simulate_get("/") - - (event,) = (item.payload for item in items) - else: - events = capture_events() + items = capture_items("event") - with pytest.raises(ZeroDivisionError): - client.simulate_get("/") + with pytest.raises(ZeroDivisionError): + client.simulate_get("/") - (event,) = events + (event,) = (item.payload for item in items) last_ex_values = event["exception"]["values"][-1] assert last_ex_values["type"] == "ZeroDivisionError" assert last_ex_values["stacktrace"]["frames"][-1]["vars"]["ex"] == "ValueError()" -@pytest.mark.parametrize("span_streaming", [True, False]) def test_bad_request_not_captured( sentry_init, - capture_events, capture_items, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) app = falcon.API() @@ -588,26 +466,20 @@ def on_get(self, req, resp): client = falcon.testing.TestClient(app) - if span_streaming: - events = capture_items("event") - else: - events = capture_events() + events = capture_items("event") client.simulate_get("/") assert not events -@pytest.mark.parametrize("span_streaming", [True, False]) def test_does_not_leak_scope( sentry_init, - capture_events, capture_items, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) app = falcon.API() @@ -628,10 +500,7 @@ def generator(): client = falcon.testing.TestClient(app) - if span_streaming: - events = capture_items("event") - else: - events = capture_events() + events = capture_items("event") sentry_sdk.get_isolation_scope().set_tag("request_data", False) @@ -643,8 +512,7 @@ def generator(): assert not sentry_sdk.get_isolation_scope()._tags["request_data"] -@pytest.mark.parametrize("span_streaming", [True, False]) -def test_falcon_not_breaking_asgi(sentry_init, span_streaming): +def test_falcon_not_breaking_asgi(sentry_init): """ This test simply verifies that the Falcon integration does not break ASGI Falcon apps. @@ -654,7 +522,7 @@ def test_falcon_not_breaking_asgi(sentry_init, span_streaming): """ sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) asgi_app = falcon.asgi.App() @@ -665,13 +533,10 @@ def test_falcon_not_breaking_asgi(sentry_init, span_streaming): pytest.fail("Falcon integration causing errors in ASGI apps.") -@pytest.mark.parametrize("span_streaming", [True, False]) def test_falcon_custom_error_handler( sentry_init, make_app, - capture_events, capture_items, - span_streaming, ): """ When a custom error handler handles what otherwise would have resulted in a 5xx error, @@ -679,59 +544,43 @@ def test_falcon_custom_error_handler( """ sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) app = make_app() client = falcon.testing.TestClient(app) - if span_streaming: - events = capture_items("event") - else: - events = capture_events() + events = capture_items("event") client.simulate_get("/custom-error") assert len(events) == 0 -@pytest.mark.parametrize("span_streaming", [True, False]) def test_span_origin( sentry_init, - capture_events, capture_items, make_client, - span_streaming, ): sentry_init( integrations=[FalconIntegration()], traces_sample_rate=1.0, - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) client = make_client() - if span_streaming: - items = capture_items("span") - - client.simulate_get("/message") - - sentry_sdk.flush() - spans = [item.payload for item in items] - - assert spans[0]["attributes"]["sentry.origin"] == "auto.http.falcon" - else: - events = capture_events() + items = capture_items("span") - client.simulate_get("/message") + client.simulate_get("/message") - (_, event) = events + sentry_sdk.flush() + spans = [item.payload for item in items] - assert event["contexts"]["trace"]["origin"] == "auto.http.falcon" + assert spans[0]["attributes"]["sentry.origin"] == "auto.http.falcon" -@pytest.mark.parametrize("span_streaming", [True, False]) -def test_falcon_request_media(sentry_init, span_streaming): +def test_falcon_request_media(sentry_init): # test_passed stores whether the test has passed. test_passed = False @@ -759,7 +608,7 @@ def on_post(self, req, _): sentry_init( integrations=[FalconIntegration()], - trace_lifecycle="stream" if span_streaming else "static", + trace_lifecycle="stream", ) try: