Browse Source

ref(metrics) fix incorrect exception being raised (#73367)

Closes https://github.com/getsentry/sentry/issues/71561

---------

Signed-off-by: Vjeran Grozdanic <vjerangrozdanic@sentry.io>
Vjeran Grozdanić 3 days ago
parent
commit
d68c2ebf4f

+ 2 - 2
src/sentry/dynamic_sampling/rules/base.py

@@ -48,9 +48,9 @@ def get_guarded_blended_sample_rate(organization: Organization, project: Project
         organization_id=organization.id, project=project
     )
 
-    # If the sample rate is None, it means that dynamic sampling rules shouldn't be generated.
+    # get_blended_sample_rate returns None if the organization doesn't have dynamic sampling
     if sample_rate is None:
-        raise Exception("get_blended_sample_rate returns none")
+        return 1.0
 
     # If the sample rate is 100%, we don't want to use any special dynamic sample rate, we will just sample at 100%.
     if sample_rate == 1.0:

+ 11 - 1
tests/sentry/api/endpoints/test_relay_projectconfigs.py

@@ -166,7 +166,17 @@ def test_relays_dyamic_sampling(call_endpoint, default_project):
         dynamic_sampling = safe.get_path(
             result, "configs", str(default_project.id), "config", "sampling"
         )
-        assert dynamic_sampling == {"version": 2, "rules": []}
+        assert dynamic_sampling == {
+            "version": 2,
+            "rules": [
+                {
+                    "samplingValue": {"type": "sampleRate", "value": 1.0},
+                    "type": "trace",
+                    "condition": {"op": "and", "inner": []},
+                    "id": 1000,  # this is reserved id for RuleType.BOOST_LOW_VOLUME_PROJECTS_RULE which is being created
+                }
+            ],
+        }
 
 
 @django_db_all

+ 11 - 1
tests/sentry/api/endpoints/test_relay_projectconfigs_v2.py

@@ -126,7 +126,17 @@ def test_relays_dyamic_sampling(call_endpoint, default_projectkey):
             "config",
             "sampling",
         )
-        assert dynamic_sampling == {"version": 2, "rules": []}
+        assert dynamic_sampling == {
+            "version": 2,
+            "rules": [
+                {
+                    "samplingValue": {"type": "sampleRate", "value": 1.0},
+                    "type": "trace",
+                    "condition": {"op": "and", "inner": []},
+                    "id": 1000,  # this is reserved id for RuleType.BOOST_LOW_VOLUME_PROJECTS_RULE which is being created
+                }
+            ],
+        }
 
 
 @django_db_all

+ 3 - 4
tests/sentry/dynamic_sampling/test_generate_rules.py

@@ -89,13 +89,12 @@ def test_generate_rules_capture_exception(get_blended_sample_rate, sentry_sdk):
     # since we mock get_blended_sample_rate function
     # no need to create real project in DB
     fake_project = MagicMock()
-    # if blended rate is None that means no dynamic sampling behavior should happen.
-    # Therefore no rules should be set.
-    assert generate_rules(fake_project) == []
+    # if blended rate is None that means dynamic sampling rate should be set to 1.
+    rules = generate_rules(fake_project)
+    assert rules[0]["samplingValue"]["value"] == 1.0
     get_blended_sample_rate.assert_called_with(
         organization_id=fake_project.organization.id, project=fake_project
     )
-    assert sentry_sdk.capture_exception.call_count == 1
     _validate_rules(fake_project)