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 session when send_session_data is false #772

Merged
merged 1 commit into from
May 30, 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"
---

Don't set session data when the send_session_data configuration is set to false
8 changes: 8 additions & 0 deletions lib/appsignal/span.ex
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,18 @@ defmodule Appsignal.Span do
do_set_sample_data(span, "params", Appsignal.Utils.MapFilter.filter(value))
end

defp set_sample_data(span, %{send_session_data: true}, "session_data", value) do
do_set_sample_data(span, "session-data", value)
end

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

defp set_sample_data(span, _config, "session_data", _value) do
span
end

defp set_sample_data(span, _config, key, value) do
do_set_sample_data(span, key, value)
end
Expand Down
44 changes: 44 additions & 0 deletions test/appsignal/span_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,50 @@ defmodule AppsignalSpanTest do
end
end

describe ".set_sample_data/3, if send_session_data 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_session_data: false})

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

:ok
end

@tag :skip_env_test_no_nif
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_session_data is set to false, when using 'session_data' 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_session_data: false})

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

:ok
end

@tag :skip_env_test_no_nif
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
test "returns nil" do
assert Span.set_sample_data(nil, "key", %{param: "value"}) == nil
Expand Down