Skip to content

Commit

Permalink
Add enable_tracing to default traces_sample_rate to 1.0 (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py authored Feb 16, 2023
1 parent ba1286e commit de3b6c1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
3 changes: 3 additions & 0 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(
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
Expand Down
10 changes: 6 additions & 4 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)


Expand Down
27 changes: 27 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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):
Expand Down Expand Up @@ -231,6 +232,32 @@ def do_this():
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}

Expand Down

0 comments on commit de3b6c1

Please sign in to comment.