Skip to content

Commit 0efd4b8

Browse files
sekiyama58zachdaniel
authored andcommitted
Fix broken Tracer.configure(disabled?: true) (#71)
1 parent 1c051f2 commit 0efd4b8

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

lib/tracer.ex

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ defmodule Spandex.Tracer do
102102
def configure(opts) do
103103
case config(opts, @otp_app) do
104104
:disabled ->
105-
:ok
105+
Application.put_env(@otp_app, __MODULE__, merge_config(opts, @otp_app))
106106

107107
config ->
108108
Application.put_env(@otp_app, __MODULE__, config)
@@ -223,14 +223,17 @@ defmodule Spandex.Tracer do
223223
Spandex.distributed_context(conn, config(opts, @otp_app))
224224
end
225225

226+
defp merge_config(opts, otp_app) do
227+
otp_app
228+
|> Application.get_env(__MODULE__)
229+
|> Kernel.||([])
230+
|> Keyword.merge(opts || [])
231+
|> Optimal.validate!(@opts)
232+
|> Keyword.put(:tracer, __MODULE__)
233+
end
234+
226235
defp config(opts, otp_app) do
227-
config =
228-
otp_app
229-
|> Application.get_env(__MODULE__)
230-
|> Kernel.||([])
231-
|> Keyword.merge(opts || [])
232-
|> Optimal.validate!(@opts)
233-
|> Keyword.put(:tracer, __MODULE__)
236+
config = merge_config(opts, otp_app)
234237

235238
if config[:disabled?] do
236239
:disabled
@@ -242,7 +245,7 @@ defmodule Spandex.Tracer do
242245
defp validate_update_config(opts, otp_app) do
243246
env = Application.get_env(otp_app, __MODULE__)
244247

245-
if env[:disabled] do
248+
if env[:disabled?] do
246249
:disabled
247250
else
248251
schema = %{@opts | defaults: [], required: []}

test/configure_test.exs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmodule Spandex.Test.ConfigureTest do
2+
use ExUnit.Case, async: false
3+
4+
alias Spandex.Test.Util
5+
require Spandex.Test.Support.Tracer
6+
alias Spandex.Test.Support.Tracer
7+
8+
test "disabled tracer should not have results" do
9+
original_env = Application.get_env(:spandex, Tracer)
10+
assert :ok = Tracer.configure(disabled?: true)
11+
12+
Tracer.trace "my_trace" do
13+
end
14+
15+
span = Util.can_fail(fn -> Util.find_span("my_trace") end)
16+
17+
assert(span == nil)
18+
19+
Tracer.configure(original_env)
20+
end
21+
end

0 commit comments

Comments
 (0)