NewRelicAddons v0.1.0 NewRelicAddons.Decorators View Source

Provides easy-to-use stackable decorators for the official New Relic library.

Features

  • decorators are stackable with others e.g. from other libraries
  • allows to hide args in event tracer via hide_args option
  • includes transaction tracer with process-based scoping and customizable category name

Usage

You must first include decorators in your module:

use NewRelicAddons.Decorators

Then you can start decorating specific functions:

@decorate new_relic_event()
defp some_long_operation do
  # ...
end

@decorate new_relic_event()
defp other_long_operation do
  # ...
end

...or the entire module:

@decorate_all new_relic_event()

# ...

...or if you expect vulnerable function attributes:

@decorate new_relic_event(hide_args: true)
defp change_password(user, new_password) do
  # ...
end

If these functions are called within Phoenix web request processes and you've already configured NewRelicPhoenix, then you're good to go - decorated calls will now appear within your web transactions.

If you however want to trace functions from outside of Phoenix flow (e.g. background jobs or any GenServers), you'll also have to wrap the processing function in a transaction:

@decorate new_relic_transaction()
defp process do
  some_long_operation()
  other_long_operation()
end

@decorate new_relic_event()
defp some_long_operation do
  # ...
end

@decorate new_relic_event()
defp other_long_operation do
  # ...
end

You may also specify a custom category:

@decorate new_relic_transaction("RPC")
defp process_rpc_call(request) do
  # ...
end

Keep in mind that the function wrapped in transaction decorator will be called on separate process in order to control the lifecycle of the transaction. The process is spawned via Task.async and awaited upon for infinity - thus not changing the initial behavior. Even though the timeout is set to :infinity, the transaction function should not be long-running or you'll run into trouble (see NewRelic.start_transaction/2).

Link to this section Summary

Link to this section Functions

Link to this macro

new_relic_event() View Source (macro)

Link to this macro

new_relic_event(var1) View Source (macro)

Link to this function

new_relic_event(opts \\ [], body, map) View Source

Link to this macro

new_relic_transaction() View Source (macro)

Link to this macro

new_relic_transaction(var1) View Source (macro)

Link to this function

new_relic_transaction(opts \\ [], body, map) View Source