diff --git a/lib/appsignal/utils/data_encoder.ex b/lib/appsignal/utils/data_encoder.ex index 18feb6078..3688b5d61 100644 --- a/lib/appsignal/utils/data_encoder.ex +++ b/lib/appsignal/utils/data_encoder.ex @@ -31,6 +31,9 @@ defmodule Appsignal.Utils.DataEncoder do def encode(resource, {key, value}) when is_binary(value) do Nif.data_set_string(resource, key, value) end + def encode(resource, {key, value}) when is_integer(value) and value >= 9223372036854775808 do + Nif.data_set_string(resource, key, "bigint:#{value}") + end def encode(resource, {key, value}) when is_integer(value) do Nif.data_set_integer(resource, key, value) end @@ -58,6 +61,9 @@ defmodule Appsignal.Utils.DataEncoder do def encode(resource, value) when is_binary(value) do Nif.data_set_string(resource, value) end + def encode(resource, value) when is_integer(value) and value >= 9223372036854775808 do + Nif.data_set_string(resource, "bigint:#{value}") + end def encode(resource, value) when is_integer(value) do Nif.data_set_integer(resource, value) end diff --git a/test/appsignal/utils/data_encoder_test.exs b/test/appsignal/utils/data_encoder_test.exs index 8ba4e88d4..7781d5fe9 100644 --- a/test/appsignal/utils/data_encoder_test.exs +++ b/test/appsignal/utils/data_encoder_test.exs @@ -39,8 +39,15 @@ defmodule Appsignal.Utils.DataEncoderTest do end test "encode a map with an integer value" do - resource = DataEncoder.encode(%{foo: 1}) - assert {:ok, '{"foo":1}'} == Nif.data_to_json(resource) + resource = DataEncoder.encode(%{foo: 9223372036854775807}) + assert {:ok, '{"foo":9223372036854775807}'} == Nif.data_to_json(resource) + end + + test "encode a map with an integer too big for C-lang longs to fit" do + resource = DataEncoder.encode(%{foo: 9223372036854775808}) + assert {:ok, '{"foo":"bigint:9223372036854775808"}'} == Nif.data_to_json(resource) + resource = DataEncoder.encode(%{foo: 9223372036854775809}) + assert {:ok, '{"foo":"bigint:9223372036854775809"}'} == Nif.data_to_json(resource) end test "encode a map with a float value" do @@ -102,8 +109,15 @@ defmodule Appsignal.Utils.DataEncoderTest do end test "encode a list with an integer item" do - resource = DataEncoder.encode([1]) - assert {:ok, '[1]'} == Nif.data_to_json(resource) + resource = DataEncoder.encode([9223372036854775807]) + assert {:ok, '[9223372036854775807]'} == Nif.data_to_json(resource) + end + + test "encode a list with an integer item too big for C-lang longs to fit" do + resource = DataEncoder.encode([9223372036854775808]) + assert {:ok, '["bigint:9223372036854775808"]'} == Nif.data_to_json(resource) + resource = DataEncoder.encode([9223372036854775809]) + assert {:ok, '["bigint:9223372036854775809"]'} == Nif.data_to_json(resource) end test "encode a list with an float item" do