Skip to content

Commit bdcc5de

Browse files
committed
Add tracing config option
1 parent 5714b5f commit bdcc5de

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

config/config.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ if config_env() == :test do
1010
send_result: :sync,
1111
send_max_attempts: 1,
1212
dedup_events: false,
13-
test_mode: true
13+
test_mode: true,
14+
tracing: true
1415

1516
config :logger, backends: []
1617

lib/sentry/application.ex

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,27 @@ defmodule Sentry.Application do
2626

2727
integrations_config = Config.integrations()
2828

29+
maybe_span_storage =
30+
if Config.tracing?() do
31+
[Sentry.OpenTelemetry.SpanStorage]
32+
else
33+
[]
34+
end
35+
2936
children =
3037
[
3138
{Registry, keys: :unique, name: Sentry.Transport.SenderRegistry},
3239
Sentry.Sources,
3340
Sentry.Dedupe,
3441
Sentry.ClientReport.Sender,
35-
Sentry.OpenTelemetry.SpanStorage,
3642
{Sentry.Integrations.CheckInIDMappings,
3743
[
3844
max_expected_check_in_time:
3945
Keyword.fetch!(integrations_config, :max_expected_check_in_time)
4046
]}
4147
] ++
4248
maybe_http_client_spec ++
49+
maybe_span_storage ++
4350
[Sentry.Transport.SenderPool]
4451

4552
cache_loaded_applications()

lib/sentry/config.ex

+14
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ defmodule Sentry.Config do
125125
be used as the value for this option.
126126
"""
127127
],
128+
tracing: [
129+
type: :boolean,
130+
default: false,
131+
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.
135+
136+
This feature requires `opentelemetry` package and its integrations with Bandit, Phoenix or Ecto.
137+
"""
138+
],
128139
included_environments: [
129140
type: {:or, [{:in, [:all]}, {:list, {:or, [:atom, :string]}}]},
130141
deprecated: "Use :dsn to control whether to send events to Sentry.",
@@ -627,6 +638,9 @@ defmodule Sentry.Config do
627638
@spec integrations() :: keyword()
628639
def integrations, do: fetch!(:integrations)
629640

641+
@spec tracing?() :: boolean()
642+
def tracing?, do: fetch!(:tracing)
643+
630644
@spec put_config(atom(), term()) :: :ok
631645
def put_config(key, value) when is_atom(key) do
632646
unless key in @valid_keys do

test/sentry/config_test.exs

+9
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ 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
163+
164+
assert_raise ArgumentError, ~r/invalid value for :tracing option/, fn ->
165+
Config.validate!(tracing: "not_a_boolean")
166+
end
167+
end
168+
160169
test ":json_library" do
161170
assert Config.validate!(json_library: Jason)[:json_library] == Jason
162171

test/sentry/opentelemetry/span_processor_test.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule Sentry.Opentelemetry.SpanProcessorTest do
3636
end
3737

3838
test "sends captured root spans as transactions" do
39-
put_test_config(environment_name: "test")
39+
put_test_config(environment_name: "test", tracing: true)
4040

4141
Sentry.Test.start_collecting_sentry_reports()
4242

@@ -55,7 +55,7 @@ defmodule Sentry.Opentelemetry.SpanProcessorTest do
5555
end
5656

5757
test "sends captured spans as transactions with child spans" do
58-
put_test_config(environment_name: "test")
58+
put_test_config(environment_name: "test", tracing: true)
5959

6060
Sentry.Test.start_collecting_sentry_reports()
6161

@@ -92,7 +92,7 @@ defmodule Sentry.Opentelemetry.SpanProcessorTest do
9292
end
9393

9494
test "removes span records from storage after sending a transaction" do
95-
put_test_config(environment_name: "test")
95+
put_test_config(environment_name: "test", tracing: true)
9696

9797
Sentry.Test.start_collecting_sentry_reports()
9898

0 commit comments

Comments
 (0)