Skip to content

Commit a509ace

Browse files
committed
feat(UI-1898): datadog screen session replays
1 parent 31997c8 commit a509ace

File tree

11 files changed

+172
-4
lines changed

11 files changed

+172
-4
lines changed

.env.example

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
VITE_APP_VERSION=1.0.0
12
VITE_HOST_URL=http://localhost:1234
23
VITE_DESCOPE_PROJECT_ID=descopeProjectId
34
TESTS_JWT_AUTH_TOKEN=jwtAuthTokenToRunE2ETests
45
OPEN_AI_KEY=openAiKey
56

67
# Akbot Integration
78
VITE_AKBOT_URL=http://localhost:9980/ai
8-
# Akbot Integration
9-
VITE_AKBOT_ORIGIN=http://localhost:3000
9+
VITE_AKBOT_ORIGIN=http://localhost:3000
10+
11+
# Datadog RUM Configuration
12+
VITE_DATADOG_APPLICATION_ID=your-datadog-app-id
13+
VITE_DATADOG_CLIENT_TOKEN=your-datadog-client-token
14+
VITE_DATADOG_SITE=datadoghq.com

package-lock.json

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
},
3737
"dependencies": {
3838
"@bufbuild/protobuf": "^1.10.0",
39+
"@datadog/browser-rum": "^6.21.1",
40+
"@datadog/browser-rum-react": "^6.21.1",
3941
"@descope/react-sdk": "^2.16.1",
4042
"@estruyf/github-actions-reporter": "^1.9.2",
4143
"@floating-ui/react": "^0.27.2",

src/app.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect } from "react";
22

3+
import { datadogRum } from "@datadog/browser-rum";
34
import * as Sentry from "@sentry/react";
45
import ga4 from "react-ga4";
56
import { useTranslation } from "react-i18next";
@@ -64,10 +65,17 @@ export const App = () => {
6465

6566
useEffect(() => {
6667
const path = location.pathname + location.search;
68+
6769
ga4.send({
6870
hitType: "pageview",
6971
page: path,
7072
});
73+
74+
datadogRum.startView(path);
75+
76+
datadogRum.setGlobalContextProperty("page.path", location.pathname);
77+
datadogRum.setGlobalContextProperty("page.search", location.search);
78+
datadogRum.setGlobalContextProperty("page.hash", location.hash);
7179
}, [location]);
7280

7381
if (isProduction) {

src/constants/datadog.constants.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Site } from "@datadog/browser-core";
2+
import type { PropagatorType } from "@datadog/browser-rum";
3+
4+
import { isProduction } from "@constants/global.constants";
5+
import { VersionService } from "@src/services/version.service";
6+
7+
export const applicationId: string = import.meta.env.VITE_DATADOG_APPLICATION_ID;
8+
export const clientToken: string = import.meta.env.VITE_DATADOG_CLIENT_TOKEN;
9+
export const site: Site = (import.meta.env.VITE_DATADOG_SITE || "localhost") as Site;
10+
export const datadogVersion: string = VersionService.getCurrentVersion();
11+
export const service = "autokitteh-web-platform";
12+
13+
export const sessionSampleRate = isProduction ? 10 : 100;
14+
export const sessionReplaySampleRate = isProduction ? 5 : 100;
15+
16+
export const allowedTracingUrls = [
17+
{ match: /^https?:\/\/localhost:\d+\//, propagatorTypes: ["datadog" as PropagatorType] },
18+
{ match: /^https?:\/\/[^/]*\.autokitteh\.com\//, propagatorTypes: ["datadog" as PropagatorType] },
19+
];
20+
21+
export const defaultPrivacyLevel = "mask-user-input" as const;

src/constants/global.constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import packageJson from "../../package.json";
55

66
export const isDevelopment = import.meta.env.VITE_NODE_ENV === "development";
77
export const isProduction = import.meta.env.VITE_NODE_ENV === "production";
8+
export const appMode = import.meta.env.VITE_NODE_ENV;
89
export const descopeProjectId: string = import.meta.env.VITE_DESCOPE_PROJECT_ID;
910
export const hubSpotPortalId: string = import.meta.env.VITE_HUBSPOT_PORTAL_ID;
1011
export const hubSpotFormId: string = import.meta.env.VITE_HUBSPOT_FORM_ID;

src/constants/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export {
3434
sessionTerminationDelay,
3535
defaultManifestFileName,
3636
optionalManifestFileName,
37+
appMode,
3738
} from "@constants/global.constants";
3839
export { integrationToEditComponent } from "@constants/connections/editComponentsMapping.constants";
3940
export { formsPerIntegrationsMapping } from "@constants/connections/formsPerIntegrationsMapping.constants";
@@ -105,3 +106,14 @@ export { ActivityState } from "@src/constants/activities.constants";
105106
export { getBillingPlanFeatures } from "@constants/lists";
106107
export { billingUpgradeFetchUrlRetries } from "@src/constants/billing.constants";
107108
export { lintViolationRules } from "@constants/project.constants";
109+
export {
110+
applicationId,
111+
clientToken,
112+
site,
113+
datadogVersion,
114+
service,
115+
sessionSampleRate,
116+
sessionReplaySampleRate,
117+
allowedTracingUrls,
118+
defaultPrivacyLevel,
119+
} from "@constants/datadog.constants";

src/main.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
11
import React from "react";
22

3+
import { datadogRum } from "@datadog/browser-rum";
34
import TimeAgo from "javascript-time-ago";
45
import en from "javascript-time-ago/locale/en";
56
import ReactDOM from "react-dom/client";
67

8+
import { appMode } from "@constants";
9+
import {
10+
applicationId,
11+
clientToken,
12+
site,
13+
datadogVersion,
14+
service,
15+
sessionSampleRate,
16+
sessionReplaySampleRate,
17+
allowedTracingUrls,
18+
defaultPrivacyLevel,
19+
} from "@constants/datadog.constants";
720
import { MainApp } from "@src/mainApp";
821

922
import "./assets/index.css";
1023
import "./i18n";
1124

1225
TimeAgo.addDefaultLocale(en);
1326

27+
if (!applicationId || !clientToken || !datadogVersion) {
28+
datadogRum.init({
29+
applicationId,
30+
clientToken,
31+
site,
32+
service,
33+
env: appMode || "development",
34+
version: datadogVersion,
35+
sessionSampleRate,
36+
sessionReplaySampleRate,
37+
trackResources: true,
38+
trackLongTasks: true,
39+
trackUserInteractions: true,
40+
enablePrivacyForActionName: true,
41+
allowedTracingUrls,
42+
defaultPrivacyLevel,
43+
});
44+
}
45+
1446
ReactDOM.createRoot(document.getElementById("root")!).render(<MainApp />);

src/mainApp.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { useEffect } from "react";
22

3-
import "@utilities/getApiBaseUrl.utils";
4-
3+
import { datadogRum } from "@datadog/browser-rum";
54
import { BrowserRouter } from "react-router-dom";
65

6+
import "@utilities/getApiBaseUrl.utils";
7+
78
import { App } from "./app";
89
import { descopeProjectId } from "@constants";
910
import { VersionService } from "@services";
@@ -21,6 +22,23 @@ export const MainApp = () => {
2122
VersionService.initializeVersionTracking();
2223
}, []);
2324

25+
useEffect(() => {
26+
if (user?.id) {
27+
datadogRum.setUser({
28+
id: user.id,
29+
email: user.email,
30+
name: user.name,
31+
});
32+
}
33+
}, [user]);
34+
35+
useEffect(() => {
36+
if (currentOrganization?.id) {
37+
datadogRum.setGlobalContextProperty("organization.id", currentOrganization.id);
38+
datadogRum.setGlobalContextProperty("organization.name", currentOrganization.displayName);
39+
}
40+
}, [currentOrganization]);
41+
2442
return (
2543
<BrowserRouter>
2644
<ClarityProvider>

src/vite-env.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ interface ImportMetaEnv {
2828
readonly VITE_AKBOT_ORIGIN: string;
2929
readonly VITE_AKBOT_URL: string;
3030
readonly VITE_DISPLAY_BILLING: boolean;
31+
readonly VITE_DATADOG_APPLICATION_ID: string;
32+
readonly VITE_DATADOG_CLIENT_TOKEN: string;
33+
readonly VITE_DATADOG_SITE: string;
3134
}
3235

3336
interface ImportMeta {

0 commit comments

Comments
 (0)