diff --git a/apps/omg_child_chain/lib/omg_child_chain/release_tasks/set_tracer.ex b/apps/omg_child_chain/lib/omg_child_chain/release_tasks/set_tracer.ex index ec187136c2..a653df57f3 100644 --- a/apps/omg_child_chain/lib/omg_child_chain/release_tasks/set_tracer.ex +++ b/apps/omg_child_chain/lib/omg_child_chain/release_tasks/set_tracer.ex @@ -25,8 +25,6 @@ defmodule OMG.ChildChain.ReleaseTasks.SetTracer do config = Keyword.put(config, :disabled?, get_dd_disabled()) config = Keyword.put(config, :env, get_app_env()) - :ok = Application.put_env(:statix, :tags, ["application:child_chain", "app_env:#{get_app_env()}"], persistent: true) - :ok = Application.put_env(@app, OMG.ChildChain.Tracer, config, persistent: true) end diff --git a/apps/omg_child_chain_rpc/lib/omg_child_chain_rpc/release_tasks/set_tracer.ex b/apps/omg_child_chain_rpc/lib/omg_child_chain_rpc/release_tasks/set_tracer.ex index 4e4139d30d..5a82adf360 100644 --- a/apps/omg_child_chain_rpc/lib/omg_child_chain_rpc/release_tasks/set_tracer.ex +++ b/apps/omg_child_chain_rpc/lib/omg_child_chain_rpc/release_tasks/set_tracer.ex @@ -25,8 +25,6 @@ defmodule OMG.ChildChainRPC.ReleaseTasks.SetTracer do config = Keyword.put(config, :disabled?, get_dd_disabled()) config = Keyword.put(config, :env, get_app_env()) - :ok = Application.put_env(:statix, :tags, ["application:child_chain", "app_env:#{get_app_env()}"], persistent: true) - :ok = Application.put_env(@app, OMG.ChildChainRPC.Tracer, config, persistent: true) :ok = Application.put_env(:spandex_phoenix, :tracer, OMG.ChildChainRPC.Tracer, persistent: true) end diff --git a/apps/omg_status/lib/omg_status/release_tasks/set_tracer.ex b/apps/omg_status/lib/omg_status/release_tasks/set_tracer.ex index 2fc877ffec..22fe58ef1c 100644 --- a/apps/omg_status/lib/omg_status/release_tasks/set_tracer.ex +++ b/apps/omg_status/lib/omg_status/release_tasks/set_tracer.ex @@ -20,7 +20,7 @@ defmodule OMG.Status.ReleaseTasks.SetTracer do @app :omg_status @impl Provider - def init(_args) do + def init(args) do _ = Application.ensure_all_started(:logger) config = Application.get_env(:omg_status, Tracer) config = Keyword.put(config, :disabled?, get_dd_disabled()) @@ -30,6 +30,9 @@ defmodule OMG.Status.ReleaseTasks.SetTracer do # statix setup :ok = Application.put_env(:statix, :host, get_dd_hostname(Application.get_env(:statix, :host)), persistent: true) :ok = Application.put_env(:statix, :port, get_dd_port(Application.get_env(:statix, :port)), persistent: true) + release = Keyword.get(args, :release) + tags = ["application:#{release}", "app_env:#{get_app_env()}", "hostname:#{get_hostname()}"] + :ok = Application.put_env(:statix, :tags, tags, persistent: true) # spandex_datadog setup :ok = @@ -46,6 +49,13 @@ defmodule OMG.Status.ReleaseTasks.SetTracer do :ok = Application.put_env(:spandex_datadog, :sync_threshold, get_sync_threshold(), persistent: true) end + defp get_hostname() do + hostname = validate_hostname(get_env("HOSTNAME")) + + _ = Logger.info("CONFIGURATION: App: #{@app} Key: HOSTNAME Value: #{inspect(hostname)}.") + hostname + end + defp get_dd_disabled() do dd_disabled? = validate_bool( @@ -88,6 +98,9 @@ defmodule OMG.Status.ReleaseTasks.SetTracer do batch_size end + defp validate_hostname(value) when is_binary(value), do: value + defp validate_hostname(_), do: exit("HOSTNAME is not set correctly.") + def get_sync_threshold() do sync_threshold = validate_integer( diff --git a/apps/omg_status/test/omg_status/release_tasks/set_tracer_test.exs b/apps/omg_status/test/omg_status/release_tasks/set_tracer_test.exs index 92a7f52712..36bc8e43c6 100644 --- a/apps/omg_status/test/omg_status/release_tasks/set_tracer_test.exs +++ b/apps/omg_status/test/omg_status/release_tasks/set_tracer_test.exs @@ -31,6 +31,14 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do # it got fiddled before :ok = Application.put_env(@app, Tracer, @configuration_old, persistent: true) :ok = Application.put_env(@app, :spandex_datadog, @configuration_old_spandex_datadog, persistent: true) + :ok = System.delete_env("HOSTNAME") + :ok = System.delete_env("DD_DISABLED") + :ok = System.delete_env("APP_ENV") + :ok = System.delete_env("DD_PORT") + :ok = System.delete_env("DD_HOSTNAME") + :ok = System.delete_env("DD_APM_PORT") + :ok = System.delete_env("BATCH_SIZE") + :ok = System.delete_env("SYNC_THRESHOLD") end) :ok @@ -39,6 +47,7 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do test "if environment variables get applied in the configuration" do :ok = System.put_env("DD_DISABLED", "TRUE") :ok = System.put_env("APP_ENV", "YOLO") + :ok = System.put_env("HOSTNAME", "this is my tracer test 3") :ok = SetTracer.init([]) configuration = Application.get_env(@app, Tracer) disabled_updated = configuration[:disabled?] @@ -56,6 +65,7 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do :ok = Application.put_env(@app, Tracer, @configuration_old, persistent: true) :ok = System.delete_env("DD_DISABLED") :ok = System.delete_env("APP_ENV") + :ok = System.put_env("HOSTNAME", "this is my tracer test 3") :ok = SetTracer.init([]) configuration = Application.get_env(@app, Tracer) sorted_configuration = Enum.sort(configuration) @@ -65,7 +75,9 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do test "if environment variables get applied in the statix configuration" do :ok = System.put_env("DD_HOSTNAME", "cluster") :ok = System.put_env("DD_PORT", "1919") - :ok = SetTracer.init([]) + :ok = System.put_env("HOSTNAME", "this is my tracer test 1") + :ok = System.put_env("APP_ENV", "test 1") + :ok = SetTracer.init(release: :test_case_1) configuration = Enum.sort(Application.get_all_env(:statix)) host = configuration[:host] port = configuration[:port] @@ -76,7 +88,7 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do @configuration_old_statix |> Keyword.put(:host, "cluster") |> Keyword.put(:port, 1919) - |> Keyword.put(:tags, nil) + |> Keyword.put(:tags, ["application:test_case_1", "app_env:test 1", "hostname:this is my tracer test 1"]) |> Enum.sort() end @@ -88,11 +100,13 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do :ok = System.delete_env("DD_HOSTNAME") :ok = System.delete_env("DD_PORT") - :ok = SetTracer.init([]) + :ok = System.put_env("HOSTNAME", "this is my tracer test 2") + :ok = System.put_env("APP_ENV", "test 2") + :ok = SetTracer.init(release: :test_case_2) configuration = Application.get_all_env(:statix) sorted_configuration = Enum.sort(configuration) - - assert sorted_configuration == @configuration_old_statix |> Keyword.put(:tags, nil) |> Enum.sort() + expected_tags = ["application:test_case_2", "app_env:test 2", "hostname:this is my tracer test 2"] + assert sorted_configuration == @configuration_old_statix |> Keyword.put(:tags, expected_tags) |> Enum.sort() end test "if environment variables get applied in the spandex_datadog configuration" do @@ -100,6 +114,7 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do :ok = System.put_env("DD_APM_PORT", "1919") :ok = System.put_env("BATCH_SIZE", "7000") :ok = System.put_env("SYNC_THRESHOLD", "900") + :ok = System.put_env("HOSTNAME", "this is my tracer test 4") :ok = SetTracer.init([]) configuration = Enum.sort(Application.get_all_env(:spandex_datadog)) host = configuration[:host] @@ -130,6 +145,7 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do :ok = System.delete_env("DD_APM_PORT") :ok = System.delete_env("BATCH_SIZE") :ok = System.delete_env("SYNC_THRESHOLD") + :ok = System.put_env("HOSTNAME", "this is my tracer test 5") :ok = SetTracer.init([]) configuration = Application.get_all_env(:spandex_datadog) sorted_configuration = Enum.sort(configuration) @@ -142,4 +158,18 @@ defmodule OMG.Status.ReleaseTasks.SetTracerTest do catch_exit(SetTracer.init([])) :ok = System.delete_env("DD_DISABLED") end + + test "if environment variables get applied in the statix tags configuration" do + :ok = System.put_env("HOSTNAME", "this is my tracer test") + :ok = System.put_env("APP_ENV", "YOLO") + :ok = SetTracer.init([]) + assert Enum.member?(Application.get_env(:statix, :tags), "hostname:this is my tracer test") + end + + test "if exit is thrown when faulty configuration for hostname is used" do + :ok = System.put_env("DD_DISABLED", "TRUE") + :ok = System.put_env("APP_ENV", "YOLO") + assert catch_exit(SetTracer.init([])) == "HOSTNAME is not set correctly." + :ok = System.delete_env("DD_DISABLED") + end end diff --git a/apps/omg_utils/test/omg_utils/http_rpc/response_test.exs b/apps/omg_utils/test/omg_utils/http_rpc/response_test.exs index 9cd172f286..a9fb0cf7dd 100644 --- a/apps/omg_utils/test/omg_utils/http_rpc/response_test.exs +++ b/apps/omg_utils/test/omg_utils/http_rpc/response_test.exs @@ -23,7 +23,6 @@ defmodule OMG.Utils.HttpRPC.ResponseTest do txbytes: nil, txhash: nil, txindex: nil, - metadata: nil, txtype: nil, metadata: nil, inserted_at: nil, diff --git a/apps/omg_watcher/lib/omg_watcher/release_tasks/set_tracer.ex b/apps/omg_watcher/lib/omg_watcher/release_tasks/set_tracer.ex index 40d4f12747..e4dd25276f 100644 --- a/apps/omg_watcher/lib/omg_watcher/release_tasks/set_tracer.ex +++ b/apps/omg_watcher/lib/omg_watcher/release_tasks/set_tracer.ex @@ -25,8 +25,6 @@ defmodule OMG.Watcher.ReleaseTasks.SetTracer do config = Keyword.put(config, :disabled?, get_dd_disabled()) config = Keyword.put(config, :env, get_app_env()) - :ok = Application.put_env(:statix, :tags, ["application:watcher", "app_env:#{get_app_env()}"], persistent: true) - :ok = Application.put_env(@app, OMG.Watcher.Tracer, config, persistent: true) end diff --git a/apps/omg_watcher/test/omg_watcher/release_tasks/set_tracer_test.exs b/apps/omg_watcher/test/omg_watcher/release_tasks/set_tracer_test.exs index dd358528cb..51fc93976c 100644 --- a/apps/omg_watcher/test/omg_watcher/release_tasks/set_tracer_test.exs +++ b/apps/omg_watcher/test/omg_watcher/release_tasks/set_tracer_test.exs @@ -31,6 +31,7 @@ defmodule OMG.Watcher.ReleaseTasks.SetTracerTest do test "if environment variables get applied in the configuration" do :ok = System.put_env("DD_DISABLED", "TRUE") :ok = System.put_env("APP_ENV", "YOLO") + :ok = System.put_env("HOSTNAME", "this is my tracer test 1") :ok = SetTracer.init([]) configuration = Application.get_env(@app, Tracer) disabled_updated = configuration[:disabled?] @@ -46,6 +47,7 @@ defmodule OMG.Watcher.ReleaseTasks.SetTracerTest do test "if default configuration is used when there's no environment variables" do :ok = System.delete_env("DD_DISABLED") + :ok = System.put_env("HOSTNAME", "this is my tracer test2") :ok = System.put_env("APP_ENV", "YOLO") :ok = SetTracer.init([]) configuration = Application.get_env(@app, Tracer) diff --git a/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_tracer.ex b/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_tracer.ex index 672d001f73..d02e6d9954 100644 --- a/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_tracer.ex +++ b/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_tracer.ex @@ -25,9 +25,6 @@ defmodule OMG.WatcherInfo.ReleaseTasks.SetTracer do config = Keyword.put(config, :disabled?, get_dd_disabled()) config = Keyword.put(config, :env, get_app_env()) - :ok = - Application.put_env(:statix, :tags, ["application:watcher_info", "app_env:#{get_app_env()}"], persistent: true) - :ok = Application.put_env(@app, OMG.WatcherInfo.Tracer, config, persistent: true) end diff --git a/rel/config.exs b/rel/config.exs index 335b0524ab..78c22d3e79 100644 --- a/rel/config.exs +++ b/rel/config.exs @@ -55,7 +55,7 @@ release :watcher do {OMG.WatcherRPC.ReleaseTasks.SetTracer, []}, {OMG.WatcherRPC.ReleaseTasks.SetApiMode, :watcher}, {OMG.Status.ReleaseTasks.SetSentry, []}, - {OMG.Status.ReleaseTasks.SetTracer, []}, + {OMG.Status.ReleaseTasks.SetTracer, [release: :watcher]}, {OMG.Status.ReleaseTasks.SetApplication, [release: :watcher, current_version: current_version(:omg_child_chain) <> "+" <> sha]}, {OMG.Watcher.ReleaseTasks.SetChildChain, []}, @@ -104,7 +104,7 @@ release :watcher_info do {OMG.WatcherRPC.ReleaseTasks.SetTracer, []}, {OMG.WatcherRPC.ReleaseTasks.SetApiMode, :watcher_info}, {OMG.Status.ReleaseTasks.SetSentry, []}, - {OMG.Status.ReleaseTasks.SetTracer, []}, + {OMG.Status.ReleaseTasks.SetTracer, [release: :watcher_info]}, {OMG.Status.ReleaseTasks.SetApplication, [release: :watcher_info, current_version: current_version(:omg_child_chain) <> "+" <> sha]}, {OMG.Watcher.ReleaseTasks.SetChildChain, []}, @@ -159,7 +159,7 @@ release :child_chain do {OMG.ChildChainRPC.ReleaseTasks.SetEndpoint, []}, {OMG.ChildChainRPC.ReleaseTasks.SetTracer, []}, {OMG.Status.ReleaseTasks.SetSentry, []}, - {OMG.Status.ReleaseTasks.SetTracer, []}, + {OMG.Status.ReleaseTasks.SetTracer, [release: :child_chain]}, {OMG.Status.ReleaseTasks.SetApplication, [release: :child_chain, current_version: current_version(:omg_child_chain) <> "+" <> sha]} ]