diff --git a/.github/workflows/deploy-production.yaml b/.github/workflows/deploy-production.yaml index b110190d..787251b1 100644 --- a/.github/workflows/deploy-production.yaml +++ b/.github/workflows/deploy-production.yaml @@ -47,5 +47,7 @@ jobs: SSH_HOST: ${{ vars.SSH_HOST }} GIT_BRANCH: ${{ github.head_ref || github.ref_name }} CONTINUATION_TOKEN_FORMAT: "large" + NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }} + NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME }} run: | ansible-playbook -i ansible/inventory.yaml ansible/playbooks/deployment.yaml diff --git a/.github/workflows/deploy-testing.yaml b/.github/workflows/deploy-testing.yaml index f27ac3ee..fbf5d76b 100644 --- a/.github/workflows/deploy-testing.yaml +++ b/.github/workflows/deploy-testing.yaml @@ -52,5 +52,7 @@ jobs: ENABLE_LISTENER: "true" ENABLE_GATEWAY_DATA: "true" CONTINUATION_TOKEN_FORMAT: "large" + NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }} + NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME }} run: | ansible-playbook -i ansible/inventory.yaml ansible/playbooks/deployment.yaml diff --git a/ansible/playbooks/deployment.yaml b/ansible/playbooks/deployment.yaml index 71691115..f3829ed5 100644 --- a/ansible/playbooks/deployment.yaml +++ b/ansible/playbooks/deployment.yaml @@ -81,6 +81,8 @@ prover_storage: "{{ lookup('ansible.builtin.env', 'PROVER_STORAGE') }}" enable_listener: "{{ lookup('ansible.builtin.env', 'ENABLE_LISTENER') }}" enable_gateway_data: "{{ lookup('ansible.builtin.env', 'ENABLE_GATEWAY_DATA') }}" + newrelic_key: "{{ lookup('ansible.builtin.env', 'NEWRELIC_KEY') }}" + newrelic_app_name: "{{ lookup('ansible.builtin.env', 'NEWRELIC_APP_NAME') }}" - name: Create user systemd directory ansible.builtin.file: diff --git a/ansible/playbooks/templates/.env.j2 b/ansible/playbooks/templates/.env.j2 index 836fed1e..4bd0fc17 100644 --- a/ansible/playbooks/templates/.env.j2 +++ b/ansible/playbooks/templates/.env.j2 @@ -11,3 +11,5 @@ AWS_REGION={{ aws_region }} PROVER_STORAGE={{ prover_storage }} ENABLE_LISTENER={{ enable_listener }} ENABLE_GATEWAY_DATA={{ enable_gateway_data }} +NEWRELIC_KEY={{ newrelic_key }} +NEWRELIC_APP_NAME={{ newrelic_app_name }} diff --git a/config/runtime.exs b/config/runtime.exs index 83be8026..5a508e75 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -120,6 +120,21 @@ if config_env() == :prod do ], secret_key_base: secret_key_base + # Newrelic agent + newrelic_license_key = + System.get_env("NEWRELIC_KEY") || + raise "environment variable NEWRELIC_KEY is missing." + + newrelic_app_name = + System.get_env("NEWRELIC_APP_NAME") || + raise "environment variable NEWRELIC_APP_NAME is missing." + + config :new_relic_agent, + app_name: newrelic_app_name, + license_key: newrelic_license_key, + # Logs are forwarded directly from Elixir to New Relic + logs_in_context: :direct + # ## SSL Support # # To get SSL working, you will need to add the `https` key diff --git a/mix.exs b/mix.exs index ac0b6a0a..4318369b 100644 --- a/mix.exs +++ b/mix.exs @@ -58,7 +58,8 @@ defmodule StarknetExplorer.MixProject do {:sweet_xml, "~> 0.7.0"}, {:ecto_sqlite3, ">= 0.0.0"}, {:esbuild, "~> 0.4", runtime: Mix.env() == :dev}, - {:scrivener_ecto, "~> 2.7"} + {:scrivener_ecto, "~> 2.7"}, + {:new_relic_agent, "~> 1.0", only: :prod} ] end diff --git a/mix.lock b/mix.lock index bcd745b0..d2544d71 100644 --- a/mix.lock +++ b/mix.lock @@ -32,6 +32,7 @@ "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, "mint": {:hex, :mint, "1.5.1", "8db5239e56738552d85af398798c80648db0e90f343c8469f6c6d8898944fb6f", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "4a63e1e76a7c3956abd2c72f370a0d0aecddc3976dea5c27eccbecfa5e7d5b1e"}, + "new_relic_agent": {:hex, :new_relic_agent, "1.27.8", "a2835b686bc46fc7e53222651cce56a253ae1cedef6dd4042a2f12d41ff95624", [:mix], [{:castore, ">= 0.1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:ecto, ">= 3.4.1", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, ">= 3.4.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.5.5", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, ">= 1.10.4", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 2.4.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:redix, ">= 0.11.0", [hex: :redix, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fd52f329db7d731a767d5f527f4424dd72d26c5c89f04504b769d4fa7f1ee77c"}, "nimble_options": {:hex, :nimble_options, "1.0.2", "92098a74df0072ff37d0c12ace58574d26880e522c22801437151a159392270e", [:mix], [], "hexpm", "fd12a8db2021036ce12a309f26f564ec367373265b53e25403f0ee697380f1b8"}, "nimble_pool": {:hex, :nimble_pool, "1.0.0", "5eb82705d138f4dd4423f69ceb19ac667b3b492ae570c9f5c900bb3d2f50a847", [:mix], [], "hexpm", "80be3b882d2d351882256087078e1b1952a28bf98d0a287be87e4a24a710b67a"}, "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},