diff --git a/README.md b/README.md index 08e407b..ac9c46e 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,9 @@ blank or non-string `name`. Tag values are cleaned before sending: `null` and `undefined` values are left out, and anything else is converted with `String()`. A value whose -conversion throws drops the whole report, with a `debug` line. +conversion throws drops the whole report, with a `debug` line. A `tags` +that is not an object at all (`null`, a string, a number, from untyped +code) is ignored, and the event is sent with only the client's own tags. The limits are also available as `TraceClient.TIMEOUT_MS` (5000), `TraceClient.IN_FLIGHT_CAPACITY` (256), `TraceClient.MAX_VERSION_LENGTH` diff --git a/tests/trace-client.test.ts b/tests/trace-client.test.ts index f99802d..a5a56b2 100644 --- a/tests/trace-client.test.ts +++ b/tests/trace-client.test.ts @@ -566,6 +566,19 @@ describe("TraceClient", () => { await client.close(); }); + it("sends the event with only the program version when untyped code passes null or a non-object as tags", async () => { + const client = new TraceClient(baseUrl, "MyGame", { version: "1.2.3", key: "k", debug }); + for (const tags of [null, 42, "loose", true]) { + await client.report("startup", { tags: tags as unknown as Record }); + } + assert.equal(capture.requests.length, 4, "a tags value that is not an object is ignored, not a drop"); + for (const request of capture.requests) { + assert.deepEqual(JSON.parse(request.body), { application: "MyGame", name: "startup", tags: { version: "1.2.3" } }); + } + await client.close(); + assert.deepEqual(log, [], "ignoring a non-object tags value is not a serialize failure"); + }); + it("drops a report whose tags cannot be serialized, without throwing", async () => { const client = new TraceClient(baseUrl, "MyGame", { version: "1.2.3", key: "k", debug }); const hostile = {