Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logger metadata can mangle span_ids #117

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/spandex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ defmodule Spandex do
adapter = opts[:adapter]

with {:ok, top_span} <- span(name, opts, span_context, adapter) do
Logger.metadata(trace_id: span_context.trace_id, span_id: top_span.id)
update_logger_metadata(trace_id: span_context.trace_id, span_id: top_span.id)

trace = %Trace{
id: span_context.trace_id,
Expand Down Expand Up @@ -483,7 +483,7 @@ defmodule Spandex do

with {:ok, span} <- Span.child_of(current_span, name, adapter.span_id(), adapter.now(), opts),
{:ok, _trace} <- strategy.put_trace(opts[:trace_key], %{trace | stack: [span | trace.stack]}) do
Logger.metadata(span_id: span.id, trace_id: trace.id)
update_logger_metadata(trace_id: trace.id, span_id: span.id)
{:ok, span}
end
end
Expand All @@ -495,7 +495,7 @@ defmodule Spandex do

with {:ok, span} <- span(name, opts, span_context, adapter),
{:ok, _trace} <- strategy.put_trace(opts[:trace_key], %{trace | stack: [span]}) do
Logger.metadata(span_id: span.id, trace_id: trace_id)
update_logger_metadata(trace_id: trace_id, span_id: span.id)
{:ok, span}
end
end
Expand All @@ -507,7 +507,7 @@ defmodule Spandex do
span_context = %SpanContext{trace_id: trace_id}

with {:ok, span} <- span(name, opts, span_context, adapter) do
Logger.metadata(trace_id: trace_id, span_id: span.id)
update_logger_metadata(trace_id: trace_id, span_id: span.id)
trace = %Trace{spans: [], stack: [span], id: trace_id}
strategy.put_trace(opts[:trace_key], trace)
end
Expand Down Expand Up @@ -557,4 +557,8 @@ defmodule Spandex do
{:ok, span} -> span
end
end

defp update_logger_metadata(trace_id: trace_id, span_id: span_id) do
Logger.metadata(trace_id: to_string(trace_id), span_id: to_string(span_id))
end
end