Skip to content

Commit 5952c5b

Browse files
committed
test: Remove more transaction tests
1 parent f785bb6 commit 5952c5b

7 files changed

Lines changed: 53 additions & 283 deletions

File tree

tests/integrations/launchdarkly/test_launchdarkly.py

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
from ldclient.integrations.test_data import TestData
88

99
import sentry_sdk
10-
from sentry_sdk import start_span, start_transaction
1110
from sentry_sdk.integrations import DidNotEnable
1211
from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration
13-
from tests.conftest import ApproxDict
1412

1513

1614
def test_launchdarkly_integration(sentry_init, capture_events, uninstall_integration):
@@ -188,16 +186,11 @@ def test_launchdarkly_integration_did_not_enable(uninstall_integration):
188186
)
189187

190188

191-
@pytest.mark.parametrize(
192-
"span_streaming",
193-
[True, False],
194-
)
195189
def test_launchdarkly_span_integration(
196190
sentry_init,
197191
capture_events,
198192
capture_items,
199193
uninstall_integration,
200-
span_streaming,
201194
):
202195
td = TestData.data_source()
203196
td.update(td.flag("hello").variation_for_all(True))
@@ -210,37 +203,19 @@ def test_launchdarkly_span_integration(
210203
sentry_init(
211204
traces_sample_rate=1.0,
212205
integrations=[LaunchDarklyIntegration()],
213-
trace_lifecycle="stream" if span_streaming else "static",
206+
trace_lifecycle="stream",
214207
)
215208
client = ldclient.get()
216209

217-
if span_streaming:
218-
items = capture_items("span")
210+
items = capture_items("span")
219211

220-
with sentry_sdk.traces.start_span(name="bar"):
221-
client.variation("hello", Context.create("my-org", "organization"), False)
222-
client.variation("other", Context.create("my-org", "organization"), False)
212+
with sentry_sdk.traces.start_span(name="bar"):
213+
client.variation("hello", Context.create("my-org", "organization"), False)
214+
client.variation("other", Context.create("my-org", "organization"), False)
223215

224-
sentry_sdk.flush()
216+
sentry_sdk.flush()
225217

226-
assert len(items) == 1
227-
span = items[0].payload
228-
assert span["attributes"]["flag.evaluation.hello"] is True
229-
assert span["attributes"]["flag.evaluation.other"] is False
230-
231-
else:
232-
events = capture_events()
233-
234-
with start_transaction(name="hi"):
235-
with start_span(op="foo", name="bar"):
236-
client.variation(
237-
"hello", Context.create("my-org", "organization"), False
238-
)
239-
client.variation(
240-
"other", Context.create("my-org", "organization"), False
241-
)
242-
243-
(event,) = events
244-
assert event["spans"][0]["data"] == ApproxDict(
245-
{"flag.evaluation.hello": True, "flag.evaluation.other": False}
246-
)
218+
assert len(items) == 1
219+
span = items[0].payload
220+
assert span["attributes"]["flag.evaluation.hello"] is True
221+
assert span["attributes"]["flag.evaluation.other"] is False

tests/integrations/openfeature/test_openfeature.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
from openfeature.provider.in_memory_provider import InMemoryFlag, InMemoryProvider
77

88
import sentry_sdk
9-
from sentry_sdk import start_span, start_transaction
109
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
11-
from tests.conftest import ApproxDict
1210

1311

1412
def test_openfeature_integration(sentry_init, capture_events, uninstall_integration):
@@ -154,51 +152,32 @@ async def runner():
154152
}
155153

156154

157-
@pytest.mark.parametrize(
158-
"span_streaming",
159-
[True, False],
160-
)
161155
def test_openfeature_span_integration(
162156
sentry_init,
163157
capture_events,
164158
capture_items,
165159
uninstall_integration,
166-
span_streaming,
167160
):
168161
uninstall_integration(OpenFeatureIntegration.identifier)
169162
sentry_init(
170163
traces_sample_rate=1.0,
171164
integrations=[OpenFeatureIntegration()],
172-
trace_lifecycle="stream" if span_streaming else "static",
165+
trace_lifecycle="stream",
173166
)
174167

175168
api.set_provider(
176169
InMemoryProvider({"hello": InMemoryFlag("on", {"on": True, "off": False})})
177170
)
178171
client = api.get_client()
179172

180-
if span_streaming:
181-
items = capture_items("span")
182-
with sentry_sdk.traces.start_span(name="bar"):
183-
client.get_boolean_value("hello", default_value=False)
184-
client.get_boolean_value("world", default_value=False)
173+
items = capture_items("span")
174+
with sentry_sdk.traces.start_span(name="bar"):
175+
client.get_boolean_value("hello", default_value=False)
176+
client.get_boolean_value("world", default_value=False)
185177

186-
sentry_sdk.flush()
178+
sentry_sdk.flush()
187179

188-
assert len(items) == 1
189-
span = items[0].payload
190-
assert span["attributes"]["flag.evaluation.hello"] is True
191-
assert span["attributes"]["flag.evaluation.world"] is False
192-
193-
else:
194-
events = capture_events()
195-
196-
with start_transaction(name="hi"):
197-
with start_span(op="foo", name="bar"):
198-
client.get_boolean_value("hello", default_value=False)
199-
client.get_boolean_value("world", default_value=False)
200-
201-
(event,) = events
202-
assert event["spans"][0]["data"] == ApproxDict(
203-
{"flag.evaluation.hello": True, "flag.evaluation.world": False}
204-
)
180+
assert len(items) == 1
181+
span = items[0].payload
182+
assert span["attributes"]["flag.evaluation.hello"] is True
183+
assert span["attributes"]["flag.evaluation.world"] is False

tests/integrations/requests/test_requests.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,35 +108,6 @@ def test_crumb_capture_client_error(
108108

109109
@pytest.mark.tests_internal_exceptions
110110
def test_omit_url_data_if_parsing_fails(sentry_init, capture_events):
111-
sentry_init(integrations=[StdlibIntegration()])
112-
113-
events = capture_events()
114-
115-
url = f"http://localhost:{PORT}/ok" # noqa:E231
116-
117-
with mock.patch(
118-
"sentry_sdk.integrations.stdlib.parse_url",
119-
side_effect=ValueError,
120-
):
121-
response = requests.get(url)
122-
123-
capture_message("Testing!")
124-
125-
(event,) = events
126-
assert event["breadcrumbs"]["values"][0]["data"] == ApproxDict(
127-
{
128-
SPANDATA.HTTP_REQUEST_METHOD: "GET",
129-
SPANDATA.HTTP_STATUS_CODE: response.status_code,
130-
# no url related data
131-
}
132-
)
133-
assert "url" not in event["breadcrumbs"]["values"][0]["data"]
134-
assert SPANDATA.HTTP_FRAGMENT not in event["breadcrumbs"]["values"][0]["data"]
135-
assert SPANDATA.HTTP_QUERY not in event["breadcrumbs"]["values"][0]["data"]
136-
137-
138-
@pytest.mark.tests_internal_exceptions
139-
def test_omit_url_data_if_parsing_fails_span_streaming(sentry_init, capture_events):
140111
sentry_init(
141112
integrations=[StdlibIntegration()],
142113
trace_lifecycle="stream",

tests/integrations/statsig/test_statsig.py

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
from statsig.statsig_user import StatsigUser
99

1010
import sentry_sdk
11-
from sentry_sdk import start_span, start_transaction
1211
from sentry_sdk.integrations.statsig import StatsigIntegration
13-
from tests.conftest import ApproxDict
1412

1513

1614
@contextmanager
@@ -183,44 +181,30 @@ def test_wrapper_attributes(sentry_init, uninstall_integration):
183181
statsig.check_gate = original_check_gate
184182

185183

186-
@pytest.mark.parametrize(
187-
"span_streaming",
188-
[True, False],
189-
)
190184
def test_statsig_span_integration(
191-
sentry_init, capture_events, capture_items, uninstall_integration, span_streaming
185+
sentry_init,
186+
capture_events,
187+
capture_items,
188+
uninstall_integration,
192189
):
193190
uninstall_integration(StatsigIntegration.identifier)
194191

195192
with mock_statsig({"hello": True}):
196193
sentry_init(
197194
traces_sample_rate=1.0,
198195
integrations=[StatsigIntegration()],
199-
trace_lifecycle="stream" if span_streaming else "static",
196+
trace_lifecycle="stream",
200197
)
201198
user = StatsigUser(user_id="user-id")
202199

203-
if span_streaming:
204-
items = capture_items("span")
205-
with sentry_sdk.traces.start_span(name="hi"):
206-
statsig.check_gate(user, "hello")
207-
statsig.check_gate(user, "world")
208-
209-
sentry_sdk.flush()
210-
211-
assert len(items) == 1
212-
span = items[0].payload
213-
assert span["attributes"]["flag.evaluation.hello"] is True
214-
assert span["attributes"]["flag.evaluation.world"] is False
215-
216-
else:
217-
events = capture_events()
218-
with start_transaction(name="hi"):
219-
with start_span(op="foo", name="bar"):
220-
statsig.check_gate(user, "hello")
221-
statsig.check_gate(user, "world")
222-
223-
(event,) = events
224-
assert event["spans"][0]["data"] == ApproxDict(
225-
{"flag.evaluation.hello": True, "flag.evaluation.world": False}
226-
)
200+
items = capture_items("span")
201+
with sentry_sdk.traces.start_span(name="hi"):
202+
statsig.check_gate(user, "hello")
203+
statsig.check_gate(user, "world")
204+
205+
sentry_sdk.flush()
206+
207+
assert len(items) == 1
208+
span = items[0].payload
209+
assert span["attributes"]["flag.evaluation.hello"] is True
210+
assert span["attributes"]["flag.evaluation.world"] is False

tests/integrations/stdlib/test_httplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def getresponse(self, *args, **kwargs):
418418
assert request_headers["baggage"] == expected_outgoing_baggage
419419

420420

421-
def test_outgoing_trace_headers_span_streaming_no_current_span(sentry_init):
421+
def test_outgoing_trace_headers_no_current_span(sentry_init):
422422
"""
423423
With span streaming enabled and no active span, trace propagation headers
424424
should still be attached to outgoing requests, propagated from the scope's

tests/integrations/tornado/test_tornado.py

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -438,129 +438,6 @@ def test_oversized_request_body_not_annotated_data_collection(
438438
assert "http.request.body.data" not in server_span["attributes"]
439439

440440

441-
@pytest.mark.parametrize(
442-
"data_collection, expect_body",
443-
[
444-
pytest.param({}, True, id="data_collection_http_bodies_default"),
445-
pytest.param(
446-
{"http_bodies": ["incoming_request"]},
447-
True,
448-
id="data_collection_http_bodies_incoming_request",
449-
),
450-
pytest.param(
451-
{"http_bodies": ["outgoing_request"]},
452-
False,
453-
id="data_collection_http_bodies_outgoing_request_only",
454-
),
455-
pytest.param(
456-
{"http_bodies": []}, False, id="data_collection_http_bodies_empty"
457-
),
458-
],
459-
)
460-
def test_request_body_data_collection_span_streaming(
461-
tornado_testcase, sentry_init, capture_items, data_collection, expect_body
462-
):
463-
sentry_init(
464-
integrations=[TornadoIntegration()],
465-
traces_sample_rate=1.0,
466-
trace_lifecycle="stream",
467-
_experiments={"data_collection": data_collection},
468-
)
469-
470-
items = capture_items("span")
471-
472-
client = tornado_testcase(Application([(r"/hi", HelloHandler)]))
473-
response = client.fetch("/hi", method="POST", body=b"heyoo")
474-
assert response.code == 200
475-
476-
sentry_sdk.flush()
477-
478-
(server_span,) = [item.payload for item in items]
479-
480-
if expect_body:
481-
assert server_span["attributes"]["http.request.body.data"] == "heyoo"
482-
else:
483-
assert "http.request.body.data" not in server_span["attributes"]
484-
485-
486-
@pytest.mark.parametrize(
487-
"data_collection, expect_body",
488-
[
489-
pytest.param({}, True, id="data_collection_http_bodies_default"),
490-
pytest.param(
491-
{"http_bodies": ["incoming_request"]},
492-
True,
493-
id="data_collection_http_bodies_incoming_request",
494-
),
495-
pytest.param(
496-
{"http_bodies": ["outgoing_request"]},
497-
False,
498-
id="data_collection_http_bodies_outgoing_request_only",
499-
),
500-
pytest.param(
501-
{"http_bodies": []}, False, id="data_collection_http_bodies_empty"
502-
),
503-
],
504-
)
505-
def test_request_body_data_collection_event_processor(
506-
tornado_testcase, sentry_init, capture_events, data_collection, expect_body
507-
):
508-
sentry_init(
509-
integrations=[TornadoIntegration()],
510-
trace_lifecycle="static",
511-
_experiments={"data_collection": data_collection},
512-
)
513-
514-
events = capture_events()
515-
516-
data = {"hey": 42}
517-
client = tornado_testcase(Application([(r"/hi", CrashingHandler)]))
518-
response = client.fetch(
519-
"/hi",
520-
method="POST",
521-
body=json.dumps(data),
522-
headers={"Content-Type": "application/json"},
523-
)
524-
assert response.code == 500
525-
526-
sentry_sdk.flush()
527-
528-
(event,) = events
529-
530-
if expect_body:
531-
assert event["request"]["data"] == data
532-
else:
533-
assert "data" not in event["request"]
534-
535-
536-
def test_oversized_request_body_not_annotated_data_collection_span_streaming(
537-
tornado_testcase, sentry_init, capture_items
538-
):
539-
"""
540-
The gating happens before the size check, so an oversized body is dropped
541-
outright instead of being reported as removed because of the size limit.
542-
"""
543-
sentry_init(
544-
integrations=[TornadoIntegration()],
545-
traces_sample_rate=1.0,
546-
trace_lifecycle="stream",
547-
max_request_body_size="small",
548-
_experiments={"data_collection": {"http_bodies": []}},
549-
)
550-
551-
items = capture_items("span")
552-
553-
client = tornado_testcase(Application([(r"/hi", HelloHandler)]))
554-
response = client.fetch("/hi", method="POST", body=b"a" * 2000)
555-
assert response.code == 200
556-
557-
sentry_sdk.flush()
558-
559-
(server_span,) = [item.payload for item in items]
560-
561-
assert "http.request.body.data" not in server_span["attributes"]
562-
563-
564441
@pytest.mark.parametrize("send_pii", [True, False])
565442
@pytest.mark.parametrize(
566443
"handler,code",

0 commit comments

Comments
 (0)