Repository: getsentry/sentry

Issue:
Remove unnecessary `start_tansaction` calls
## Description

We have several calls to the Python SDK's `start_transaction` method. Many of these calls are unnecessary, since the SDK is already automatically starting transactions for the places we have added the `start_transaction` calls. Using manual `start_transaction` calls prevents us from being able to take advantage of dynamic sampling and distributed tracing and adds unnecessary complication to our code.

We should evaluate every custom `start_transaction` call in the codebase. We should remove all the unnecessary calls. For the calls that need to remain, we should evaluate whether we can change the `start_transaction` call to `start_span`. We should absolutely ensure we avoid creating transactions within transactions, as doing so causes undefined behavior.

See also: https://www.notion.so/sentry/Sentry-SDK-Custom-Code-and-why-we-Should-fix-it-932c8493c29b4bb2bf18c2fc4b729ef1?pvs=4#06a7f5ab24bb47ab968b6add75e17a25

## Related Issues/PRs
Parent issue: #56248

```[tasklist]
### Subtasks
- [ ] #63948
- [ ] getsentry/getsentry#12730
- [ ] https://github.com/getsentry/sentry/issues/63951
- [ ] https://github.com/getsentry/sentry/pull/64272
- [ ] https://github.com/getsentry/sentry/pull/64285
- [ ] https://github.com/getsentry/sentry/pull/64367
- [ ] https://github.com/getsentry/sentry/pull/64579
- [ ] https://github.com/getsentry/sentry/pull/64582
- [ ] https://github.com/getsentry/sentry/pull/64864
- [ ] https://github.com/getsentry/sentry/pull/65157
- [x] [in progress] Investigate if we can remove https://github.com/getsentry/sentry/blob/25df01d67ca3bfc7e5a38fb1142a3f242b784127/src/sentry/shared_integrations/client/base.py#L239 (removed in #65157)
- [x] [This `start_transaction`](https://github.com/getsentry/sentry/blob/1ba56fd0a60e34e0f693d60ded19c4947dc90024/src/sentry/replays/usecases/reader.py#L252) is very weird, take a look later (included in #64864)
- [x] Create more subtasks once existing ones complete
- [ ] #65423
```

## Notes
  - For now, the [`start_transaction` call in `src/sentry/ingest/consumer/processors.py`](https://github.com/getsentry/sentry/blob/e6e4b445c4e5ba8da51a9c45b62d754ad6ce5e89/src/sentry/ingest/consumer/processors.py#L41) appears okay to stay, since we are not already auto-instrumenting. If we create a Kafka integration, as suggested in https://github.com/getsentry/sentry-python/issues/2367, we could remove this manual `start_transaction` call.




Discussion:

Resolving patch:
diff --git a/src/sentry/snuba/tasks.py b/src/sentry/snuba/tasks.py
--- a/src/sentry/snuba/tasks.py
+++ b/src/sentry/snuba/tasks.py
@@ -275,28 +275,23 @@ def subscription_checker(**kwargs):
     Checks for subscriptions stuck in a transition status and attempts to repair them
     """
     count = 0
-    with sentry_sdk.start_transaction(
-        op="subscription_checker",
-        name="subscription_checker",
-        sampled=False,
+    for subscription in QuerySubscription.objects.filter(
+        status__in=(
+            QuerySubscription.Status.CREATING.value,
+            QuerySubscription.Status.UPDATING.value,
+            QuerySubscription.Status.DELETING.value,
+        ),
+        date_updated__lt=timezone.now() - SUBSCRIPTION_STATUS_MAX_AGE,
     ):
-        for subscription in QuerySubscription.objects.filter(
-            status__in=(
-                QuerySubscription.Status.CREATING.value,
-                QuerySubscription.Status.UPDATING.value,
-                QuerySubscription.Status.DELETING.value,
-            ),
-            date_updated__lt=timezone.now() - SUBSCRIPTION_STATUS_MAX_AGE,
-        ):
-            with sentry_sdk.start_span(op="repair_subscription") as span:
-                span.set_data("subscription_id", subscription.id)
-                span.set_data("status", subscription.status)
-                count += 1
-                if subscription.status == QuerySubscription.Status.CREATING.value:
-                    create_subscription_in_snuba.delay(query_subscription_id=subscription.id)
-                elif subscription.status == QuerySubscription.Status.UPDATING.value:
-                    update_subscription_in_snuba.delay(query_subscription_id=subscription.id)
-                elif subscription.status == QuerySubscription.Status.DELETING.value:
-                    delete_subscription_from_snuba.delay(query_subscription_id=subscription.id)
+        with sentry_sdk.start_span(op="repair_subscription") as span:
+            span.set_data("subscription_id", subscription.id)
+            span.set_data("status", subscription.status)
+            count += 1
+            if subscription.status == QuerySubscription.Status.CREATING.value:
+                create_subscription_in_snuba.delay(query_subscription_id=subscription.id)
+            elif subscription.status == QuerySubscription.Status.UPDATING.value:
+                update_subscription_in_snuba.delay(query_subscription_id=subscription.id)
+            elif subscription.status == QuerySubscription.Status.DELETING.value:
+                delete_subscription_from_snuba.delay(query_subscription_id=subscription.id)
 
     metrics.incr("snuba.subscriptions.repair", amount=count)


Test patch: