changed
README.md
|
@@ -1,4 1,4 @@
|
1
|
- ## New Relic's Open Source Elixir Agent
|
1
|
# New Relic's Open Source Elixir Agent
|
2
2
|
|
3
3
|
[![Version](https://img.shields.io/github/tag/newrelic/elixir_agent.svg)](https://github.com/newrelic/elixir_agent/releases)
|
4
4
|
[![Build Status](https://travis-ci.org/newrelic/elixir_agent.svg?branch=master)](https://travis-ci.org/newrelic/elixir_agent)
|
|
@@ -6,19 6,22 @@
|
6
6
|
|
7
7
|
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.
|
8
8
|
|
9
|
- ## Support Statement:
|
9
|
[View the Documentation](https://hexdocs.pm/new_relic_agent)
|
10
|
|
11
|
## Support Statement
|
10
12
|
|
11
13
|
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.
|
12
14
|
|
13
15
|
## Installation
|
14
16
|
|
15
|
- Requirements:
|
16
|
- * Elixir `1.7`
|
17
|
Install the [Hex package](https://hex.pm/packages/new_relic_agent)
|
17
18
|
|
18
19
|
```elixir
|
19
20
|
defp deps do
|
20
21
|
[
|
21
22
|
{:new_relic_agent, "~> 1.0"},
|
23
|
{:cowboy, "~> 2.0"},
|
24
|
{:plug, "~> 1.6"}
|
22
25
|
]
|
23
26
|
end
|
24
27
|
```
|
|
@@ -42,12 45,38 @@ You can also configure these attributes via `ENV` vars, which helps keep secrets
|
42
45
|
* `NEW_RELIC_APP_NAME`
|
43
46
|
* `NEW_RELIC_LICENSE_KEY`
|
44
47
|
|
48
|
## Instrumentation
|
45
49
|
|
46
|
- #### Logging
|
50
|
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.
|
47
51
|
|
48
|
- The agent will log important events. By default they will go to `tmp/new_relic.log`. You can also configure it to go to `STDOUT` or any other writable file location:
|
52
|
* `NewRelic.Transaction` enables rich Transaction Monitoring for a `Plug` pipeline. It's a macro that injects a few plugs and an error handler.
|
49
53
|
|
50
54
|
```elixir
|
51
|
- config :new_relic_agent,
|
52
|
- log: "stdout"
|
55
|
defmodule MyApp do
|
56
|
use Plug.Router
|
57
|
use NewRelic.Transaction
|
58
|
# ...
|
59
|
end
|
60
|
```
|
61
|
|
62
|
* `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.
|
63
|
|
64
|
```elixir
|
65
|
defmodule MyModule do
|
66
|
use NewRelic.Tracer
|
67
|
|
68
|
@trace :func
|
69
|
def func do
|
70
|
# Will report as `MyModule.func/0`
|
71
|
end
|
72
|
end
|
73
|
```
|
74
|
|
75
|
#### Pre-Instrumented Modules
|
76
|
|
77
|
* `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.
|
78
|
|
79
|
```elixir
|
80
|
alias NewRelic.Instrumented.HTTPoison
|
81
|
HTTPoison.get("http://www.example.com")
|
53
82
|
```
|
changed
VERSION
|
@@ -1 1 @@
|
1
|
- 1.0.0
|
1
|
1.0.1
|
changed
hex_metadata.config
|
@@ -76,9 76,9 @@
|
76
76
|
{<<"requirement">>,<<"~> 1.0">>}],
|
77
77
|
[{<<"app">>,<<"httpoison">>},
|
78
78
|
{<<"name">>,<<"httpoison">>},
|
79
|
- {<<"optional">>,true},
|
79
|
{<<"optional">>,false},
|
80
80
|
{<<"repository">>,<<"hexpm">>},
|
81
|
- {<<"requirement">>,<<">= 1.0.0">>}],
|
81
|
{<<"requirement">>,<<"~> 1.0">>}],
|
82
82
|
[{<<"app">>,<<"cowboy">>},
|
83
83
|
{<<"name">>,<<"cowboy">>},
|
84
84
|
{<<"optional">>,false},
|
|
@@ -89,4 89,4 @@
|
89
89
|
{<<"optional">>,false},
|
90
90
|
{<<"repository">>,<<"hexpm">>},
|
91
91
|
{<<"requirement">>,<<"~> 1.6">>}]]}.
|
92
|
- {<<"version">>,<<"1.0.0">>}.
|
92
|
{<<"version">>,<<"1.0.1">>}.
|
changed
lib/new_relic/harvest/collector/protocol.ex
|
@@ -66,10 66,10 @@ defmodule NewRelic.Harvest.Collector.Protocol do
|
66
66
|
|> URI.to_string()
|
67
67
|
end
|
68
68
|
|
69
|
- defp parse_http_response({:ok, {{_, 200, 'OK'}, _headers, body}}),
|
69
|
defp parse_http_response({:ok, %{status_code: 200, body: body}}),
|
70
70
|
do: {:ok, Jason.decode!(body)}
|
71
71
|
|
72
|
- defp parse_http_response({:ok, {{_, status, _}, _headers, body}}) do
|
72
|
defp parse_http_response({:ok, %{status_code: status, body: body}}) do
|
73
73
|
NewRelic.log(:error, "(#{status}) #{body}")
|
74
74
|
{:error, status}
|
75
75
|
end
|
changed
lib/new_relic/tracer.ex
|
@@ -19,6 19,7 @@ defmodule NewRelic.Tracer do
|
19
19
|
```elixir
|
20
20
|
defmodule MyModule do
|
21
21
|
use NewRelic.Tracer
|
22
|
|
22
23
|
@trace :func
|
23
24
|
def func do
|
24
25
|
# Will report as `MyModule.func/0`
|
|
@@ -33,6 34,7 @@ defmodule NewRelic.Tracer do
|
33
34
|
```elixir
|
34
35
|
defmodule MyExternalService do
|
35
36
|
use NewRelic.Tracer
|
37
|
|
36
38
|
@trace {:query, category: :external}
|
37
39
|
def query(args) do
|
38
40
|
# Make the call
|
changed
lib/new_relic/util.ex
|
@@ -7,31 7,11 @@ defmodule NewRelic.Util do
|
7
7
|
|
8
8
|
def pid, do: System.get_pid() |> String.to_integer()
|
9
9
|
|
10
|
- def get(url, headers, timeout_ms \\ :infinity) do
|
11
|
- with url = to_charlist(url),
|
12
|
- headers = for({k, v} <- headers, do: {to_charlist(k), to_charlist(v)}) do
|
13
|
- :httpc.request(
|
14
|
- :get,
|
15
|
- {url, headers},
|
16
|
- [{:timeout, timeout_ms}],
|
17
|
- []
|
18
|
- )
|
19
|
- end
|
20
|
- end
|
10
|
def post(url, body, headers) when is_binary(body),
|
11
|
do: HTTPoison.post(url, body, headers)
|
21
12
|
|
22
|
- def post(url, body, headers) when is_binary(body) do
|
23
|
- with url = to_charlist(url),
|
24
|
- headers = for({k, v} <- headers, do: {to_charlist(k), to_charlist(v)}) do
|
25
|
- :httpc.request(
|
26
|
- :post,
|
27
|
- {url, headers, 'application/json', body},
|
28
|
- [],
|
29
|
- []
|
30
|
- )
|
31
|
- end
|
32
|
- end
|
33
|
-
|
34
|
- def post(url, body, headers), do: post(url, Jason.encode!(body), headers)
|
13
|
def post(url, body, headers),
|
14
|
do: post(url, Jason.encode!(body), headers)
|
35
15
|
|
36
16
|
def time_to_ms({megasec, sec, microsec}),
|
37
17
|
do: (megasec * 1_000_000 sec) * 1_000 round(microsec / 1_000)
|
|
@@ -85,8 65,8 @@ defmodule NewRelic.Util do
|
85
65
|
|
86
66
|
@aws_vendor_data ["availabilityZone", "instanceId", "instanceType"]
|
87
67
|
defp aws_vendor_hash(url) do
|
88
|
- case get(url, [], 100) do
|
89
|
- {:ok, {{_, 200, 'OK'}, _headers, body}} ->
|
68
|
case HTTPoison.get(url, [], timeout: 100) do
|
69
|
{:ok, %{status_code: 200, body: body}} ->
|
90
70
|
case Jason.decode(body) do
|
91
71
|
{:ok, data} -> Map.take(data, @aws_vendor_data)
|
92
72
|
_ -> nil
|
changed
mix.exs
|
@@ -39,7 39,7 @@ defmodule NewRelic.Mixfile do
|
39
39
|
{:jason, "~> 1.0"},
|
40
40
|
{:plug, "~> 1.6"},
|
41
41
|
{:cowboy, "~> 2.0"},
|
42
|
- {:httpoison, ">= 1.0.0", optional: true}
|
42
|
{:httpoison, "~> 1.0"}
|
43
43
|
]
|
44
44
|
end
|