Skip to content

Commit

Permalink
ft: set message to JSON instead of extracting tags in adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Apr 22, 2024
1 parent 904fb27 commit e7e0946
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
25 changes: 1 addition & 24 deletions lib/logflare/backends/adaptor/datadog_adaptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,32 +159,9 @@ defmodule Logflare.Backends.Adaptor.DatadogAdaptor do

defp translate_event(%Logflare.LogEvent{} = le) do
%{
message: le.body.event_message,
message: Jason.encode!(le.body),
ddsource: "logflare",
ddtags: build_tags(le.body),
service: le.source.name
}
end

defp build_tags(body) do
body
|> Map.drop([:event_message])
|> Enum.map_join(",", fn {key, value} ->
do_build(value, key)
end)
end

defp do_build(map, parent) when is_map(map) do
for {key, value} <- map,
sub <- do_build(value, "#{parent}.#{key}"),
do: sub
end

defp do_build(list, parent) when is_list(list) do
for {value, key} <- Enum.with_index(list),
sub <- do_build(value, "#{parent}.#{key}"),
do: sub
end

defp do_build(other, key), do: ["#{key}:#{other}"]
end
20 changes: 0 additions & 20 deletions test/logflare/backends/adaptor/datadog_adaptor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,5 @@ defmodule Logflare.Backends.Adaptor.DatadogAdaptorTest do
assert_receive {:ok, resp}, 200
assert length(resp) == 4
end

test "metadata other than `event_message` is stored in `ddtags`", %{pid: pid} do
events = [
%Logflare.LogEvent{
body: %{
event_message: "hello world",
foo: "foo",
bar: %{baz: 4}
},
source: %{name: "sample"}
}
]

@subject.ingest(pid, events, [])

assert_receive {:ok, [event]}, 200
assert %{"ddtags" => tags} = event
assert tags =~ ~r/foo:foo/
assert tags =~ ~r/bar\.baz:4/
end
end
end

0 comments on commit e7e0946

Please sign in to comment.