elixir_agent icon indicating copy to clipboard operation
elixir_agent copied to clipboard

New Relic Elixir agent installation issue

Open blaugrana17 opened this issue 3 years ago • 15 comments

Hey guys! I’m working on installing the NewRelic Elixir agent to my Elixir/Phoenix project. I’m using this GitHub - newrelic/elixir_agent: New Relic's Open Source Elixir Agent official repository for that and followed this instruction elixir_agent/README.md at master · newrelic/elixir_agent · GitHub and it, unfortunately, didn’t work. One of my colleagues said that he previously had an issue with installing and configuring Elixir on the other project and his opinion on the reason for that issue was Elixir and Phoenix versions.

The current version of elixir and phoenix is 1.7.4 and 1.4.0 as well. I tried to do the installation using elixir version 1.9.2 and phoenix version 1.4.0 and didn’t succeed.

I see no errors and at the same time, my application isn’t appearing in Newrelic dashboard, which’s quite confusing.

Is there anything else that must be configured or considered besides what’s mentioned in the installation instruction above?

Thanks a lot!

blaugrana17 avatar Sep 27 '21 08:09 blaugrana17

What OTP version is running? 21 is the minimum version required

binaryseed avatar Sep 27 '21 17:09 binaryseed

@binaryseed I've created a sample setup that doesn't work for us - https://github.com/maxprokopiev/new_relic_elixir_test

it uses elixir:1.9.4-alpine docker image which supposed to use the OTP_VERSION=22.3.4.21 (https://hub.docker.com/layers/elixir/library/elixir/1.9.4-alpine/images/sha256-6b2be54f4cd56e69ecf491ba065b38633df7f4ac1de7e7b0b6119c2c2da06c58?context=explore)

if you try to run docker-compose run dev mix run -e TestApp.hello with a valid NR license key it executes without any errors but also we cannot see anything in the NR dashboard

maxprokopiev avatar Oct 13 '21 08:10 maxprokopiev

also at the same time I cannot see Elixir in the list of the APM agents https://docs.newrelic.com/docs/agents/ maybe we're trying to use smth that is not supported at all? is there any place with official docs from NR on how to set this up?

maxprokopiev avatar Oct 13 '21 08:10 maxprokopiev

This elixir-agent is open source and not fully supported by NewRelic at this time: https://github.com/newrelic/elixir_agent#support-statement

tpitale avatar Nov 09 '21 23:11 tpitale

@maxprokopiev Have you tried setting the license key not as a config option but as an env variable NEW_RELIC_LICENSE_KEY? I feel like I've seen this issue before.

tpitale avatar Nov 09 '21 23:11 tpitale

This code: https://github.com/newrelic/elixir_agent/blob/0ba0e9ad2a538d8b46a6c7055d7332df9cf95c30/lib/new_relic/init.ex#L107-L112

Is called during init here: https://github.com/newrelic/elixir_agent/blob/0ba0e9ad2a538d8b46a6c7055d7332df9cf95c30/lib/new_relic/init.ex#L24

I'll try to test this locally to see if I can figure out what is up.

tpitale avatar Nov 09 '21 23:11 tpitale

Well, I was wrong … this part at least works.

tpitale avatar Nov 09 '21 23:11 tpitale

Okay, I was able to test locally with my own code using the license key configured both in config and env. Both worked. I'll try to get your example and test it @maxprokopiev

tpitale avatar Nov 10 '21 01:11 tpitale

@tpitale thanks for the response! With the license key either in config or env we get the same - apps work fine, but nothing in new relic dashboard

maxprokopiev avatar Nov 11 '21 09:11 maxprokopiev

@maxprokopiev Have you tried setting the log level to :debug in your config.exs? config :logger, level: :debug? I think the logs go to log/new_relic.log by default. https://github.com/newrelic/elixir_agent/blob/0ba0e9ad2a538d8b46a6c7055d7332df9cf95c30/lib/new_relic/logger.ex#L5-L9

tpitale avatar Dec 01 '21 18:12 tpitale

You can also configure where it logs to: https://github.com/newrelic/elixir_agent/blob/0ba0e9ad2a538d8b46a6c7055d7332df9cf95c30/lib/new_relic/config.ex#L37-L55

tpitale avatar Dec 01 '21 18:12 tpitale

@maxprokopiev In your example, the application ends before the agent has a chance to send any data. I ran it and saw a new app show up in APM after I made some changes:

  1. I added the config logger I shared above. I did not see any mention of Transaction Event Harvest
  2. I changed the TestApp to run more code:
defmodule TestApp do
  @moduledoc """
  Documentation for TestApp.
  """

  use NewRelic.Tracer

  @doc """
  Hello world.

  ## Examples

      iex> TestApp.hello()
      :world

  """
  def hello do
    Application.ensure_all_started(:new_relic_agent)
    IO.puts("======")
    NewRelic.start_transaction("Test", "Name")
    Enum.each(1..100, &say_hello("world", &1))
    NewRelic.stop_transaction()
    IO.puts("======")
    Application.stop(:new_relic_agent)
  end

  @trace :say_hello
  def say_hello(to, x) do
    IO.puts("Hello, #{to} #{x}")
    Process.sleep(100)
  end
end
  1. Re-ran, saw a new APM app show up. Saw this in the log: [DEBUG] - 2021-12-01 19:14:05 - Completed Transaction Event harvest - size: 0, seen: 0, max: 83

tpitale avatar Dec 01 '21 19:12 tpitale

All that said, at this rate of transactions (1/run) it'll take a little for the data to show up at all. But, I did see the BEAM tab in APM and can see records of process counts and memory usage/reductions. So data is flowing.

tpitale avatar Dec 01 '21 19:12 tpitale

Note, in the example I gave, I did have to do Application.ensure_all_started(:new_relic_agent). Not sure yet why that seemed to be required for this example, but most apps running with mix do no need that as long as the agent is a dependency. Could be an elixir 1.9 => 1.10 change?

tpitale avatar Dec 01 '21 19:12 tpitale

@tpitale heya, I can confirm that with your example it works and we have data in the dashboard now 🎉 thanks big time for that ✨

I'll try to experiment more and drill down to the minimum requirements but so far I can see 3 things that we had to add in order for the data to show up:

  • Application.ensure_all_started(:new_relic_agent)
  • higher rate of transactions for the test app (shouldn't be an issue for the real one)
  • license key should be defined in env as NEW_RELIC_LICENSE_KEY, with the license key defined in config :new_relic_agent I get [ERROR] - 2021-12-13 09:01:30 - preconnect: (410) force_disconnect - NewRelic::Agent::LicenseException - Invalid license key on each run 🤔

maxprokopiev avatar Dec 13 '21 09:12 maxprokopiev