feat(spans-migration): self-hosted migration for transaction alerts#111348
feat(spans-migration): self-hosted migration for transaction alerts#111348nikkikapadia wants to merge 3 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Redundant 50-line Dataset enum duplicates existing module
- Removed the redundant 50-line Dataset enum and replaced its usage with string literals since the migration only uses three values and already imports live code from the codebase.
Or push these changes by commenting:
@cursor push 1f9a9dd231
Preview (1f9a9dd231)
diff --git a/src/sentry/migrations/1056_transactions_to_spans_alerts_self_hosted.py b/src/sentry/migrations/1056_transactions_to_spans_alerts_self_hosted.py
--- a/src/sentry/migrations/1056_transactions_to_spans_alerts_self_hosted.py
+++ b/src/sentry/migrations/1056_transactions_to_spans_alerts_self_hosted.py
@@ -1,6 +1,5 @@
# Generated by Django 5.2.12 on 2026-03-20 19:02
-from enum import Enum
from django.db import migrations
from sentry.explore.translation.alerts_translation import (
@@ -15,65 +14,10 @@
import sentry_sdk
-class Dataset(Enum):
- Events = "events"
- "The events dataset contains all ingested errors."
-
- Transactions = "transactions"
- "The transactions dataset contains all ingested transactions."
-
- Discover = "discover"
- "The discover dataset is a combination of both the events and transactions datasets."
-
- Outcomes = "outcomes"
- """
- The outcomes dataset contains materialized views of raw outcomes.
- Outcomes are used to track usage of the product, i.e. how many errors has the
- project ingested, etc.
- """
-
- OutcomesRaw = "outcomes_raw"
- "The raw, non materialized version of the above"
-
- Sessions = "sessions"
- "The sessions dataset is deprecated."
-
- Metrics = "metrics"
- "this 'metrics' dataset is only used for release health."
-
- PerformanceMetrics = "generic_metrics"
- """
- PerformanceMetrics contains all generic metrics platform metrics.
- """
-
- Replays = "replays"
- "Indexed data for the Session Replays feature"
-
- Profiles = "profiles"
- "Indexed data for the Profiling feature"
-
- IssuePlatform = "search_issues"
- "Issues made via the issue platform will be searchable via the IssuePlatform dataset"
-
- Functions = "functions"
- "The functions dataset is built on top of profiling and contains more granular data about profiling functions"
-
- SpansIndexed = "spans"
- """
- Contains span data which is searchable.
- This is different from metrics,
- indexed spans are similar to indexed transactions in the fields available to search
- """
-
- EventsAnalyticsPlatform = "events_analytics_platform"
-
-
def migrate_transactions_to_spans_alerts_self_hosted(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
- qs = SnubaQuery.objects.filter(
- dataset__in=[Dataset.PerformanceMetrics.value, Dataset.Transactions.value]
- )
+ qs = SnubaQuery.objects.filter(dataset__in=["generic_metrics", "transactions"])
for snuba_query in RangeQuerySetWrapperWithProgressBar(qs):
try:
@@ -86,7 +30,7 @@
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
qs = SnubaQuery.objects.filter(
- dataset=Dataset.EventsAnalyticsPlatform.value, query_snapshot__isnull=False
+ dataset="events_analytics_platform", query_snapshot__isnull=False
)
for snuba_query in RangeQuerySetWrapperWithProgressBar(qs):This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
| indexed spans are similar to indexed transactions in the fields available to search | ||
| """ | ||
|
|
||
| EventsAnalyticsPlatform = "events_analytics_platform" |
There was a problem hiding this comment.
Redundant 50-line Dataset enum duplicates existing module
Low Severity
The migration defines a full 50-line copy of the Dataset enum, but only uses three of its values (PerformanceMetrics, Transactions, EventsAnalyticsPlatform). Since the migration already imports live code from sentry.snuba.models and sentry.explore.translation.alerts_translation (which itself imports Dataset from sentry.snuba.dataset), the local copy provides no isolation benefit. It could simply from sentry.snuba.dataset import Dataset or use the three string literals directly.
There was a problem hiding this comment.
this is correct practice for migrations like this
|
This PR has a migration; here is the generated SQL for for --
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL |



all the migrations in SaaS are done for am2/3 and have sat for a bit, I haven't seen any big complaints come in so i assume it's good to go for self-hosted as well. This migration converts all
transactionsorgeneric_metricsalerts to EAP spans alerts. I'm reusing the same scripts we used for the migration jobs here. I've also created tests for multiple different scenarios that we filter for within the script to ensure it's behaving as expected.