Browse Source

feat(mobile-score): Add mobile profile to relay config (#66812)

Adds the mobile profile that we're treating as an alpha version. This
profile is just to ensure that we're able to ingest the values we want
and we will iterate the profiles in the future.

The browser configs are extracted into a helper function with no
modifications, and there is a mobile profile added. The
`config.performanceScore.profiles` path will only be added if either of
these helpers populates an array with profiles to pass along.
Nar Saynorath 11 months ago
parent
commit
a65a98d9bb
1 changed files with 362 additions and 294 deletions
  1. 362 294
      src/sentry/relay/config/__init__.py

+ 362 - 294
src/sentry/relay/config/__init__.py

@@ -35,6 +35,7 @@ from sentry.ingest.transaction_clusterer.rules import (
     get_sorted_rules,
 )
 from sentry.interfaces.security import DEFAULT_DISALLOWED_SOURCES
+from sentry.models.organization import Organization
 from sentry.models.project import Project
 from sentry.models.projectkey import ProjectKey
 from sentry.relay.config.experimental import TimeChecker, add_experimental_config
@@ -389,6 +390,361 @@ def _should_extract_abnormal_mechanism(project: Project) -> bool:
     )
 
 
+def _get_browser_performance_profiles(organization: Organization) -> list[dict[str, Any]]:
+    if not features.has("organizations:performance-calculate-score-relay", organization):
+        return []
+
+    shouldIncludeFid = not features.has(
+        "organizations:deprecate-fid-from-performance-score", organization
+    )
+
+    return [
+        {
+            "name": "Chrome",
+            "scoreComponents": [
+                {
+                    "measurement": "fcp",
+                    "weight": 0.15,
+                    "p10": 900.0,
+                    "p50": 1600.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "lcp",
+                    "weight": 0.30,
+                    "p10": 1200.0,
+                    "p50": 2400.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "fid",
+                    "weight": 0.30 if shouldIncludeFid else 0.0,
+                    "p10": 100.0,
+                    "p50": 300.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "cls",
+                    "weight": 0.15,
+                    "p10": 0.1,
+                    "p50": 0.25,
+                    "optional": False,
+                },
+                {
+                    "measurement": "ttfb",
+                    "weight": 0.10,
+                    "p10": 200.0,
+                    "p50": 400.0,
+                    "optional": False,
+                },
+            ],
+            "condition": {
+                "op": "eq",
+                "name": "event.contexts.browser.name",
+                "value": "Chrome",
+            },
+        },
+        {
+            "name": "Firefox",
+            "scoreComponents": [
+                {
+                    "measurement": "fcp",
+                    "weight": 0.15,
+                    "p10": 900.0,
+                    "p50": 1600.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "lcp",
+                    "weight": 0.30,
+                    "p10": 1200.0,
+                    "p50": 2400.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "fid",
+                    "weight": 0.30 if shouldIncludeFid else 0.0,
+                    "p10": 100.0,
+                    "p50": 300.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "cls",
+                    "weight": 0.0,
+                    "p10": 0.1,
+                    "p50": 0.25,
+                    "optional": False,
+                },
+                {
+                    "measurement": "ttfb",
+                    "weight": 0.10,
+                    "p10": 200.0,
+                    "p50": 400.0,
+                    "optional": False,
+                },
+            ],
+            "condition": {
+                "op": "eq",
+                "name": "event.contexts.browser.name",
+                "value": "Firefox",
+            },
+        },
+        {
+            "name": "Safari",
+            "scoreComponents": [
+                {
+                    "measurement": "fcp",
+                    "weight": 0.15,
+                    "p10": 900.0,
+                    "p50": 1600.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "lcp",
+                    "weight": 0.0,
+                    "p10": 1200.0,
+                    "p50": 2400.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "fid",
+                    "weight": 0.0,
+                    "p10": 100.0,
+                    "p50": 300.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "cls",
+                    "weight": 0.0,
+                    "p10": 0.1,
+                    "p50": 0.25,
+                    "optional": False,
+                },
+                {
+                    "measurement": "ttfb",
+                    "weight": 0.10,
+                    "p10": 200.0,
+                    "p50": 400.0,
+                    "optional": False,
+                },
+            ],
+            "condition": {
+                "op": "eq",
+                "name": "event.contexts.browser.name",
+                "value": "Safari",
+            },
+        },
+        {
+            "name": "Edge",
+            "scoreComponents": [
+                {
+                    "measurement": "fcp",
+                    "weight": 0.15,
+                    "p10": 900.0,
+                    "p50": 1600.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "lcp",
+                    "weight": 0.30,
+                    "p10": 1200.0,
+                    "p50": 2400.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "fid",
+                    "weight": 0.30 if shouldIncludeFid else 0.0,
+                    "p10": 100.0,
+                    "p50": 300.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "cls",
+                    "weight": 0.15,
+                    "p10": 0.1,
+                    "p50": 0.25,
+                    "optional": False,
+                },
+                {
+                    "measurement": "ttfb",
+                    "weight": 0.10,
+                    "p10": 200.0,
+                    "p50": 400.0,
+                    "optional": False,
+                },
+            ],
+            "condition": {
+                "op": "eq",
+                "name": "event.contexts.browser.name",
+                "value": "Edge",
+            },
+        },
+        {
+            "name": "Opera",
+            "scoreComponents": [
+                {
+                    "measurement": "fcp",
+                    "weight": 0.15,
+                    "p10": 900.0,
+                    "p50": 1600.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "lcp",
+                    "weight": 0.30,
+                    "p10": 1200.0,
+                    "p50": 2400.0,
+                    "optional": False,
+                },
+                {
+                    "measurement": "fid",
+                    "weight": 0.30 if shouldIncludeFid else 0.0,
+                    "p10": 100.0,
+                    "p50": 300.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "cls",
+                    "weight": 0.15,
+                    "p10": 0.1,
+                    "p50": 0.25,
+                    "optional": False,
+                },
+                {
+                    "measurement": "ttfb",
+                    "weight": 0.10,
+                    "p10": 200.0,
+                    "p50": 400.0,
+                    "optional": False,
+                },
+            ],
+            "condition": {
+                "op": "eq",
+                "name": "event.contexts.browser.name",
+                "value": "Opera",
+            },
+        },
+        {
+            "name": "Chrome INP",
+            "scoreComponents": [
+                {
+                    "measurement": "inp",
+                    "weight": 1.0,
+                    "p10": 200.0,
+                    "p50": 500.0,
+                    "optional": False,
+                },
+            ],
+            "condition": {
+                "op": "or",
+                "inner": [
+                    {
+                        "op": "eq",
+                        "name": "event.contexts.browser.name",
+                        "value": "Chrome",
+                    },
+                    {
+                        "op": "eq",
+                        "name": "event.contexts.browser.name",
+                        "value": "Google Chrome",
+                    },
+                ],
+            },
+        },
+        {
+            "name": "Edge INP",
+            "scoreComponents": [
+                {
+                    "measurement": "inp",
+                    "weight": 1.0,
+                    "p10": 200.0,
+                    "p50": 500.0,
+                    "optional": False,
+                },
+            ],
+            "condition": {
+                "op": "eq",
+                "name": "event.contexts.browser.name",
+                "value": "Edge",
+            },
+        },
+        {
+            "name": "Opera INP",
+            "scoreComponents": [
+                {
+                    "measurement": "inp",
+                    "weight": 1.0,
+                    "p10": 200.0,
+                    "p50": 500.0,
+                    "optional": False,
+                },
+            ],
+            "condition": {
+                "op": "eq",
+                "name": "event.contexts.browser.name",
+                "value": "Opera",
+            },
+        },
+    ]
+
+
+def _get_mobile_performance_profiles(organization: Organization) -> list[dict[str, Any]]:
+    if not features.has(
+        "organizations:performance-calculate-mobile-perf-score-relay", organization
+    ):
+        return []
+
+    return [
+        {
+            "name": "Mobile",
+            "version": "mobile.alpha",
+            "scoreComponents": [
+                {
+                    "measurement": "time_to_initial_display",
+                    "weight": 0.25,
+                    "p10": 1800.0,
+                    "p50": 3000.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "time_to_full_display",
+                    "weight": 0.25,
+                    "p10": 2500.0,
+                    "p50": 4000.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "app_start_warm",
+                    "weight": 0.25,
+                    "p10": 200.0,
+                    "p50": 500.0,
+                    "optional": True,
+                },
+                {
+                    "measurement": "app_start_cold",
+                    "weight": 0.25,
+                    "p10": 200.0,
+                    "p50": 500.0,
+                    "optional": True,
+                },
+            ],
+            "condition": {
+                "op": "and",
+                "inner": [
+                    {
+                        "op": "or",
+                        "inner": [
+                            {"op": "eq", "name": "event.sdk.name", "value": "sentry.cocoa"},
+                            {"op": "eq", "name": "event.sdk.name", "value": "sentry.java.android"},
+                        ],
+                    },
+                    {"op": "eq", "name": "event.contexts.trace.op", "value": "ui.load"},
+                ],
+            },
+        }
+    ]
+
+
 def _get_project_config(
     project: Project, full_config: bool = True, project_keys: Sequence[ProjectKey] | None = None
 ) -> "ProjectConfig":
@@ -477,300 +833,12 @@ def _get_project_config(
             ),
         }
 
-    if features.has("organizations:performance-calculate-score-relay", project.organization):
-        shouldIncludeFid = not features.has(
-            "organizations:deprecate-fid-from-performance-score", project.organization
-        )
-        config["performanceScore"] = {
-            "profiles": [
-                {
-                    "name": "Chrome",
-                    "scoreComponents": [
-                        {
-                            "measurement": "fcp",
-                            "weight": 0.15,
-                            "p10": 900.0,
-                            "p50": 1600.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "lcp",
-                            "weight": 0.30,
-                            "p10": 1200.0,
-                            "p50": 2400.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "fid",
-                            "weight": 0.30 if shouldIncludeFid else 0.0,
-                            "p10": 100.0,
-                            "p50": 300.0,
-                            "optional": True,
-                        },
-                        {
-                            "measurement": "cls",
-                            "weight": 0.15,
-                            "p10": 0.1,
-                            "p50": 0.25,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "ttfb",
-                            "weight": 0.10,
-                            "p10": 200.0,
-                            "p50": 400.0,
-                            "optional": False,
-                        },
-                    ],
-                    "condition": {
-                        "op": "eq",
-                        "name": "event.contexts.browser.name",
-                        "value": "Chrome",
-                    },
-                },
-                {
-                    "name": "Firefox",
-                    "scoreComponents": [
-                        {
-                            "measurement": "fcp",
-                            "weight": 0.15,
-                            "p10": 900.0,
-                            "p50": 1600.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "lcp",
-                            "weight": 0.30,
-                            "p10": 1200.0,
-                            "p50": 2400.0,
-                            "optional": True,
-                        },
-                        {
-                            "measurement": "fid",
-                            "weight": 0.30 if shouldIncludeFid else 0.0,
-                            "p10": 100.0,
-                            "p50": 300.0,
-                            "optional": True,
-                        },
-                        {
-                            "measurement": "cls",
-                            "weight": 0.0,
-                            "p10": 0.1,
-                            "p50": 0.25,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "ttfb",
-                            "weight": 0.10,
-                            "p10": 200.0,
-                            "p50": 400.0,
-                            "optional": False,
-                        },
-                    ],
-                    "condition": {
-                        "op": "eq",
-                        "name": "event.contexts.browser.name",
-                        "value": "Firefox",
-                    },
-                },
-                {
-                    "name": "Safari",
-                    "scoreComponents": [
-                        {
-                            "measurement": "fcp",
-                            "weight": 0.15,
-                            "p10": 900.0,
-                            "p50": 1600.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "lcp",
-                            "weight": 0.0,
-                            "p10": 1200.0,
-                            "p50": 2400.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "fid",
-                            "weight": 0.0,
-                            "p10": 100.0,
-                            "p50": 300.0,
-                            "optional": True,
-                        },
-                        {
-                            "measurement": "cls",
-                            "weight": 0.0,
-                            "p10": 0.1,
-                            "p50": 0.25,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "ttfb",
-                            "weight": 0.10,
-                            "p10": 200.0,
-                            "p50": 400.0,
-                            "optional": False,
-                        },
-                    ],
-                    "condition": {
-                        "op": "eq",
-                        "name": "event.contexts.browser.name",
-                        "value": "Safari",
-                    },
-                },
-                {
-                    "name": "Edge",
-                    "scoreComponents": [
-                        {
-                            "measurement": "fcp",
-                            "weight": 0.15,
-                            "p10": 900.0,
-                            "p50": 1600.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "lcp",
-                            "weight": 0.30,
-                            "p10": 1200.0,
-                            "p50": 2400.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "fid",
-                            "weight": 0.30 if shouldIncludeFid else 0.0,
-                            "p10": 100.0,
-                            "p50": 300.0,
-                            "optional": True,
-                        },
-                        {
-                            "measurement": "cls",
-                            "weight": 0.15,
-                            "p10": 0.1,
-                            "p50": 0.25,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "ttfb",
-                            "weight": 0.10,
-                            "p10": 200.0,
-                            "p50": 400.0,
-                            "optional": False,
-                        },
-                    ],
-                    "condition": {
-                        "op": "eq",
-                        "name": "event.contexts.browser.name",
-                        "value": "Edge",
-                    },
-                },
-                {
-                    "name": "Opera",
-                    "scoreComponents": [
-                        {
-                            "measurement": "fcp",
-                            "weight": 0.15,
-                            "p10": 900.0,
-                            "p50": 1600.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "lcp",
-                            "weight": 0.30,
-                            "p10": 1200.0,
-                            "p50": 2400.0,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "fid",
-                            "weight": 0.30 if shouldIncludeFid else 0.0,
-                            "p10": 100.0,
-                            "p50": 300.0,
-                            "optional": True,
-                        },
-                        {
-                            "measurement": "cls",
-                            "weight": 0.15,
-                            "p10": 0.1,
-                            "p50": 0.25,
-                            "optional": False,
-                        },
-                        {
-                            "measurement": "ttfb",
-                            "weight": 0.10,
-                            "p10": 200.0,
-                            "p50": 400.0,
-                            "optional": False,
-                        },
-                    ],
-                    "condition": {
-                        "op": "eq",
-                        "name": "event.contexts.browser.name",
-                        "value": "Opera",
-                    },
-                },
-                {
-                    "name": "Chrome INP",
-                    "scoreComponents": [
-                        {
-                            "measurement": "inp",
-                            "weight": 1.0,
-                            "p10": 200.0,
-                            "p50": 500.0,
-                            "optional": False,
-                        },
-                    ],
-                    "condition": {
-                        "op": "or",
-                        "inner": [
-                            {
-                                "op": "eq",
-                                "name": "event.contexts.browser.name",
-                                "value": "Chrome",
-                            },
-                            {
-                                "op": "eq",
-                                "name": "event.contexts.browser.name",
-                                "value": "Google Chrome",
-                            },
-                        ],
-                    },
-                },
-                {
-                    "name": "Edge INP",
-                    "scoreComponents": [
-                        {
-                            "measurement": "inp",
-                            "weight": 1.0,
-                            "p10": 200.0,
-                            "p50": 500.0,
-                            "optional": False,
-                        },
-                    ],
-                    "condition": {
-                        "op": "eq",
-                        "name": "event.contexts.browser.name",
-                        "value": "Edge",
-                    },
-                },
-                {
-                    "name": "Opera INP",
-                    "scoreComponents": [
-                        {
-                            "measurement": "inp",
-                            "weight": 1.0,
-                            "p10": 200.0,
-                            "p50": 500.0,
-                            "optional": False,
-                        },
-                    ],
-                    "condition": {
-                        "op": "eq",
-                        "name": "event.contexts.browser.name",
-                        "value": "Opera",
-                    },
-                },
-            ]
-        }
+    performance_score_profiles = [
+        *_get_browser_performance_profiles(project.organization),
+        *_get_mobile_performance_profiles(project.organization),
+    ]
+    if performance_score_profiles:
+        config["performanceScore"] = {"profiles": performance_score_profiles}
 
     with Hub.current.start_span(op="get_filter_settings"):
         if filter_settings := get_filter_settings(project):