newrelic / elixir_agent

New Relic's Open Source Elixir Agent

Home Page:https://hex.pm/packages/new_relic_agent

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Explicit way of failing a "other" transaction

VitorTrin opened this issue · comments

Is your feature request related to a problem? Please describe.
The NewRelic.start_transaction() automaticaly catches exceptions and reports errors, which is great for most use cases, but sometimes you can't raise and you still would like to report something. For example, inside Oban jobs, raises are caught by Oban and never end up reported.

Describe the solution you'd like
Add the NewRelic.stop_transaction/1 function. The argument of this function is the error that will be reported

Describe alternatives you've considered
Directly calling NewRelic.Transaction.Reporter.fail/1 with varied levels of success.

@VitorTrin I'm curious, is this not accomplishable by decorating the Oban perform function with something like @trace :perform. Unless I'm misunderstanding how the trace macro works, it does seem to raise the exception after creating a span for it.

rescue
exception ->
message = NewRelic.Util.Error.format_reason(:error, exception)
NewRelic.DistributedTrace.set_span(:error, message: message)
reraise exception, __STACKTRACE__

The trace macro wasn't enough for me because I wanted my job transactions to show up as Oban transactions, not Other

Do they show up in any distinguishable manner? The tracer documentation indicates that it reports the function name.

@trace :func
def func do
# Will report as `MyModule.func/0`
end
end

I'm invested in this as well since it is something I am also trying to get working with Oban