open-telemetry / opentelemetry-erlang

OpenTelemetry Erlang SDK
https://opentelemetry.io
Apache License 2.0
332 stars 105 forks source link

logging a keyword list is incorrectly detected as a string #693

Open thomasdziedzic-calmwave opened 9 months ago

thomasdziedzic-calmwave commented 9 months ago

I'm getting an error when using opentelemetry_experimental 0.4.0:

** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an iodata term

    (stdlib 5.2) re.erl:987: :re.replace([msg: "...", event_id: "..."], ~c",?\r?\n *", ~c", ", [{:return, :list}, :global, :unicode])

it's throwing the keyword list into :re.replace at https://github.com/open-telemetry/opentelemetry-erlang/blob/main/apps/opentelemetry_experimental/src/otel_otlp_logs.erl#L77-L78

this is because the keyword list is getting detected as a string on https://github.com/open-telemetry/opentelemetry-erlang/blob/main/apps/opentelemetry_experimental/src/otel_otlp_logs.erl#L71

where the IS_STRING macro is defined as (is_list(String) orelse is_binary(String)) so the keyword list is detected as a STRING because it's a list and so the code tries to do a regex replace on it which leads to the error.

tsloughter commented 9 months ago

Ah yup, that should use unicode:characters_to_binary to check if its a string like is done in otel_otlp_common.