Repository: getsentry/sentry-python

Issue:
Add enableTracing option
A new simplified options for configuring to turn tracing & performance on should be added to all SDKs. For each SDK the default sample rate should be agreed upon. 

Docs do not need to be updated yet, nor the onboarding wizard. This can wait until the top level options are added to a number of SDKs and we decide if we want to configure the default onboarding experience, for all new users.

See [develop docs](https://develop.sentry.dev/sdk/performance/#enabletracing) for more information. This is a non-breaking change to be clear. Any of the three options should enable performance, alone or in combination

### Open point:
recommend default it 1.0 or 100%. Can discuss if it should be less.

Discussion:

Patch:
diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py
index 24a8b3c2..0ea23650 100644
--- a/sentry_sdk/client.py
+++ b/sentry_sdk/client.py
@@ -98,6 +98,9 @@ def _get_options(*args, **kwargs):
 
         rv["project_root"] = project_root
 
+    if rv["enable_tracing"] is True and rv["traces_sample_rate"] is None:
+        rv["traces_sample_rate"] = 1.0
+
     return rv
 
 
diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py
index 743e869a..a2ba2c88 100644
--- a/sentry_sdk/consts.py
+++ b/sentry_sdk/consts.py
@@ -122,6 +122,7 @@ class ClientConstructor(object):
         instrumenter=INSTRUMENTER.SENTRY,  # type: Optional[str]
         before_send_transaction=None,  # type: Optional[TransactionProcessor]
         project_root=None,  # type: Optional[str]
+        enable_tracing=None,  # type: Optional[bool]
     ):
         # type: (...) -> None
         pass
diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py
index cc1851ff..52941b4f 100644
--- a/sentry_sdk/tracing_utils.py
+++ b/sentry_sdk/tracing_utils.py
@@ -114,12 +114,14 @@ def has_tracing_enabled(options):
     # type: (Dict[str, Any]) -> bool
     """
     Returns True if either traces_sample_rate or traces_sampler is
-    defined, False otherwise.
+    defined and enable_tracing is set and not false.
     """
-
     return bool(
-        options.get("traces_sample_rate") is not None
-        or options.get("traces_sampler") is not None
+        options.get("enable_tracing") is not False
+        and (
+            options.get("traces_sample_rate") is not None
+            or options.get("traces_sampler") is not None
+        )
     )
 
 


Test patch:
diff --git a/tests/test_basics.py b/tests/test_basics.py
index 37aafed3..60c1822b 100644
--- a/tests/test_basics.py
+++ b/tests/test_basics.py
@@ -25,6 +25,7 @@ from sentry_sdk.scope import (  # noqa: F401
     global_event_processors,
 )
 from sentry_sdk.utils import get_sdk_name
+from sentry_sdk.tracing_utils import has_tracing_enabled
 
 
 def test_processors(sentry_init, capture_events):
@@ -231,6 +232,32 @@ def test_option_before_breadcrumb(sentry_init, capture_events, monkeypatch):
     assert crumb["type"] == "default"
 
 
+@pytest.mark.parametrize(
+    "enable_tracing, traces_sample_rate, tracing_enabled, updated_traces_sample_rate",
+    [
+        (None, None, False, None),
+        (False, 0.0, False, 0.0),
+        (False, 1.0, False, 1.0),
+        (None, 1.0, True, 1.0),
+        (True, 1.0, True, 1.0),
+        (None, 0.0, True, 0.0),  # We use this as - it's configured but turned off
+        (True, 0.0, True, 0.0),  # We use this as - it's configured but turned off
+        (True, None, True, 1.0),
+    ],
+)
+def test_option_enable_tracing(
+    sentry_init,
+    enable_tracing,
+    traces_sample_rate,
+    tracing_enabled,
+    updated_traces_sample_rate,
+):
+    sentry_init(enable_tracing=enable_tracing, traces_sample_rate=traces_sample_rate)
+    options = Hub.current.client.options
+    assert has_tracing_enabled(options) is tracing_enabled
+    assert options["traces_sample_rate"] == updated_traces_sample_rate
+
+
 def test_breadcrumb_arguments(sentry_init, capture_events):
     assert_hint = {"bar": 42}