Skip to content

Commit de3b6c1

Browse files
authored
Add enable_tracing to default traces_sample_rate to 1.0 (#1900)
1 parent ba1286e commit de3b6c1

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

sentry_sdk/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def _get_options(*args, **kwargs):
9898

9999
rv["project_root"] = project_root
100100

101+
if rv["enable_tracing"] is True and rv["traces_sample_rate"] is None:
102+
rv["traces_sample_rate"] = 1.0
103+
101104
return rv
102105

103106

sentry_sdk/consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __init__(
122122
instrumenter=INSTRUMENTER.SENTRY, # type: Optional[str]
123123
before_send_transaction=None, # type: Optional[TransactionProcessor]
124124
project_root=None, # type: Optional[str]
125+
enable_tracing=None, # type: Optional[bool]
125126
):
126127
# type: (...) -> None
127128
pass

sentry_sdk/tracing_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ def has_tracing_enabled(options):
114114
# type: (Dict[str, Any]) -> bool
115115
"""
116116
Returns True if either traces_sample_rate or traces_sampler is
117-
defined, False otherwise.
117+
defined and enable_tracing is set and not false.
118118
"""
119-
120119
return bool(
121-
options.get("traces_sample_rate") is not None
122-
or options.get("traces_sampler") is not None
120+
options.get("enable_tracing") is not False
121+
and (
122+
options.get("traces_sample_rate") is not None
123+
or options.get("traces_sampler") is not None
124+
)
123125
)
124126

125127

tests/test_basics.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
global_event_processors,
2626
)
2727
from sentry_sdk.utils import get_sdk_name
28+
from sentry_sdk.tracing_utils import has_tracing_enabled
2829

2930

3031
def test_processors(sentry_init, capture_events):
@@ -231,6 +232,32 @@ def do_this():
231232
assert crumb["type"] == "default"
232233

233234

235+
@pytest.mark.parametrize(
236+
"enable_tracing, traces_sample_rate, tracing_enabled, updated_traces_sample_rate",
237+
[
238+
(None, None, False, None),
239+
(False, 0.0, False, 0.0),
240+
(False, 1.0, False, 1.0),
241+
(None, 1.0, True, 1.0),
242+
(True, 1.0, True, 1.0),
243+
(None, 0.0, True, 0.0), # We use this as - it's configured but turned off
244+
(True, 0.0, True, 0.0), # We use this as - it's configured but turned off
245+
(True, None, True, 1.0),
246+
],
247+
)
248+
def test_option_enable_tracing(
249+
sentry_init,
250+
enable_tracing,
251+
traces_sample_rate,
252+
tracing_enabled,
253+
updated_traces_sample_rate,
254+
):
255+
sentry_init(enable_tracing=enable_tracing, traces_sample_rate=traces_sample_rate)
256+
options = Hub.current.client.options
257+
assert has_tracing_enabled(options) is tracing_enabled
258+
assert options["traces_sample_rate"] == updated_traces_sample_rate
259+
260+
234261
def test_breadcrumb_arguments(sentry_init, capture_events):
235262
assert_hint = {"bar": 42}
236263

0 commit comments

Comments
 (0)