Skip to content

Commit 9078ba6

Browse files
committed
Update traces_sample_rate default value to be
1 parent eabb0ff commit 9078ba6

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

lib/sentry/config.ex

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ defmodule Sentry.Config do
145145
],
146146
traces_sample_rate: [
147147
type: {:custom, __MODULE__, :__validate_traces_sample_rate__, []},
148-
default: 0.0,
148+
default: nil,
149149
doc: """
150150
The sample rate for transaction events. A value between `0.0` and `1.0` (inclusive).
151151
A value of `0.0` means no transactions will be sampled, while `1.0` means all transactions
152-
will be sampled. This value is also used to determine if tracing is enabled: if it's
153-
greater than `0`, tracing is enabled.
152+
will be sampled.
153+
154+
This value is also used to determine if tracing is enabled: if it's not `nil`, tracing is enabled.
154155
155156
Tracing requires OpenTelemetry packages to work. See [the
156157
OpenTelemetry setup documentation](https://opentelemetry.io/docs/languages/erlang/getting-started/)
@@ -662,7 +663,7 @@ defmodule Sentry.Config do
662663
def integrations, do: fetch!(:integrations)
663664

664665
@spec tracing?() :: boolean()
665-
def tracing?, do: fetch!(:traces_sample_rate) > 0.0
666+
def tracing?, do: not is_nil(fetch!(:traces_sample_rate))
666667

667668
@spec put_config(atom(), term()) :: :ok
668669
def put_config(key, value) when is_atom(key) do
@@ -763,12 +764,12 @@ defmodule Sentry.Config do
763764
end
764765
end
765766

766-
def __validate_traces_sample_rate__(float) do
767-
if is_float(float) and float >= 0.0 and float <= 1.0 do
768-
{:ok, float}
767+
def __validate_traces_sample_rate__(value) do
768+
if is_nil(value) or (is_float(value) and value >= 0.0 and value <= 1.0) do
769+
{:ok, value}
769770
else
770771
{:error,
771-
"expected :traces_sample_rate to be a float between 0.0 and 1.0 (included), got: #{inspect(float)}"}
772+
"expected :traces_sample_rate to be nil or a value between 0.0 and 1.0 (included), got: #{inspect(value)}"}
772773
end
773774
end
774775

test/sentry/config_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,12 @@ defmodule Sentry.ConfigTest do
154154
end
155155

156156
test ":traces_sample_rate" do
157+
assert Config.validate!([])[:traces_sample_rate] == nil
158+
159+
assert Config.validate!(traces_sample_rate: nil)[:traces_sample_rate] == nil
160+
assert Config.validate!(traces_sample_rate: 0.0)[:traces_sample_rate] == 0.0
161+
assert Config.validate!(traces_sample_rate: 0.5)[:traces_sample_rate] == 0.5
157162
assert Config.validate!(traces_sample_rate: 1.0)[:traces_sample_rate] == 1.0
158-
assert Config.validate!([])[:traces_sample_rate] == 0.0
159163

160164
assert_raise ArgumentError, ~r/invalid value for :traces_sample_rate option/, fn ->
161165
Config.validate!(traces_sample_rate: 2.0)

0 commit comments

Comments
 (0)