Skip to content

Commit

Permalink
use private function name, and existing macros
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 1, 2018
1 parent 8b6c2e8 commit 13c4496
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions lib/decorators.ex
Expand Up @@ -24,7 +24,7 @@ if Code.ensure_loaded?(Decorator.Define) do
"""

@tracer Application.get_env(:spandex, :decorators)[:tracer]
def tracer, do: @tracer
def __tracer__(), do: @tracer

use Decorator.Define, span: 0, span: 1, trace: 0, trace: 1

Expand All @@ -41,23 +41,14 @@ if Code.ensure_loaded?(Decorator.Define) do
context.arity
)

quote do
attributes = unquote(attributes)
tracer = attributes[:tracer] || unquote(__MODULE__).tracer()
attributes = Keyword.delete(attributes, :tracer)
tracer = attributes[:tracer] || unquote(__MODULE__).__tracer__()
attributes = Keyword.delete(attributes, :tracer)

_ = tracer.start_trace(unquote(name), attributes)
quote do
require unquote(tracer)

try do
unquote(tracer).trace unquote(name), unquote(attributes) do
unquote(body)
rescue
exception ->
stacktrace = System.stacktrace()
_ = tracer.span_error(exception, stacktrace)

reraise(exception, stacktrace)
after
_ = tracer.finish_trace()
end
end
end
Expand All @@ -75,23 +66,14 @@ if Code.ensure_loaded?(Decorator.Define) do
context.arity
)

quote do
attributes = unquote(attributes)
tracer = attributes[:tracer] || unquote(__MODULE__).tracer()
attributes = Keyword.delete(attributes, :tracer)
tracer = attributes[:tracer] || unquote(__MODULE__).__tracer__()
attributes = Keyword.delete(attributes, :tracer)

_ = tracer.start_span(unquote(name), attributes)
quote do
require unquote(tracer)

try do
unquote(tracer).span unquote(name), unquote(attributes) do
unquote(body)
rescue
exception ->
stacktrace = System.stacktrace()
_ = tracer.span_error(exception, stacktrace)

reraise(exception, stacktrace)
after
_ = tracer.finish_span()
end
end
end
Expand Down

0 comments on commit 13c4496

Please sign in to comment.