Skip to content

Commit 6ea5f3a

Browse files
Param and session filtering (#27)
* Use Span.to_map to test Plug.set_conn_data/2 The current Elixir integration version automatically handles the skip parameter and skip session data options, meaning that logic can be removed from the Plug integration. To make sure everything keeps working, this patch adds two tests that ensure the params and session data is properly set right now, and after the removal. * Remove config checks for params and session data Since appsignal 2.2.13 (which includes appsignal/appsignal-elixir#771 and appsignal/appsignal-elixir#772), the app's configuration is checked whenever parameters or session data is added to the current span. This patch updates the appsignal version dependency to 2.2.13 or higher, and removes the duplicate checks from Appsignal.Plug.
1 parent 1dd4dfd commit 6ea5f3a

4 files changed

+19
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: "patch"
3+
type: "remove"
4+
---
5+
6+
Remove duplicate session and param filter checks

lib/appsignal_plug.ex

+2-14
Original file line numberDiff line numberDiff line change
@@ -166,33 +166,21 @@ defmodule Appsignal.Plug do
166166
end
167167

168168
defp set_params(span, conn) do
169-
set_params(span, Application.get_env(:appsignal, :config), conn)
170-
end
171-
172-
defp set_params(span, %{send_params: true}, conn) do
173169
%Plug.Conn{params: params} = Plug.Conn.fetch_query_params(conn)
174170
@span.set_sample_data(span, "params", params)
175171
end
176172

177-
defp set_params(span, _config, _conn) do
178-
span
179-
end
180-
181173
defp set_sample_data(span, conn) do
182174
@span.set_sample_data(span, "environment", Appsignal.Metadata.metadata(conn))
183175
end
184176

185-
defp set_session_data(span, conn) do
186-
set_session_data(span, Application.get_env(:appsignal, :config), conn)
187-
end
188-
189-
defp set_session_data(span, %{send_session_data: true}, %Plug.Conn{
177+
defp set_session_data(span, %Plug.Conn{
190178
private: %{plug_session: session, plug_session_fetch: :done}
191179
}) do
192180
@span.set_sample_data(span, "session_data", session)
193181
end
194182

195-
defp set_session_data(span, _config, _conn) do
183+
defp set_session_data(span, _conn) do
196184
span
197185
end
198186
end

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule Appsignal.Plug.MixProject do
4545

4646
[
4747
{:plug, ">= 1.1.0"},
48-
{:appsignal, ">= 2.2.10 and < 3.0.0"},
48+
{:appsignal, ">= 2.2.13 and < 3.0.0"},
4949
{:credo, "~> 1.2", only: [:dev, :test], runtime: false},
5050
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
5151
{:ex_doc, "~> 0.21", only: :dev, runtime: false}

test/appsignal_plug_test.exs

+10-5
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ defmodule Appsignal.PlugTest do
459459
assert Appsignal.Plug.set_conn_data(span, %Plug.Conn{method: "GET", params: %{"id" => "4"}}) ==
460460
span
461461

462-
assert sample_data("params", %{"id" => "4"})
462+
assert %{"sample_data" => %{"params" => ~s({"id":"4"})}} = Appsignal.Span.to_map(span)
463463
end
464464

465465
test "does not set params when send_params is set to false", %{span: span} do
@@ -472,7 +472,8 @@ defmodule Appsignal.PlugTest do
472472
Application.put_env(:appsignal, :config, config)
473473
end
474474

475-
refute sample_data("params", %{"id" => "4"})
475+
%{"sample_data" => sample_data} = Appsignal.Span.to_map(span)
476+
refute Map.has_key?(sample_data, "params")
476477
end
477478

478479
test "sets the span's session data", %{span: span} do
@@ -485,12 +486,15 @@ defmodule Appsignal.PlugTest do
485486
}
486487
}) == span
487488

488-
assert sample_data("session_data", %{key: "value"})
489+
%{"sample_data" => sample_data} = Appsignal.Span.to_map(span)
490+
assert ~s({"key":"value"}) == sample_data["session_data"]
489491
end
490492

491493
test "does not set unfetched session data", %{span: span} do
492494
assert Appsignal.Plug.set_conn_data(span, %Plug.Conn{}) == span
493-
refute sample_data("session_data", %{key: "value"})
495+
496+
%{"sample_data" => sample_data} = Appsignal.Span.to_map(span)
497+
refute Map.has_key?(sample_data, "session_data")
494498
end
495499

496500
test "does not set session data when send_session_data is set to false", %{span: span} do
@@ -510,7 +514,8 @@ defmodule Appsignal.PlugTest do
510514
Application.put_env(:appsignal, :config, config)
511515
end
512516

513-
refute sample_data("session_data", %{key: "value"})
517+
%{"sample_data" => sample_data} = Appsignal.Span.to_map(span)
518+
refute Map.has_key?(sample_data, "session_data")
514519
end
515520
end
516521

0 commit comments

Comments
 (0)