From 17c0deb277fa53ba5cbce2cd0623e2af58cccace Mon Sep 17 00:00:00 2001 From: Noemi Date: Thu, 31 Mar 2022 16:23:24 +0200 Subject: [PATCH] Fix `datamap.setFloat` implementation The existing implementation for `datamap.setFloat` mistakenly attempted to use the second argument as both the value to add to the map and the map to add it to. This resulted in an "Invalid argument" error thrown when trying to cast the value as a map. The tests for `Data.generate` tested sending floating point values to the agent using the value `99.0`. Since JavaScript has a unified `number` type for integers and floats alike, `99.0` is the same number as `99`. The implementation of `Data.generate` decides whether to call `datamap.setInteger` or `datamap.setFloat` based on whether `Number.isInteger` returns `true` or `false` -- and it will return `true` for `99.0`, as it would for `99`. This means that, in practice, `datamap.setFloat` was not covered by the tests. --- .../allow-sending-non-integer-values-in-data-maps.md | 6 ++++++ packages/nodejs/ext/appsignal_extension.cpp | 2 +- packages/nodejs/src/__tests__/data.test.ts | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 packages/nodejs/.changesets/allow-sending-non-integer-values-in-data-maps.md diff --git a/packages/nodejs/.changesets/allow-sending-non-integer-values-in-data-maps.md b/packages/nodejs/.changesets/allow-sending-non-integer-values-in-data-maps.md new file mode 100644 index 00000000..77bdf20c --- /dev/null +++ b/packages/nodejs/.changesets/allow-sending-non-integer-values-in-data-maps.md @@ -0,0 +1,6 @@ +--- +bump: "patch" +type: "fix" +--- + +Fix an issue where the AppSignal extension would throw an error when an object containing a non-integer number is sent to it. This would be triggered when calling `setSampleData` with an object containing a non-integer number, or when the values for a metric's tags are non-integer numbers. diff --git a/packages/nodejs/ext/appsignal_extension.cpp b/packages/nodejs/ext/appsignal_extension.cpp index f97311b6..401409d4 100644 --- a/packages/nodejs/ext/appsignal_extension.cpp +++ b/packages/nodejs/ext/appsignal_extension.cpp @@ -182,7 +182,7 @@ Napi::Value SetFloatToDataMap(const Napi::CallbackInfo &info) { Napi::Number num = info[1].As(); Napi::External map = - info[1].As>(); + info[2].As>(); appsignal_data_map_set_float(map.Data(), MakeAppsignalString(key_utf8), num.DoubleValue()); diff --git a/packages/nodejs/src/__tests__/data.test.ts b/packages/nodejs/src/__tests__/data.test.ts index 6ef3fbae..a6737ea6 100644 --- a/packages/nodejs/src/__tests__/data.test.ts +++ b/packages/nodejs/src/__tests__/data.test.ts @@ -17,7 +17,7 @@ describe("Data", () => { const nested = { string: "payload", int: 9999, - float: 99.0, + float: 99.9, 1: true, null: "null_key", null_value: null, @@ -57,7 +57,7 @@ describe("Data", () => { false, "string", 9999, - 99.0, + 99.9, [1, 2, 3], { foo: "bʊr" }, { arr: [1, 2, "three"], foo: "bʊr" }