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

Encode logger metadata as string. #127

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
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
8 changes: 4 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)
Logger.metadata(trace_id: to_string(span_context.trace_id), span_id: to_string(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)
Logger.metadata(span_id: to_string(span.id), trace_id: to_string(trace.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)
Logger.metadata(span_id: to_string(span.id), trace_id: to_string(trace_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)
Logger.metadata(trace_id: to_string(trace_id), span_id: to_string(span.id))
trace = %Trace{spans: [], stack: [span], id: trace_id}
strategy.put_trace(opts[:trace_key], trace)
end
Expand Down
4 changes: 2 additions & 2 deletions test/plug/add_context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ defmodule Spandex.Plug.AddContextTest do

assert {:ok, expected_span} = Tracer.start_span("foobar")

assert Keyword.fetch!(Logger.metadata(), :trace_id) == tid
assert Keyword.fetch!(Logger.metadata(), :span_id) == expected_span.id
assert Keyword.fetch!(Logger.metadata(), :trace_id) == to_string(tid)
assert Keyword.fetch!(Logger.metadata(), :span_id) == to_string(expected_span.id)

{:ok, _} = Tracer.finish_trace()

Expand Down