Skip to content

Commit 6e922d5

Browse files
committed
Use set_sample_data_if_nil on span close
When closing spans, use `set_sample_data_if_nil` instead of `set_sample_data` as to not override custom instrumentation set by the user while the span was open.
1 parent b259ec5 commit 6e922d5

4 files changed

+11
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: "patch"
3+
type: "fix"
4+
---
5+
6+
Fix an issue in which sample data is overriden by Plug data when the span closes.

lib/appsignal_plug.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ defmodule Appsignal.Plug do
108108
span
109109
|> @span.set_name(Appsignal.Metadata.name(conn))
110110
|> @span.set_attribute("appsignal:category", Appsignal.Metadata.category(conn))
111-
|> @span.set_sample_data("params", Appsignal.Metadata.params(conn))
112-
|> @span.set_sample_data("environment", Appsignal.Metadata.metadata(conn))
113-
|> @span.set_sample_data("session_data", Appsignal.Metadata.session(conn))
111+
|> @span.set_sample_data_if_nil("params", Appsignal.Metadata.params(conn))
112+
|> @span.set_sample_data_if_nil("environment", Appsignal.Metadata.metadata(conn))
113+
|> @span.set_sample_data_if_nil("session_data", Appsignal.Metadata.session(conn))
114114
end
115115

116116
@doc false

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ defmodule Appsignal.Plug.MixProject do
5858

5959
[
6060
{:plug, plug_version},
61-
{:appsignal, ">= 2.7.4 and < 3.0.0"},
61+
{:appsignal, ">= 2.7.6 and < 3.0.0"},
6262
{:credo, "~> 1.2", only: [:dev, :test], runtime: false},
6363
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
6464
{:ex_doc, "~> 0.21", only: :dev, runtime: false},

test/appsignal_plug_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ defmodule Appsignal.PlugTest do
518518
end
519519

520520
defp sample_data(asserted_key, asserted_data) do
521-
{:ok, sample_data} = Test.Span.get(:set_sample_data)
521+
{:ok, sample_data} = Test.Span.get(:set_sample_data_if_nil)
522522

523523
Enum.any?(sample_data, fn {%Span{}, key, data} ->
524524
key == asserted_key and data == asserted_data

0 commit comments

Comments
 (0)