inspect terms that otherwise can't be serialized by exporter (#40)

This commit is contained in:
Timmo Verlaan 2021-11-19 02:02:36 +01:00 committed by GitHub
parent 9ce604153d
commit f21b315e3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 12 deletions

View File

@ -26,27 +26,27 @@ defmodule OpentelemetryPhoenix.Reason do
def normalize({:badarity, {fun, args}}) do
{:arity, arity} = Function.info(fun, :arity)
[reason: :badarity, function: "#{inspect(fun)}", arity: arity, args: args]
[reason: :badarity, function: _inspect(fun), arity: arity, args: _inspect(args)]
end
def normalize({:badfun, term}) do
[reason: :badfun, term: term]
[reason: :badfun, term: _inspect(term)]
end
def normalize({:badstruct, struct, term}) do
[reason: :badstruct, struct: struct, term: term]
[reason: :badstruct, struct: struct, term: _inspect(term)]
end
def normalize({:badmatch, term}) do
[reason: :badmatch, term: term]
[reason: :badmatch, term: _inspect(term)]
end
def normalize({:badmap, term}) do
[reason: :badmap, term: term]
[reason: :badmap, term: _inspect(term)]
end
def normalize({:badbool, op, term}) do
[reason: :badbool, operator: op, term: term]
[reason: :badbool, operator: op, term: _inspect(term)]
end
def normalize({:badkey, key}) do
@ -54,23 +54,23 @@ defmodule OpentelemetryPhoenix.Reason do
end
def normalize({:badkey, key, map}) do
[reason: :badkey, key: key, map: map]
[reason: :badkey, key: key, map: _inspect(map)]
end
def normalize({:case_clause, term}) do
[reason: :case_clause, term: term]
[reason: :case_clause, term: _inspect(term)]
end
def normalize({:with_clause, term}) do
[reason: :with_clause, term: term]
[reason: :with_clause, term: _inspect(term)]
end
def normalize({:try_clause, term}) do
[reason: :try_clause, term: term]
[reason: :try_clause, term: _inspect(term)]
end
def normalize({:badarg, payload}) do
[reason: :badarg, payload: payload]
[reason: :badarg, payload: _inspect(payload)]
end
def normalize(other) do
@ -80,4 +80,12 @@ defmodule OpentelemetryPhoenix.Reason do
def normalize(other, _stacktrace) do
[reason: other]
end
defp _inspect(term) do
if String.Chars.impl_for(term) do
term
else
inspect(term)
end
end
end

View File

@ -140,7 +140,7 @@ defmodule OpentelemetryPhoenixTest do
{"exception.message", "Erlang error: :badkey"},
{"exception.stacktrace", _stacktrace},
{:key, :name},
{:map, %{username: "rick"}}
{:map, "%{username: \"rick\"}"}
]
)
],