ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - romul/newrelic.ex: NewRelic agent for Elixir
NewRelic agent for Elixir. Contribute to romul/newrelic.ex development by creating an account on GitHub.
Visit Site

GitHub - romul/newrelic.ex: NewRelic agent for Elixir

GitHub - romul/newrelic.ex: NewRelic agent for Elixir

NewRelic agent for Elixir

Build Status

Instrument your Phoenix applications with New Relic.

It currently supports instrumenting Phoenix controllers and Ecto repositories to record response times for web transactions and database queries.

Based on newrelic-erlang and new-relixir

Why yet another?

  1. newrelic-erlang & new-relixir look abandoned, so the main goal is to create a maintainable integration with NewRelic open to pull requests.
  2. newrelic-erlang has a performance issue related to statman usage. Look at a real-world example of new-relixir usage (the project handles about 25 rps):

CPU load Memory usage

The new_relic isn't suffer from such the leaks.

Usage

The following instructions show how to add instrumentation with New Relic to a hypothetical Phoenix application named MyApp.

  1. Add new_relic to your list of dependencies and start-up applications in mix.exs:

    # mix.exs
    
    defmodule MyApp.Mixfile do
      use Mix.Project
    
      # ...
    
      def application do
        [mod: {MyApp, []},
         applications: [:new_relic]]
      end
    
      defp deps do
        [{:new_relic, "~> 0.1.2"}]
      end
    end
    
  2. Add your New Relic application name and license key to config/config.exs. You may wish to use environment variables to keep production, staging, and development environments separate:

    # config/config.exs
    
    config :new_relic,
      application_name: System.get_env("NEWRELIC_APP_NAME"),
      license_key: System.get_env("NEWRELIC_LICENSE_KEY"),
      poll_interval: 60_000 # push data to NewRelic once per 1 minute
    
  3. Define a module to wrap your repository's methods with New Relic instrumentation:

    # lib/my_app/repo.ex
    
    defmodule MyApp.Repo do
      use Ecto.Repo, otp_app: :my_app
    
      defmodule NewRelic do
        use Elixir.NewRelic.Plug.Repo, repo: MyApp.Repo
      end
    end
    

    Now MyApp.Repo.NewRelic can be used as a substitute for MyApp.Repo. If a Plug.Conn is provided as the :conn option to any of the wrapper's methods, it will instrument the response time for that call. Otherwise, the repository will behave the same as the repository that it wraps.

  4. For any Phoenix controller that you want to instrument, add NewRelic.Plug.Phoenix and replace existing aliases to your application's repository with an alias to your New Relic repository wrapper. If instrumenting all controllers, update web/web.ex:

    # web/web.ex
    
    defmodule MyApp.Web do
      def controller do
        quote do
          # ...
          plug NewRelic.Plug.Phoenix
          alias MyApp.Repo.NewRelic, as: Repo # Replaces `alias MyApp.Repo`
        end
      end
    end
    
  5. Update your controllers to pass conn as an option to your New Relic repo wrapper:

    # web/controllers/users.ex
    
    defmodule MyApp.UserController do
      use MyApp.Web, :controller
    
      def index(conn, _params) do
        users = Repo.all(User, conn: conn) # Replaces `Repo.all(User)`
        # ...
      end
    end
    

Instrumenting Custom Repo Methods

If you've defined custom methods on your repository, you will need to define them on your wrapper module as well. In the wrapper module, simply call your repository's original method inside a closure that you pass to instrument_db:

# lib/my_app/repo.ex

defmodule MyApp.Repo do
  use Ecto.Repo, otp_app: :my_app

  def custom_method(queryable, opts \\ []) do
    # ...
  end

  defmodule NewRelic do
    use NewRelic.Plug.Repo, repo: MyApp.Repo

    def custom_method(queryable, opts \\ []) do
      instrument_db(:custom_method, queryable, opts, fn() ->
        MyApp.Repo.custom_method(queryable, opts)
      end)
    end
  end
end

When using the wrapper module's custom_method, the time it takes to call MyApp.Repo.custom_method/2 will be recorded to New Relic.

Distributed under the MIT License.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory