Skip to content

Commit

Permalink
Add debug logging for endpoint-events
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkreeftmeijer committed Aug 20, 2024
1 parent 7a4515c commit 8d64274
Showing 1 changed file with 58 additions and 15 deletions.
73 changes: 58 additions & 15 deletions lib/appsignal_phoenix/event_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,58 @@ defmodule Appsignal.Phoenix.EventHandler do
end

def phoenix_endpoint_start(_event, _measurements, _metadata, _config) do
parent = @tracer.current_span()
parent_span = @tracer.current_span()

"http_request"
|> @tracer.create_span(parent)
span = "http_request"
|> @tracer.create_span(parent_span)
|> @span.set_attribute("appsignal:category", "call.phoenix_endpoint")

Logger.debug(fn -> """
AppSignal.Phoenix.EventHandler received [:phoenix, :endpoint, :start]:
root_span: #{inspect(@tracer.root_span())}
parent_span: #{inspect(parent_span)}
span: #{inspect(span)}
""" end)
end

def phoenix_endpoint_stop(_event, _measurements, metadata, _config) do
_root_span = set_span_data(@tracer.root_span(), metadata)
root_span = set_span_data(@tracer.root_span(), metadata)
span = @tracer.current_span()

@tracer.current_span()
|> @tracer.close_span()
Logger.debug(fn -> """
AppSignal.Phoenix.EventHandler received [:phoenix, :endpoint, :stop]:
root_span: #{inspect(root_span)}
span: #{inspect(span)}
""" end)

@tracer.close_span(span)
end

def phoenix_router_dispatch_start(_event, _measurements, _metadata, _config) do
parent = @tracer.current_span()
parent_span = @tracer.current_span()

"http_request"
|> @tracer.create_span(parent)
span = "http_request"
|> @tracer.create_span(parent_span)
|> @span.set_attribute("appsignal:category", "call.phoenix_router_dispatch")

Logger.debug(fn -> """
AppSignal.Phoenix.EventHandler received [:phoenix, :router_dispatch, :start]:
root_span: #{inspect(@tracer.root_span())}
parent_span: #{inspect(parent_span)}
span: #{inspect(span)}
""" end)
end

def phoenix_router_dispatch_stop(_event, _measurements, _metadata, _config) do
@tracer.current_span()
|> @tracer.close_span()
span = @tracer.current_span()

Logger.debug(fn -> """
AppSignal.Phoenix.EventHandler received [:phoenix, :router_dispatch, :stop]:
root_span: #{inspect(@tracer.root_span())}
span: #{inspect(span)}
""" end)

@tracer.close_span(span)
end

def phoenix_router_dispatch_exception(
Expand All @@ -71,7 +98,15 @@ defmodule Appsignal.Phoenix.EventHandler do
%{reason: %Plug.Conn.WrapperError{conn: conn, reason: reason, stack: stack}},
_config
) do
add_error(@tracer.root_span(), conn, reason, stack)
root_span = @tracer.root_span()

Logger.debug(fn -> """
AppSignal.Phoenix.EventHandler received [:phoenix, :router_dispatch, :exception]:
root_span: #{inspect(root_span)}
span: #{inspect(@tracer.current_span())}
""" end)

add_error(root_span, conn, reason, stack)
end

def phoenix_router_dispatch_exception(
Expand All @@ -80,7 +115,15 @@ defmodule Appsignal.Phoenix.EventHandler do
%{conn: conn, reason: reason, stacktrace: stack},
_config
) do
add_error(@tracer.root_span(), conn, reason, stack)
root_span = @tracer.root_span()

Logger.debug(fn -> """
AppSignal.Phoenix.EventHandler received [:phoenix, :router_dispatch, :exception]:
root_span: #{inspect(root_span)}
span: #{inspect(@tracer.current_span())}
""" end)

add_error(root_span, conn, reason, stack)
end

defp add_error(
Expand All @@ -106,10 +149,10 @@ defmodule Appsignal.Phoenix.EventHandler do
end

def phoenix_template_render_start(_event, _measurements, metadata, _config) do
parent = @tracer.current_span()
parent_span = @tracer.current_span()

"http_request"
|> @tracer.create_span(parent)
|> @tracer.create_span(parent_span)
|> @span.set_name(
"Render #{inspect(metadata.template)} (#{metadata.format}) template from #{module_name(metadata.view)}"
)
Expand Down

0 comments on commit 8d64274

Please sign in to comment.