From e7e0946aee640d41097a6e2d71f5b983a4fc6990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Mon, 22 Apr 2024 18:48:50 +0200 Subject: [PATCH] ft: set message to JSON instead of extracting tags in adaptor --- .../backends/adaptor/datadog_adaptor.ex | 25 +------------------ .../backends/adaptor/datadog_adaptor_test.exs | 20 --------------- 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/lib/logflare/backends/adaptor/datadog_adaptor.ex b/lib/logflare/backends/adaptor/datadog_adaptor.ex index 553a73b7b..7c814ec3f 100644 --- a/lib/logflare/backends/adaptor/datadog_adaptor.ex +++ b/lib/logflare/backends/adaptor/datadog_adaptor.ex @@ -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 diff --git a/test/logflare/backends/adaptor/datadog_adaptor_test.exs b/test/logflare/backends/adaptor/datadog_adaptor_test.exs index b0fda5416..b0f14f4f9 100644 --- a/test/logflare/backends/adaptor/datadog_adaptor_test.exs +++ b/test/logflare/backends/adaptor/datadog_adaptor_test.exs @@ -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