Skip to content

Commit

Permalink
Avoid spamming telemetry with repeated reactdevtools.node_not_found
Browse files Browse the repository at this point in the history
… events (#10541)

* Avoid spamming telemetry with repeated `reactdevtools.node_not_found` events

* rename to distinctOn
  • Loading branch information
Andarist authored May 28, 2024
1 parent e19b3a3 commit f620e9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ export class ReplayWall implements Wall {
// Get the first node ID we found for this fiber ID, if available.
const [nodeId] = fiberIdsToNodeIds.get(fiberId) ?? [];
if (!nodeId) {
sendTelemetryEvent("reactdevtools.node_not_found", payload);
sendTelemetryEvent("reactdevtools.node_not_found", payload, {
distinctOn: fiberId,
});
return;
}

Expand Down
21 changes: 20 additions & 1 deletion src/ui/utils/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,30 @@ export function setTelemetryContext({ id, email, internal }: TelemetryUser) {
}
}

export function sendTelemetryEvent(event: string, tags: any = {}) {
const sentEvents = new Set<string>();

type TelemetryOptions = {
/** It can be used to avoid sending repeated events. It's always combined with `event` for that purpose */
distinctOn?: string;
};

export function sendTelemetryEvent(
event: string,
tags: any = {},
{ distinctOn }: TelemetryOptions = {}
) {
if (userData.get("global_logTelemetryEvent")) {
console.log("telemetry event", { event, tags });
}

if (distinctOn) {
const key = `${event}:${distinctOn}`;
if (sentEvents.has(key)) {
return;
}
sentEvents.add(key);
}

if (skipTelemetry()) {
return;
}
Expand Down

0 comments on commit f620e9e

Please sign in to comment.