From bba9da0812aea4a07e7646b2e7245799c70f9318 Mon Sep 17 00:00:00 2001 From: Vemparala Surya Vamsi Date: Mon, 29 Jul 2024 12:47:56 +0530 Subject: [PATCH] tiny fix to reduce getCommonTelemetryAttributes overhead --- app/client/src/UITelemetry/generateTraces.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/client/src/UITelemetry/generateTraces.ts b/app/client/src/UITelemetry/generateTraces.ts index 011a66632c75..776d132aec2f 100644 --- a/app/client/src/UITelemetry/generateTraces.ts +++ b/app/client/src/UITelemetry/generateTraces.ts @@ -11,14 +11,14 @@ import { deviceType } from "react-device-detect"; import { APP_MODE } from "entities/App"; import { matchBuilderPath, matchViewerPath } from "constants/routes"; +import memoizeOne from "memoize-one"; const GENERATOR_TRACE = "generator-tracer"; export type OtlpSpan = Span; export type SpanAttributes = Attributes; -const getCommonTelemetryAttributes = () => { - const pathname = window.location.pathname; +const getAppMode = memoizeOne((pathname: string) => { const isEditorUrl = matchBuilderPath(pathname); const isViewerUrl = matchViewerPath(pathname); @@ -27,6 +27,11 @@ const getCommonTelemetryAttributes = () => { : isViewerUrl ? APP_MODE.PUBLISHED : ""; + return appMode; +}); +const getCommonTelemetryAttributes = () => { + const pathname = window.location.pathname; + const appMode = getAppMode(pathname); return { appMode,