Giter VIP home page Giter VIP logo

elixir_agent's Introduction

Community Project header

New Relic's Elixir Agent

Build Status Hex.pm Version Hex Docs License

The Open-Source Elixir Agent allows you to monitor your Elixir applications with New Relic. It helps you track transactions, distributed traces and other parts of your application's behavior and provides an overview of underlying BEAM activity.

View the Documentation

Support Statement

New Relic has open-sourced this project to enable monitoring of Elixir applications. This project is provided AS-IS WITHOUT WARRANTY OR SUPPORT, although you can report issues and contribute to the project here on GitHub.

Contributing

We'd love to get your contributions to improve the elixir agent! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. If you'd like to execute our corporate CLA, or if you have any questions, please drop us an email at [email protected].

Installation

Install the Hex package

Requirements:

  • Erlang/OTP 21
  • Elixir 1.8
defp deps do
  [
    {:new_relic_agent, "~> 1.0"}
  ]
end

Configuration

You need to set a few required configuration keys so we can authenticate properly.

Via Application config

config :new_relic_agent,
  app_name: "My App",
  license_key: "license_key"

Via Environment variables

You can also configure these attributes via ENV vars, which helps keep secrets out of source code.

  • NEW_RELIC_APP_NAME
  • NEW_RELIC_LICENSE_KEY

Instrumentation

Out of the box, we will report Error Traces & some general BEAM VM stats. For further visibility, you'll need to add some basic instrumentation.

Telemetry

Some Elixir packages are auto-instrumented via telemetry

Plug

Plug instrumentation is built into the agent.

  • NewRelic.Transaction enables rich Transaction Monitoring for a Plug pipeline. It's a macro that injects a few plugs and an error handler. Install it by adding use NewRelic.Transaction to your Plug module.
defmodule MyPlug do
  use Plug.Router
  use NewRelic.Transaction
  # ...
end

Function Tracing

  • NewRelic.Tracer enables detailed Function tracing. Annotate a function and it'll show up as a span in Transaction Traces / Distributed Traces, and we'll collect aggregate stats about it. Install it by adding use NewRelic.Tracer to any module, and annotating any function with @trace module attribute
defmodule MyModule do
  use NewRelic.Tracer

  @trace :func
  def func do
    # Will report as `MyModule.func/0`
  end
end
  • NewRelic.Tracer also enables detailed External request tracing. A little more instrumentation is required to pass the trace context forward with Distributed Tracing.
defmodule MyExternalService do
  use NewRelic.Tracer

  @trace {:request, category: :external}
  def request(method, url, headers) do
    NewRelic.set_span(:http, url: url, method: method, component: "HttpClient")
    headers = headers ++ NewRelic.distributed_trace_headers(:http)
    HttpClient.request(method, url, headers)
  end
end

Pre-Instrumented Modules

  • NewRelic.Instrumented.Mix.Task To enable the Agent and record a Transaction during a Mix.Task, simply use NewRelic.Instrumented.Mix.Task. This will ensure the agent is properly started, record the Transaction, and shut down.
defmodule Mix.Tasks.Example do
  use Mix.Task
  use NewRelic.Instrumented.Mix.Task

  def run(args) do
    # ...
  end
end
  • NewRelic.Instrumented.HTTPoison Automatically wraps HTTP calls in a span, and adds an outbound header to track the request as part of a Distributed Trace.
alias NewRelic.Instrumented.HTTPoison
HTTPoison.get("http://www.example.com")

Other Transactions

You may start an "Other" Transaction for non-HTTP related work. This could used be while consuming messages from a broker, for example.

To start an other transaction:

NewRelic.start_transaction(category, name)

And to stop the transaction within the same process:

NewRelic.stop_transaction()

Adapters

There are a few adapters which leverage this agent to provide library / framework specific instrumentation. Note that these will eventually be replaced with telemetry based instrumentation.

elixir_agent's People

Contributors

alejandrodnm avatar barthez avatar binaryseed avatar caiquemitsuoka avatar emeryotopalik avatar ethangunderson avatar jasondew avatar markweitzel avatar mattbaker avatar mirjoy avatar mopp avatar rhruiz avatar sb8244 avatar tomtaylor avatar tpitale avatar vermaxik avatar zoevkay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.