Skip to content

Commit 6eae916

Browse files
axelsonbinaryseed
andauthored
Various doc improvements (#453)
* Various doc improvements * Update lib/new_relic.ex --------- Co-authored-by: Vince Foley <[email protected]>
1 parent 71cabb1 commit 6eae916

File tree

3 files changed

+62
-31
lines changed

3 files changed

+62
-31
lines changed

lib/new_relic.ex

+50-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule NewRelic do
99
The first segment will be treated as the Transaction namespace,
1010
and commonly contains the name of the framework.
1111
12-
**Notes:**
12+
## Notes
1313
* At least 2 segments are required to light up the Transactions UI in APM
1414
1515
In the following example, you will see `/custom/transaction/name`
@@ -43,7 +43,7 @@ defmodule NewRelic do
4343
# "list.length" => 3
4444
```
4545
46-
**Notes:**
46+
## Notes
4747
* Nested Lists and Maps are truncated at 10 items since there are a limited number
4848
of attributes that can be reported on Transaction events
4949
"""
@@ -59,23 +59,26 @@ defmodule NewRelic do
5959
(ie: Not a "Web" Transaction). The first argument will be considered
6060
the "category", the second is the "name".
6161
62-
Examples:
62+
## Examples
6363
6464
```elixir
6565
NewRelic.start_transaction("GenStage", "MyConsumer/EventType")
6666
NewRelic.start_transaction("Task", "TaskName")
6767
```
6868
69-
**Notes:**
69+
> #### Warning {: .error}
70+
>
71+
> * You can't start a new transaction within an existing one. Any process
72+
> spawned inside a transaction belongs to that transaction.
73+
> * Do _not_ use this for processes that live a very long time, doing so
74+
> will risk a memory leak tracking attributes in the transaction!
75+
76+
## Notes
7077
7178
* Don't use this to track Web Transactions - Plug based HTTP servers
7279
are auto-instrumented based on `telemetry` events.
73-
* Do _not_ use this for processes that live a very long time, doing so
74-
will risk a memory leak tracking attributes in the transaction!
75-
* You can't start a new transaction within an existing one. Any process
76-
spawned inside a transaction belongs to that transaction.
7780
* If multiple transactions are started in the same Process, you must
78-
call `NewRelic.stop_transaction()` to mark the end of the transaction.
81+
call `NewRelic.stop_transaction/0` to mark the end of the transaction.
7982
"""
8083
@spec start_transaction(String.t(), String.t()) :: :ok
8184
defdelegate start_transaction(category, name), to: NewRelic.OtherTransaction
@@ -84,7 +87,7 @@ defmodule NewRelic do
8487
Stop an "Other" Transaction.
8588
8689
If multiple transactions are started in the same Process, you must
87-
call `NewRelic.stop_transaction()` to mark the end of the transaction.
90+
call `NewRelic.stop_transaction/0` to mark the end of the transaction.
8891
"""
8992
@spec stop_transaction() :: :ok
9093
defdelegate stop_transaction(), to: NewRelic.OtherTransaction
@@ -93,10 +96,10 @@ defmodule NewRelic do
9396
Define an "Other" transaction with the given block. The return value of
9497
the block is returned.
9598
96-
See `start_transaction` and `stop_transaction` for more details about
99+
See `start_transaction/2` and `stop_transaction/0` for more details about
97100
Transactions.
98101
99-
Example:
102+
## Example
100103
101104
```elixir
102105
defmodule Worker do
@@ -122,6 +125,8 @@ defmodule NewRelic do
122125
@doc """
123126
Call within a transaction to prevent it from reporting.
124127
128+
## Example
129+
125130
```elixir
126131
def index(conn, _) do
127132
NewRelic.ignore_transaction()
@@ -139,20 +144,20 @@ defmodule NewRelic do
139144
@doc """
140145
Advanced:
141146
Return a Transaction reference that can be used to manually connect a
142-
process to a Transaction with `NewRelic.connect_to_transaction()`
147+
process to a Transaction with `NewRelic.connect_to_transaction/1`
143148
"""
144149
defdelegate get_transaction(), to: NewRelic.Transaction.Reporter
145150

146151
@doc """
147152
Advanced:
148153
Call to manually connect the current process to a Transaction. Pass in a reference
149-
returned by `NewRelic.get_transaction()`
154+
returned by `NewRelic.get_transaction/0`
150155
151156
Only use this when there is no auto-discoverable connection (ex: the process was
152157
spawned without links or the logic is within a message handling callback).
153158
154159
This connection will persist until the process exits or
155-
`NewRelic.disconnect_from_transaction()` is called.
160+
`NewRelic.disconnect_from_transaction/0` is called.
156161
"""
157162
defdelegate connect_to_transaction(ref), to: NewRelic.Transaction.Reporter
158163

@@ -166,9 +171,22 @@ defmodule NewRelic do
166171
Store information about the type of work the current span is doing.
167172
168173
Options:
169-
- `:generic, custom: attributes`
170-
- `:http, url: url, method: method, component: component`
171-
- `:datastore, statement: statement, instance: instance, address: address, hostname: hostname, component: component`
174+
- `:type`
175+
- `:generic` - Pass custom attributes
176+
- `:http` - Pass attributes `:url`, `:method`, `:component`
177+
- `:datastore` - Pass attrributes `:statement`, `:instance`, `:address`, `:hostname`,
178+
`:component`
179+
180+
## Examples
181+
182+
```elixir
183+
NewRelic.set_span(:generic, some: "attribute")
184+
185+
NewRelic.set_span(:http, url: "https://elixir-lang.org", method: "GET", component: "HTTPoison")
186+
187+
NewRelic.set_span(:datastore, statement: statement, instance: instance, address: address,
188+
hostname: hostname, component: component)
189+
```
172190
"""
173191
defdelegate set_span(type, attributes), to: NewRelic.DistributedTrace
174192

@@ -182,14 +200,17 @@ defmodule NewRelic do
182200
HTTPoison.get(url, ["x-api-key": "secret"] ++ NewRelic.distributed_trace_headers(:http))
183201
```
184202
185-
**Notes:**
203+
## Notes
186204
187-
* Call `NewRelic.distributed_trace_headers` immediately before making the
205+
* Call `distributed_trace_headers` immediately before making the
188206
request since calling the function marks the "start" time of the request.
189207
"""
190208
defdelegate distributed_trace_headers(type), to: NewRelic.DistributedTrace
191209

192-
@deprecated "Use distributed_trace_headers/1 instead"
210+
@doc """
211+
See: `NewRelic.distributed_trace_headers/1`
212+
"""
213+
@deprecated "Use distributed_trace_headers instead"
193214
defdelegate create_distributed_trace_payload(type),
194215
to: NewRelic.DistributedTrace,
195216
as: :distributed_trace_headers
@@ -222,6 +243,8 @@ defmodule NewRelic do
222243
@doc """
223244
Report a Custom event to NRDB.
224245
246+
## Example
247+
225248
```elixir
226249
NewRelic.report_custom_event("EventType", %{"foo" => "bar"})
227250
```
@@ -233,6 +256,8 @@ defmodule NewRelic do
233256
Report a Dimensional Metric.
234257
Valid types: `:count`, `:gauge`, and `:summary`.
235258
259+
## Example
260+
236261
```elixir
237262
NewRelic.report_dimensional_metric(:count, "my_metric_name", 1, %{some: "attributes"})
238263
```
@@ -243,6 +268,8 @@ defmodule NewRelic do
243268
@doc """
244269
Report a Custom metric.
245270
271+
## Example
272+
246273
```elixir
247274
NewRelic.report_custom_metric("My/Metric", 123)
248275
```
@@ -253,6 +280,8 @@ defmodule NewRelic do
253280
@doc """
254281
Increment a Custom metric.
255282
283+
## Example
284+
256285
```elixir
257286
NewRelic.increment_custom_metric("My/Metric")
258287
```

lib/new_relic/tracer.ex

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ defmodule NewRelic.Tracer do
33
Function Tracing
44
55
To enable function tracing in a particular module, `use NewRelic.Tracer`,
6-
and annotate the functions you want to `@trace`.
6+
and annotate the functions you want to trace with `@trace`.
77
88
Traced functions will report as:
99
- Segments in Transaction Traces
1010
- Span Events in Distributed Traces
1111
- Special custom attributes on Transaction Events
1212
13-
#### Notes:
14-
15-
* Traced functions will *not* be tail-call-recursive. **Don't use this for recursive functions**.
13+
> #### Warning {: .error}
14+
>
15+
> Traced functions will *not* be tail-call-recursive. **Don't use this for recursive functions**.
1616
1717
#### Example
1818
19+
Trace as a function:
20+
1921
```elixir
2022
defmodule MyModule do
2123
use NewRelic.Tracer
@@ -31,7 +33,7 @@ defmodule NewRelic.Tracer do
3133
3234
To categorize External Service calls you must give the trace annotation a category.
3335
34-
You may also call `NewRelic.set_span` to provide better naming for metrics & spans, and additonally annotate the outgoing HTTP headers with the Distributed Tracing context to track calls across services.
36+
You may also call `NewRelic.set_span/2` to provide better naming for metrics & spans, and additonally annotate the outgoing HTTP headers with the Distributed Tracing context to track calls across services.
3537
3638
```elixir
3739
defmodule MyExternalService do

mix.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
66
"db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"},
77
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
8-
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
8+
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
99
"ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"},
1010
"ecto_sql": {:hex, :ecto_sql, "3.11.1", "e9abf28ae27ef3916b43545f9578b4750956ccea444853606472089e7d169470", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ce14063ab3514424276e7e360108ad6c2308f6d88164a076aac8a387e1fea634"},
11-
"ex_doc": {:hex, :ex_doc, "0.31.0", "06eb1dfd787445d9cab9a45088405593dd3bb7fe99e097eaa71f37ba80c7a676", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5350cafa6b7f77bdd107aa2199fe277acf29d739aba5aee7e865fc680c62a110"},
11+
"ex_doc": {:hex, :ex_doc, "0.35.1", "de804c590d3df2d9d5b8aec77d758b00c814b356119b3d4455e4b8a8687aecaf", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "2121c6402c8d44b05622677b761371a759143b958c6c19f6558ff64d0aed40df"},
1212
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
13-
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
14-
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
15-
"makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"},
13+
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
14+
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
15+
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
1616
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
1717
"nimble_options": {:hex, :nimble_options, "1.1.0", "3b31a57ede9cb1502071fade751ab0c7b8dbe75a9a4c2b5bbb0943a690b63172", [:mix], [], "hexpm", "8bbbb3941af3ca9acc7835f5655ea062111c9c27bcac53e004460dfd19008a99"},
1818
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},

0 commit comments

Comments
 (0)