Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions tests/integrations/launchdarkly/test_launchdarkly.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from ldclient.integrations.test_data import TestData

import sentry_sdk
from sentry_sdk import start_span, start_transaction
from sentry_sdk.integrations import DidNotEnable
from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration
from tests.conftest import ApproxDict


def test_launchdarkly_integration(sentry_init, capture_events, uninstall_integration):
Expand Down Expand Up @@ -188,16 +186,11 @@ def test_launchdarkly_integration_did_not_enable(uninstall_integration):
)


@pytest.mark.parametrize(
"span_streaming",
[True, False],
)
def test_launchdarkly_span_integration(
sentry_init,
capture_events,
capture_items,
uninstall_integration,
span_streaming,
):
td = TestData.data_source()
td.update(td.flag("hello").variation_for_all(True))
Expand All @@ -210,37 +203,19 @@ def test_launchdarkly_span_integration(
sentry_init(
traces_sample_rate=1.0,
integrations=[LaunchDarklyIntegration()],
trace_lifecycle="stream" if span_streaming else "static",
trace_lifecycle="stream",
)
client = ldclient.get()

if span_streaming:
items = capture_items("span")
items = capture_items("span")

with sentry_sdk.traces.start_span(name="bar"):
client.variation("hello", Context.create("my-org", "organization"), False)
client.variation("other", Context.create("my-org", "organization"), False)
with sentry_sdk.traces.start_span(name="bar"):
client.variation("hello", Context.create("my-org", "organization"), False)
client.variation("other", Context.create("my-org", "organization"), False)

sentry_sdk.flush()
sentry_sdk.flush()

assert len(items) == 1
span = items[0].payload
assert span["attributes"]["flag.evaluation.hello"] is True
assert span["attributes"]["flag.evaluation.other"] is False

else:
events = capture_events()

with start_transaction(name="hi"):
with start_span(op="foo", name="bar"):
client.variation(
"hello", Context.create("my-org", "organization"), False
)
client.variation(
"other", Context.create("my-org", "organization"), False
)

(event,) = events
assert event["spans"][0]["data"] == ApproxDict(
{"flag.evaluation.hello": True, "flag.evaluation.other": False}
)
assert len(items) == 1
span = items[0].payload
assert span["attributes"]["flag.evaluation.hello"] is True
assert span["attributes"]["flag.evaluation.other"] is False
41 changes: 10 additions & 31 deletions tests/integrations/openfeature/test_openfeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from openfeature.provider.in_memory_provider import InMemoryFlag, InMemoryProvider

import sentry_sdk
from sentry_sdk import start_span, start_transaction
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
from tests.conftest import ApproxDict


def test_openfeature_integration(sentry_init, capture_events, uninstall_integration):
Expand Down Expand Up @@ -154,51 +152,32 @@ async def runner():
}


@pytest.mark.parametrize(
"span_streaming",
[True, False],
)
def test_openfeature_span_integration(
sentry_init,
capture_events,
capture_items,
uninstall_integration,
span_streaming,
):
uninstall_integration(OpenFeatureIntegration.identifier)
sentry_init(
traces_sample_rate=1.0,
integrations=[OpenFeatureIntegration()],
trace_lifecycle="stream" if span_streaming else "static",
trace_lifecycle="stream",
)

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

if span_streaming:
items = capture_items("span")
with sentry_sdk.traces.start_span(name="bar"):
client.get_boolean_value("hello", default_value=False)
client.get_boolean_value("world", default_value=False)
items = capture_items("span")
with sentry_sdk.traces.start_span(name="bar"):
client.get_boolean_value("hello", default_value=False)
client.get_boolean_value("world", default_value=False)

sentry_sdk.flush()
sentry_sdk.flush()

assert len(items) == 1
span = items[0].payload
assert span["attributes"]["flag.evaluation.hello"] is True
assert span["attributes"]["flag.evaluation.world"] is False

else:
events = capture_events()

with start_transaction(name="hi"):
with start_span(op="foo", name="bar"):
client.get_boolean_value("hello", default_value=False)
client.get_boolean_value("world", default_value=False)

(event,) = events
assert event["spans"][0]["data"] == ApproxDict(
{"flag.evaluation.hello": True, "flag.evaluation.world": False}
)
assert len(items) == 1
span = items[0].payload
assert span["attributes"]["flag.evaluation.hello"] is True
assert span["attributes"]["flag.evaluation.world"] is False
29 changes: 0 additions & 29 deletions tests/integrations/requests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,6 @@ def test_crumb_capture_client_error(

@pytest.mark.tests_internal_exceptions
def test_omit_url_data_if_parsing_fails(sentry_init, capture_events):
sentry_init(integrations=[StdlibIntegration()])

events = capture_events()

url = f"http://localhost:{PORT}/ok" # noqa:E231

with mock.patch(
"sentry_sdk.integrations.stdlib.parse_url",
side_effect=ValueError,
):
response = requests.get(url)

capture_message("Testing!")

(event,) = events
assert event["breadcrumbs"]["values"][0]["data"] == ApproxDict(
{
SPANDATA.HTTP_REQUEST_METHOD: "GET",
SPANDATA.HTTP_STATUS_CODE: response.status_code,
# no url related data
}
)
assert "url" not in event["breadcrumbs"]["values"][0]["data"]
assert SPANDATA.HTTP_FRAGMENT not in event["breadcrumbs"]["values"][0]["data"]
assert SPANDATA.HTTP_QUERY not in event["breadcrumbs"]["values"][0]["data"]


@pytest.mark.tests_internal_exceptions
def test_omit_url_data_if_parsing_fails_span_streaming(sentry_init, capture_events):
sentry_init(
integrations=[StdlibIntegration()],
trace_lifecycle="stream",
Expand Down
48 changes: 16 additions & 32 deletions tests/integrations/statsig/test_statsig.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from statsig.statsig_user import StatsigUser

import sentry_sdk
from sentry_sdk import start_span, start_transaction
from sentry_sdk.integrations.statsig import StatsigIntegration
from tests.conftest import ApproxDict


@contextmanager
Expand Down Expand Up @@ -183,44 +181,30 @@ def test_wrapper_attributes(sentry_init, uninstall_integration):
statsig.check_gate = original_check_gate


@pytest.mark.parametrize(
"span_streaming",
[True, False],
)
def test_statsig_span_integration(
sentry_init, capture_events, capture_items, uninstall_integration, span_streaming
sentry_init,
capture_events,
capture_items,
uninstall_integration,
):
uninstall_integration(StatsigIntegration.identifier)

with mock_statsig({"hello": True}):
sentry_init(
traces_sample_rate=1.0,
integrations=[StatsigIntegration()],
trace_lifecycle="stream" if span_streaming else "static",
trace_lifecycle="stream",
)
user = StatsigUser(user_id="user-id")

if span_streaming:
items = capture_items("span")
with sentry_sdk.traces.start_span(name="hi"):
statsig.check_gate(user, "hello")
statsig.check_gate(user, "world")

sentry_sdk.flush()

assert len(items) == 1
span = items[0].payload
assert span["attributes"]["flag.evaluation.hello"] is True
assert span["attributes"]["flag.evaluation.world"] is False

else:
events = capture_events()
with start_transaction(name="hi"):
with start_span(op="foo", name="bar"):
statsig.check_gate(user, "hello")
statsig.check_gate(user, "world")

(event,) = events
assert event["spans"][0]["data"] == ApproxDict(
{"flag.evaluation.hello": True, "flag.evaluation.world": False}
)
items = capture_items("span")
with sentry_sdk.traces.start_span(name="hi"):
statsig.check_gate(user, "hello")
statsig.check_gate(user, "world")

sentry_sdk.flush()

assert len(items) == 1
span = items[0].payload
assert span["attributes"]["flag.evaluation.hello"] is True
assert span["attributes"]["flag.evaluation.world"] is False
2 changes: 1 addition & 1 deletion tests/integrations/stdlib/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def getresponse(self, *args, **kwargs):
assert request_headers["baggage"] == expected_outgoing_baggage


def test_outgoing_trace_headers_span_streaming_no_current_span(sentry_init):
def test_outgoing_trace_headers_no_current_span(sentry_init):
"""
With span streaming enabled and no active span, trace propagation headers
should still be attached to outgoing requests, propagated from the scope's
Expand Down
73 changes: 0 additions & 73 deletions tests/integrations/tornado/test_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,51 +438,6 @@ def test_oversized_request_body_not_annotated_data_collection(
assert "http.request.body.data" not in server_span["attributes"]


@pytest.mark.parametrize(
"data_collection, expect_body",
[
pytest.param({}, True, id="data_collection_http_bodies_default"),
pytest.param(
{"http_bodies": ["incoming_request"]},
True,
id="data_collection_http_bodies_incoming_request",
),
pytest.param(
{"http_bodies": ["outgoing_request"]},
False,
id="data_collection_http_bodies_outgoing_request_only",
),
pytest.param(
{"http_bodies": []}, False, id="data_collection_http_bodies_empty"
),
],
)
def test_request_body_data_collection_span_streaming(
tornado_testcase, sentry_init, capture_items, data_collection, expect_body
):
sentry_init(
integrations=[TornadoIntegration()],
traces_sample_rate=1.0,
trace_lifecycle="stream",
_experiments={"data_collection": data_collection},
)

items = capture_items("span")

client = tornado_testcase(Application([(r"/hi", HelloHandler)]))
response = client.fetch("/hi", method="POST", body=b"heyoo")
assert response.code == 200

sentry_sdk.flush()

(server_span,) = [item.payload for item in items]

if expect_body:
assert server_span["attributes"]["http.request.body.data"] == "heyoo"
else:
assert "http.request.body.data" not in server_span["attributes"]


@pytest.mark.parametrize(
"data_collection, expect_body",
[
Expand Down Expand Up @@ -533,34 +488,6 @@ def test_request_body_data_collection_event_processor(
assert "data" not in event["request"]


def test_oversized_request_body_not_annotated_data_collection_span_streaming(
tornado_testcase, sentry_init, capture_items
):
"""
The gating happens before the size check, so an oversized body is dropped
outright instead of being reported as removed because of the size limit.
"""
sentry_init(
integrations=[TornadoIntegration()],
traces_sample_rate=1.0,
trace_lifecycle="stream",
max_request_body_size="small",
_experiments={"data_collection": {"http_bodies": []}},
)

items = capture_items("span")

client = tornado_testcase(Application([(r"/hi", HelloHandler)]))
response = client.fetch("/hi", method="POST", body=b"a" * 2000)
assert response.code == 200

sentry_sdk.flush()

(server_span,) = [item.payload for item in items]

assert "http.request.body.data" not in server_span["attributes"]


@pytest.mark.parametrize("send_pii", [True, False])
@pytest.mark.parametrize(
"handler,code",
Expand Down
Loading
Loading