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
44 changes: 27 additions & 17 deletions app/client/src/UITelemetry/generateTraces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import {
osName,
osVersion,
} from "react-device-detect";
import { APP_MODE } from "entities/App";
import { matchBuilderPath, matchViewerPath } from "constants/routes";
import nanoid from "nanoid";
import memoizeOne from "memoize-one";
import { getApplicationParamsFromUrl } from "ee/utils/serviceWorkerUtils";

const GENERATOR_TRACE = "generator-tracer";

Expand All @@ -26,25 +25,36 @@ export type SpanAttributes = Attributes;

const OTLP_SESSION_ID = nanoid();

const getAppMode = memoizeOne((pathname: string) => {
const isEditorUrl = matchBuilderPath(pathname);
const isViewerUrl = matchViewerPath(pathname);

const appMode = isEditorUrl
? APP_MODE.EDIT
: isViewerUrl
? APP_MODE.PUBLISHED
: "";

return appMode;
});
const getAppParams = memoizeOne(
(origin: string, pathname: string, search: string) => {
const applicationParams = getApplicationParamsFromUrl({
origin,
pathname,
search,
});

const {
applicationSlug,
appMode = "",
basePageId: pageId,
branchName,
} = applicationParams || {};

return {
appMode,
pageId,
branchName,
applicationSlug,
};
},
);

export const getCommonTelemetryAttributes = () => {
const pathname = window.location.pathname;
const appMode = getAppMode(pathname);
const { origin, pathname, search } = window.location;
const appParams = getAppParams(origin, pathname, search);

return {
appMode,
...appParams,
deviceType,
browserName,
browserVersion,
Expand Down
3 changes: 3 additions & 0 deletions app/client/src/ce/utils/serviceWorkerUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ describe("serviceWorkerUtils", () => {
const expectedParams: TApplicationParams = {
origin: "https://app.appsmith.com",
basePageId,
applicationSlug: "my-app",
baseApplicationId: undefined,
branchName: "main",
appMode: APP_MODE.EDIT,
Expand All @@ -227,6 +228,7 @@ describe("serviceWorkerUtils", () => {
const expectedParams: TApplicationParams = {
origin: "https://app.appsmith.com",
basePageId,
applicationSlug: "my-app",
baseApplicationId: undefined,
branchName: "main",
appMode: APP_MODE.PUBLISHED,
Expand Down Expand Up @@ -307,6 +309,7 @@ describe("serviceWorkerUtils", () => {
);
const expectedParams: TApplicationParams = {
origin: "https://app.appsmith.com",
applicationSlug: "my-app",
basePageId,
baseApplicationId: undefined,
branchName: "",
Expand Down
17 changes: 11 additions & 6 deletions app/client/src/ce/utils/serviceWorkerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
interface TMatchResult {
basePageId?: string;
baseApplicationId?: string;
applicationSlug?: string;
}

export interface TApplicationParams {
Expand All @@ -22,6 +23,7 @@ export interface TApplicationParams {
baseApplicationId?: string;
branchName: string;
appMode: APP_MODE;
applicationSlug?: string;
}

type TApplicationParamsOrNull = TApplicationParams | null;
Expand Down Expand Up @@ -57,33 +59,36 @@ export const getSearchQuery = (search = "", key: string) => {
};

export const getApplicationParamsFromUrl = (
url: URL,
urlParams: Pick<URL, "origin" | "pathname" | "search">,
): TApplicationParamsOrNull => {
const { origin, pathname, search } = urlParams;
// Get the branch name from the query string
const branchName = getSearchQuery(url.search, "branch");
const branchName = getSearchQuery(search, "branch");

const matchedBuilder: Match<TMatchResult> = matchBuilderPath(url.pathname, {
const matchedBuilder: Match<TMatchResult> = matchBuilderPath(pathname, {
end: false,
});
const matchedViewer: Match<TMatchResult> = matchViewerPath(url.pathname);
const matchedViewer: Match<TMatchResult> = matchViewerPath(pathname);

if (matchedBuilder) {
return {
origin: url.origin,
origin,
basePageId: matchedBuilder.params.basePageId,
baseApplicationId: matchedBuilder.params.baseApplicationId,
branchName,
appMode: APP_MODE.EDIT,
applicationSlug: matchedBuilder.params.applicationSlug,
};
}

if (matchedViewer) {
return {
origin: url.origin,
origin,
basePageId: matchedViewer.params.basePageId,
baseApplicationId: matchedViewer.params.baseApplicationId,
branchName,
appMode: APP_MODE.PUBLISHED,
applicationSlug: matchedViewer.params.applicationSlug,
};
}

Expand Down