Skip to content

Commit 5e8fc99

Browse files
committed
tracing => traces_sample_rate
1 parent 149d0fe commit 5e8fc99

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

config/config.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if config_env() == :test do
1111
send_max_attempts: 1,
1212
dedup_events: false,
1313
test_mode: true,
14-
tracing: true
14+
traces_sample_rate: 1.0
1515

1616
config :logger, backends: []
1717

lib/sentry/client.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ defmodule Sentry.Client do
117117

118118
result_type = Keyword.get_lazy(opts, :result, &Config.send_result/0)
119119
client = Keyword.get_lazy(opts, :client, &Config.client/0)
120-
sample_rate = Keyword.get_lazy(opts, :sample_rate, &Config.sample_rate/0)
120+
sample_rate = Keyword.get_lazy(opts, :sample_rate, &Config.traces_sample_rate/0)
121121
before_send = Keyword.get_lazy(opts, :before_send, &Config.before_send/0)
122122
after_send_event = Keyword.get_lazy(opts, :after_send_event, &Config.after_send_event/0)
123123

lib/sentry/config.ex

+20-7
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,14 @@ defmodule Sentry.Config do
125125
be used as the value for this option.
126126
"""
127127
],
128-
tracing: [
129-
type: :boolean,
130-
default: false,
128+
traces_sample_rate: [
129+
type: {:custom, __MODULE__, :__validate_traces_sample_rate__, []},
130+
default: 0.0,
131131
doc: """
132-
Whether to enable tracing functionality based on OpenTelemetry. When enabled,
133-
the Sentry SDK will use OpenTelemetry to collect and report distributed tracing
134-
data to Sentry.
132+
The sample rate for transaction events. A value between 0.0 and 1.0 (inclusive).
133+
A value of 0.0 means no transactions will be sampled, while 1.0 means all transactions
134+
will be sampled. This value is also used to determine if tracing is enabled - if it's
135+
greater than 0, tracing is enabled.
135136
136137
This feature requires `opentelemetry` package and you can optionally use integrations with Bandit, Phoenix or Ecto.
137138
"""
@@ -601,6 +602,9 @@ defmodule Sentry.Config do
601602
@spec sample_rate() :: float()
602603
def sample_rate, do: fetch!(:sample_rate)
603604

605+
@spec traces_sample_rate() :: float()
606+
def traces_sample_rate, do: fetch!(:traces_sample_rate)
607+
604608
@spec hackney_opts() :: keyword()
605609
def hackney_opts, do: fetch!(:hackney_opts)
606610

@@ -639,7 +643,7 @@ defmodule Sentry.Config do
639643
def integrations, do: fetch!(:integrations)
640644

641645
@spec tracing?() :: boolean()
642-
def tracing?, do: fetch!(:tracing)
646+
def tracing?, do: fetch!(:traces_sample_rate) > 0.0
643647

644648
@spec put_config(atom(), term()) :: :ok
645649
def put_config(key, value) when is_atom(key) do
@@ -740,6 +744,15 @@ defmodule Sentry.Config do
740744
end
741745
end
742746

747+
def __validate_traces_sample_rate__(float) do
748+
if is_float(float) and float >= 0.0 and float <= 1.0 do
749+
{:ok, float}
750+
else
751+
{:error,
752+
"expected :traces_sample_rate to be a float between 0.0 and 1.0 (included), got: #{inspect(float)}"}
753+
end
754+
end
755+
743756
def __validate_json_library__(nil) do
744757
{:error, "nil is not a valid value for the :json_library option"}
745758
end

test/sentry/config_test.exs

+5-5
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ defmodule Sentry.ConfigTest do
157157
end
158158
end
159159

160-
test ":tracing" do
161-
assert Config.validate!(tracing: true)[:tracing] == true
162-
assert Config.validate!([])[:tracing] == false
160+
test ":traces_sample_rate" do
161+
assert Config.validate!(traces_sample_rate: 1.0)[:traces_sample_rate] == 1.0
162+
assert Config.validate!([])[:traces_sample_rate] == 0.0
163163

164-
assert_raise ArgumentError, ~r/invalid value for :tracing option/, fn ->
165-
Config.validate!(tracing: "not_a_boolean")
164+
assert_raise ArgumentError, ~r/invalid value for :traces_sample_rate option/, fn ->
165+
Config.validate!(traces_sample_rate: 2.0)
166166
end
167167
end
168168

test/sentry/opentelemetry/span_processor_test.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule Sentry.Opentelemetry.SpanProcessorTest do
2626

2727
@tag span_storage: true
2828
test "sends captured root spans as transactions" do
29-
put_test_config(environment_name: "test", tracing: true)
29+
put_test_config(environment_name: "test", traces_sample_rate: 1.0)
3030

3131
Sentry.Test.start_collecting_sentry_reports()
3232

@@ -46,7 +46,7 @@ defmodule Sentry.Opentelemetry.SpanProcessorTest do
4646

4747
@tag span_storage: true
4848
test "sends captured spans as transactions with child spans" do
49-
put_test_config(environment_name: "test", tracing: true)
49+
put_test_config(environment_name: "test", traces_sample_rate: 1.0)
5050

5151
Sentry.Test.start_collecting_sentry_reports()
5252

@@ -84,7 +84,7 @@ defmodule Sentry.Opentelemetry.SpanProcessorTest do
8484

8585
@tag span_storage: true
8686
test "removes span records from storage after sending a transaction", %{table_name: table_name} do
87-
put_test_config(environment_name: "test", tracing: true)
87+
put_test_config(environment_name: "test", traces_sample_rate: 1.0)
8888

8989
Sentry.Test.start_collecting_sentry_reports()
9090

0 commit comments

Comments
 (0)