Skip to content

Commit 0216690

Browse files
Don't set params when send_params is false (#771)
* Add missing test to set parameter values There was no test to make sure the params are actually set. This patch adds a regression test to make sure this isn't broken through future work. * Don't set params when send_params is false Currently, the send_params configuration option is checked in appsignal_plug, in Appsignal.Plug.set_params/2-3. Since parameters are now also added from appsignal_phoenix, and because there's already a distinction between sample data and parameters in Appsignal.Span, Appsignal.Span.set_sample_data/3-4 now checks the send_params configuration if the passed key equals "params". The implementation in appsignal_plug can be removed when depending on the upcoming version of this library.
1 parent 0e15373 commit 0216690

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: "patch"
3+
type: "add"
4+
---
5+
6+
Don't set parameters when the send_params configuration is set to false

lib/appsignal/span.ex

+10-2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,19 @@ defmodule Appsignal.Span do
190190
|> Appsignal.Span.set_sample_data("environment", %{"method" => "GET"})
191191
192192
"""
193-
def set_sample_data(span, "params", value) do
193+
def set_sample_data(span, key, value) do
194+
set_sample_data(span, Application.get_env(:appsignal, :config), key, value)
195+
end
196+
197+
defp set_sample_data(span, %{send_params: true}, "params", value) do
194198
do_set_sample_data(span, "params", Appsignal.Utils.MapFilter.filter(value))
195199
end
196200

197-
def set_sample_data(span, key, value) do
201+
defp set_sample_data(span, _config, "params", _value) do
202+
span
203+
end
204+
205+
defp set_sample_data(span, _config, key, value) do
198206
do_set_sample_data(span, key, value)
199207
end
200208

test/appsignal/span_test.exs

+47-1
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,58 @@ defmodule AppsignalSpanTest do
415415
setup :create_root_span
416416

417417
setup %{span: span} do
418-
[return: Span.set_sample_data(span, "key", %{param: "value"})]
418+
[return: Span.set_sample_data(span, "key", %{foo: "bar"})]
419419
end
420420

421421
test "returns the span", %{span: span, return: return} do
422422
assert return == span
423423
end
424+
425+
test "sets the sample data", %{span: span} do
426+
assert %{"sample_data" => %{"key" => "{\"foo\":\"bar\"}"}} = Span.to_map(span)
427+
end
428+
end
429+
430+
describe ".set_sample_data/3, if send_params is set to false" do
431+
setup :create_root_span
432+
433+
setup %{span: span} do
434+
config = Application.get_env(:appsignal, :config)
435+
Application.put_env(:appsignal, :config, %{config | send_params: false})
436+
437+
try do
438+
Span.set_sample_data(span, "key", %{foo: "bar"})
439+
after
440+
Application.put_env(:appsignal, :config, config)
441+
end
442+
443+
:ok
444+
end
445+
446+
test "sets the sample data", %{span: span} do
447+
assert %{"sample_data" => %{"key" => "{\"foo\":\"bar\"}"}} = Span.to_map(span)
448+
end
449+
end
450+
451+
describe ".set_sample_data/3, if send_params is set to false, when using 'params' as the key" do
452+
setup :create_root_span
453+
454+
setup %{span: span} do
455+
config = Application.get_env(:appsignal, :config)
456+
Application.put_env(:appsignal, :config, %{config | send_params: false})
457+
458+
try do
459+
Span.set_sample_data(span, "params", %{foo: "bar"})
460+
after
461+
Application.put_env(:appsignal, :config, config)
462+
end
463+
464+
:ok
465+
end
466+
467+
test "does not set the sample data", %{span: span} do
468+
assert Span.to_map(span)["sample_data"] == %{}
469+
end
424470
end
425471

426472
describe ".set_sample_data/3, when passing a nil-span" do

0 commit comments

Comments
 (0)