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 Nov 4, 2024
1 parent 3fa95ae commit 8d27329
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changesets/set-render-metadata-as-tags-on-render-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: patch
type: add
---

Set render metadata as tags on render error. When a template rendering error is reported, its backtrace is limited to the Elixir process that is spawned to render the template. Add information about the template and view being rendered as tags, to provide additional context about the error.
7 changes: 7 additions & 0 deletions lib/appsignal_phoenix/event_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ 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 8d27329

Please sign in to comment.