Skip to content

Commit

Permalink
use module attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 9, 2019
1 parent fd9383e commit f895594
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/spandex_phoenix/instrumenter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,32 @@ defmodule SpandexPhoenix.Instrumenter do
raise "You must configure a tracer or an otp_app in #{__MODULE__}"
end

@tracer tracer
@otp_app otp_app

@doc false
def phoenix_controller_call(:start, _compiled_meta, %{conn: conn}) do
tracer = tracer || Application.get_env(otp_app, __MODULE__)[:tracer] || raise(@tracer_not_configured_msg)
tracer = @tracer || Application.get_env(@otp_app, __MODULE__)[:tracer] || raise(@tracer_not_configured_msg)
apply(tracer, :start_span, ["Phoenix.Controller", [resource: controller_resource_name(conn)]])
end

@doc false
def phoenix_controller_call(:stop, _time_diff, _start_meta) do
tracer = tracer || Application.get_env(otp_app, __MODULE__)[:tracer] || raise(@tracer_not_configured_msg)
tracer = @tracer || Application.get_env(@otp_app, __MODULE__)[:tracer] || raise(@tracer_not_configured_msg)
apply(tracer, :finish_span, [])
end

@doc false
def phoenix_controller_render(:start, _compiled_meta, %{view: view}) do
tracer = tracer || Application.get_env(otp_app, __MODULE__)[:tracer] || raise(@tracer_not_configured_msg)
tracer = @tracer || Application.get_env(@otp_app, __MODULE__)[:tracer] || raise(@tracer_not_configured_msg)
apply(tracer, :start_span, ["Phoenix.View", [resource: view]])
end

@doc false
def phoenix_controller_render(:stop, _time_diff, _start_meta) do
tracer = tracer || Application.get_env(otp_app, :spandex_phoenix)[:tracer] || raise(@tracer_not_configured_msg)
tracer =
@tracer || Application.get_env(@otp_app, :spandex_phoenix)[:tracer] || raise(@tracer_not_configured_msg)

apply(tracer, :finish_span, [])
end

Expand Down

0 comments on commit f895594

Please sign in to comment.