Skip to content

Commit

Permalink
Don't set session when send_session_data is false (#772)
Browse files Browse the repository at this point in the history
Note: this is the same patch as
96c6036, but for session data.

Currently, the send_session_data configuration option is checked in
appsignal_plug, in Appsignal.Plug.set_session_data/2-3.

Since session data is 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_session_data configuration if the passed key equals "session-data".

The implementation in appsignal_plug can be removed when depending on
the upcoming version of this library.
  • Loading branch information
jeffkreeftmeijer authored May 30, 2022
1 parent 96c6036 commit 65c5d71
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
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

0 comments on commit 65c5d71

Please sign in to comment.