Skip to content

Commit

Permalink
Set render metadata as tags
Browse files Browse the repository at this point in the history
When an error happens during rendering, the backtrace of it is
limited to the Elixir process that is spawned for the rendering task,
lacking any context from the customer's own code. To ameliorate this
issue, add the rendering metadata as tags to the root span, providing
some additional context in the resulting error sample.
  • Loading branch information
unflxw committed Oct 11, 2024
1 parent 3fa95ae commit 653c395
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/appsignal_phoenix/event_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ defmodule Appsignal.Phoenix.EventHandler do
def phoenix_template_render_start(_event, _measurements, metadata, _config) do
parent = @tracer.current_span()

_ = @span.set_sample_data_if_nil(@tracer.root_span(), "tags", %{
"phoenix_template" => metadata.template,
"phoenix_format" => metadata.format,
"phoenix_view" => module_name(metadata.view)
})

"http_request"
|> @tracer.create_span(parent)
|> @span.set_name(
Expand Down
12 changes: 12 additions & 0 deletions test/appsignal_phoenix/event_handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ defmodule Appsignal.Phoenix.EventHandlerTest do
assert {:ok, [{%Span{}, "appsignal:category", "render.phoenix_template"}]} =
Test.Span.get(:set_attribute)
end

test "sets the root span's tags" do
assert {:ok,
[
{%Span{}, "tags",
%{
"phoenix_template" => "template",
"phoenix_format" => "html",
"phoenix_view" => "PhoenixWeb.View"
}}
]} = Test.Span.get(:set_sample_data_if_nil)
end
end

describe "after receiving an render-start and an render-stop event" do
Expand Down

0 comments on commit 653c395

Please sign in to comment.