Skip to content

Commit

Permalink
Update to use Spandex.SpanContext
Browse files Browse the repository at this point in the history
  • Loading branch information
GregMefford committed Aug 30, 2018
1 parent a20a7f4 commit 62294a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
29 changes: 13 additions & 16 deletions lib/spandex_ecto/ecto_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ defmodule SpandexEcto.EctoLogger do
query is being run asynchronously (as in the case of parallel preloads).
"""

alias Spandex.{
Span,
SpanContext,
Trace
}

defmodule Error do
defexception [:message]
end
Expand Down Expand Up @@ -91,28 +97,19 @@ defmodule SpandexEcto.EctoLogger do

defp setup(%{caller_pid: caller_pid}, tracer) when is_pid(caller_pid) do
if caller_pid == self() do
Logger.metadata(trace_id: tracer.current_trace_id(), span_id: tracer.current_span_id())

tracer.start_span("query")
else
trace = Process.info(caller_pid)[:dictionary][:spandex_trace]

if trace do
trace_id = trace.id

span_id =
trace
|> Map.get(:stack)
|> Enum.at(0, %{})
|> Map.get(:id)
case Process.info(caller_pid)[:dictionary][:spandex_trace] do
nil -> tracer.start_trace("query")

Logger.metadata(trace_id: trace_id, span_id: span_id)
%Trace{id: trace_id, stack: [%Span{id: span_id} | _]} ->
tracer.continue_trace("query", %SpanContext{trace_id: trace_id, parent_id: span_id})

tracer.continue_trace("query", trace_id, span_id)
else
tracer.start_trace("query")
%Trace{id: trace_id, stack: []} ->
tracer.continue_trace("query", %SpanContext{trace_id: trace_id})
end
end
Logger.metadata(trace_id: tracer.current_trace_id(), span_id: tracer.current_span_id())
end

defp setup(_, _), do: :ok
Expand Down
8 changes: 0 additions & 8 deletions test/spandex_ecto_test.exs

This file was deleted.

0 comments on commit 62294a7

Please sign in to comment.