Skip to content

Commit

Permalink
Fix send_params configuration in Appsignal.Plug (#9)
Browse files Browse the repository at this point in the history
Closes #8.
  • Loading branch information
jeffkreeftmeijer authored Jan 22, 2021
1 parent ff9b701 commit 95e3d82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/appsignal_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,18 @@ defmodule Appsignal.Plug do
end

defp set_params(span, conn) do
set_params(span, Application.get_env(:appsignal, :config), conn)
end

defp set_params(span, %{send_params: true}, conn) do
%Plug.Conn{params: params} = Plug.Conn.fetch_query_params(conn)
@span.set_sample_data(span, "params", params)
end

defp set_params(span, _config, _conn) do
span
end

defp set_sample_data(span, conn) do
@span.set_sample_data(span, "environment", Appsignal.Metadata.metadata(conn))
end
Expand Down
20 changes: 20 additions & 0 deletions test/appsignal_plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,26 @@ defmodule Appsignal.PlugTest do
assert Test.Span.get(:set_name) == :error
end

test "sets the span's parameters", %{span: span} do
assert Appsignal.Plug.set_conn_data(span, %Plug.Conn{method: "GET", params: %{"id" => "4"}}) ==
span

assert sample_data("params", %{"id" => "4"})
end

test "does not set params when send_params is set to false", %{span: span} do
config = Application.get_env(:appsignal, :config)
Application.put_env(:appsignal, :config, %{config | send_params: false})

try do
Appsignal.Plug.set_conn_data(span, %Plug.Conn{method: "GET", params: %{"id" => "4"}})
after
Application.put_env(:appsignal, :config, config)
end

refute sample_data("params", %{"id" => "4"})
end

test "sets the span's session data", %{span: span} do
assert Appsignal.Plug.set_conn_data(span, %Plug.Conn{
method: "GET",
Expand Down

0 comments on commit 95e3d82

Please sign in to comment.