Skip to content

Commit

Permalink
Fix broken Tracer.configure(disabled?: true) (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
sekiyama58 authored and zachdaniel committed Aug 27, 2018
1 parent 1c051f2 commit 0efd4b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/tracer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ defmodule Spandex.Tracer do
def configure(opts) do
case config(opts, @otp_app) do
:disabled ->
:ok
Application.put_env(@otp_app, __MODULE__, merge_config(opts, @otp_app))

config ->
Application.put_env(@otp_app, __MODULE__, config)
Expand Down Expand Up @@ -223,14 +223,17 @@ defmodule Spandex.Tracer do
Spandex.distributed_context(conn, config(opts, @otp_app))
end

defp merge_config(opts, otp_app) do
otp_app
|> Application.get_env(__MODULE__)
|> Kernel.||([])
|> Keyword.merge(opts || [])
|> Optimal.validate!(@opts)
|> Keyword.put(:tracer, __MODULE__)
end

defp config(opts, otp_app) do
config =
otp_app
|> Application.get_env(__MODULE__)
|> Kernel.||([])
|> Keyword.merge(opts || [])
|> Optimal.validate!(@opts)
|> Keyword.put(:tracer, __MODULE__)
config = merge_config(opts, otp_app)

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

if env[:disabled] do
if env[:disabled?] do
:disabled
else
schema = %{@opts | defaults: [], required: []}
Expand Down
21 changes: 21 additions & 0 deletions test/configure_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Spandex.Test.ConfigureTest do
use ExUnit.Case, async: false

alias Spandex.Test.Util
require Spandex.Test.Support.Tracer
alias Spandex.Test.Support.Tracer

test "disabled tracer should not have results" do
original_env = Application.get_env(:spandex, Tracer)
assert :ok = Tracer.configure(disabled?: true)

Tracer.trace "my_trace" do
end

span = Util.can_fail(fn -> Util.find_span("my_trace") end)

assert(span == nil)

Tracer.configure(original_env)
end
end

0 comments on commit 0efd4b8

Please sign in to comment.