Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set params when send_params is false #771

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type: "add"
type: "fix"

Is it not a bug fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This simply moves setting the params from the Plug integration (the only place params are set right now) to the main Elixir one. We’re doing this so we don’t have to implement it for the LiveView params again.

---

Don't set parameters when the send_params configuration is set to false
12 changes: 10 additions & 2 deletions lib/appsignal/span.ex
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,19 @@ defmodule Appsignal.Span do
|> Appsignal.Span.set_sample_data("environment", %{"method" => "GET"})

"""
def set_sample_data(span, "params", value) do
def set_sample_data(span, key, value) do
set_sample_data(span, Application.get_env(:appsignal, :config), key, value)
end

defp set_sample_data(span, %{send_params: true}, "params", value) do
do_set_sample_data(span, "params", Appsignal.Utils.MapFilter.filter(value))
end

def set_sample_data(span, key, value) do
defp set_sample_data(span, _config, "params", _value) do
span
end

defp set_sample_data(span, _config, key, value) do
do_set_sample_data(span, key, value)
end

Expand Down
48 changes: 47 additions & 1 deletion test/appsignal/span_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,58 @@ defmodule AppsignalSpanTest do
setup :create_root_span

setup %{span: span} do
[return: Span.set_sample_data(span, "key", %{param: "value"})]
[return: Span.set_sample_data(span, "key", %{foo: "bar"})]
end

test "returns the span", %{span: span, return: return} do
assert return == span
end

test "sets the sample data", %{span: span} do
assert %{"sample_data" => %{"key" => "{\"foo\":\"bar\"}"}} = Span.to_map(span)
end
end

describe ".set_sample_data/3, if send_params is set to false" do
setup :create_root_span

setup %{span: span} do
config = Application.get_env(:appsignal, :config)
Application.put_env(:appsignal, :config, %{config | send_params: false})

try do
Span.set_sample_data(span, "key", %{foo: "bar"})
after
Application.put_env(:appsignal, :config, config)
end

:ok
end

test "sets the sample data", %{span: span} do
assert %{"sample_data" => %{"key" => "{\"foo\":\"bar\"}"}} = Span.to_map(span)
end
end

describe ".set_sample_data/3, if send_params is set to false, when using 'params' as the key" do
setup :create_root_span

setup %{span: span} do
config = Application.get_env(:appsignal, :config)
Application.put_env(:appsignal, :config, %{config | send_params: false})

try do
Span.set_sample_data(span, "params", %{foo: "bar"})
after
Application.put_env(:appsignal, :config, config)
end

:ok
end

test "does not set the sample data", %{span: span} do
assert Span.to_map(span)["sample_data"] == %{}
end
end

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