Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
13 changes: 13 additions & 0 deletions tests/trace-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> });
}
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 = {
Expand Down
Loading