From 95e3d82e8a91e771ce496f05424dcc47d9d72d02 Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Fri, 22 Jan 2021 09:49:53 +0100 Subject: [PATCH] Fix send_params configuration in Appsignal.Plug (#9) Closes #8. --- lib/appsignal_plug.ex | 8 ++++++++ test/appsignal_plug_test.exs | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/appsignal_plug.ex b/lib/appsignal_plug.ex index b08089f..daa7c9e 100644 --- a/lib/appsignal_plug.ex +++ b/lib/appsignal_plug.ex @@ -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 diff --git a/test/appsignal_plug_test.exs b/test/appsignal_plug_test.exs index 383952e..0da1133 100644 --- a/test/appsignal_plug_test.exs +++ b/test/appsignal_plug_test.exs @@ -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",