Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(observability) remove datadog RUM and consolidate to logs-only observability (#4211)

teo9a8e3d618f96
diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml
index 630b439436..5f9b1658fb 100644
--- a/.github/workflows/deploy-preview.yml
+++ b/.github/workflows/deploy-preview.yml
@@ -41,7 +41,6 @@ jobs:
working-directory: js/app
run: just build-dev
env:
- VITE_DD_WEB_APP_ID: ${{ secrets.DD_WEB_APP_ID }}
VITE_DD_WEB_APP_TOKEN: ${{ secrets.DD_WEB_APP_TOKEN }}
VITE_DD_HASH: ${{ github.sha }}
VITE_SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_PRODUCTION }}
diff --git a/.github/workflows/deploy-web-app-dev-push.yml b/.github/workflows/deploy-web-app-dev-push.yml
index de00a3f4bd..078e3ca47f 100644
--- a/.github/workflows/deploy-web-app-dev-push.yml
+++ b/.github/workflows/deploy-web-app-dev-push.yml
@@ -34,7 +34,6 @@ jobs:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
DD_APP_KEY: ${{ secrets.DD_APP_KEY }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
- DD_WEB_APP_ID: ${{ secrets.DD_WEB_APP_ID }}
DD_WEB_APP_TOKEN: ${{ secrets.DD_WEB_APP_TOKEN }}
SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_PRODUCTION }}
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
diff --git a/.github/workflows/deploy-web-app.yml b/.github/workflows/deploy-web-app.yml
index aef0042210..e44a3a6c42 100644
--- a/.github/workflows/deploy-web-app.yml
+++ b/.github/workflows/deploy-web-app.yml
@@ -33,8 +33,6 @@ on:
required: true
DD_API_KEY:
required: true
- DD_WEB_APP_ID:
- required: true
DD_WEB_APP_TOKEN:
required: true
SEGMENT_WRITE_KEY:
@@ -69,7 +67,6 @@ jobs:
working-directory: js/app
run: just build-${{ inputs.environment }}
env:
- VITE_DD_WEB_APP_ID: ${{ secrets.DD_WEB_APP_ID }}
VITE_DD_WEB_APP_TOKEN: ${{ secrets.DD_WEB_APP_TOKEN }}
VITE_DD_HASH: ${{ github.sha }}
VITE_SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
diff --git a/.github/workflows/release-production.yml b/.github/workflows/release-production.yml
index 693b06a627..9dddbd9b4e 100644
--- a/.github/workflows/release-production.yml
+++ b/.github/workflows/release-production.yml
@@ -41,7 +41,6 @@ jobs:
working-directory: js/app
run: just build-prod
env:
- VITE_DD_WEB_APP_ID: ${{ secrets.DD_WEB_APP_ID }}
VITE_DD_WEB_APP_TOKEN: ${{ secrets.DD_WEB_APP_TOKEN }}
VITE_DD_HASH: ${{ github.sha }}
VITE_SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_PRODUCTION }}
diff --git a/js/analytics-proxy/src/index.ts b/js/analytics-proxy/src/index.ts
index 827ec80d4f..6fbc5c09ec 100644
--- a/js/analytics-proxy/src/index.ts
+++ b/js/analytics-proxy/src/index.ts
@@ -1,5 +1,8 @@
const PROVIDERS: Record<string, string> = {
'/i/ph': 'us.i.posthog.com',
+ // Datadog browser logs intake for the us5 site (site: us5.datadoghq.com).
+ // The observability SDK's `proxy` option targets the `/i/dd` prefix.
+ '/i/dd': 'browser-intake-us5-datadoghq.com',
};
function getProvider(pathname: string): { apiHost: string; path: string } | null {
diff --git a/js/app/packages/app/component/Root.tsx b/js/app/packages/app/component/Root.tsx
index a714ff2e33..6f1ca0803b 100644
--- a/js/app/packages/app/component/Root.tsx
+++ b/js/app/packages/app/component/Root.tsx
@@ -44,7 +44,10 @@ import {
usePlatformNotificationState,
} from '@notifications';
import { maybeHandlePlatformNotification } from '@notifications/notification-platform';
-import { useObserveRouting } from '@observability';
+import {
+ clearUser as clearDatadogUser,
+ setUser as setDatadogUser,
+} from '@observability';
import {
invalidateUserInfo,
prefetchUserInfo,
@@ -117,8 +120,6 @@ function useSyncLoginCookie() {
}
const rootPreload: RoutePreloadFunc = async (args) => {
- useObserveRouting();
-
await prefetchUserInfo();
prefetchHistory();
@@ -429,6 +430,17 @@ function UserInfoSideEffects() {
let identified = false;
createEffect(
on(userInfo, (user) => {
+ // Keep Datadog log user context in sync with auth state: set on every
+ // authenticated load (the logs SDK doesn't persist across reloads), and
+ // clear on logout so logs aren't attributed to a signed-out user. Logout
+ // flips userInfo client-side, and on native mobile it's an SPA navigation
+ // with no page reload, so this effect is what clears it there.
+ if (user?.authenticated) {
+ setDatadogUser({ id: user.id, email: user.email });
+ } else {
+ clearDatadogUser();
+ }
+
if (!user || !user.authenticated) return;
if (posthog.instance._isIdentified() || identified) {
diff --git a/js/app/packages/app/vite-env.d.ts b/js/app/packages/app/vite-env.d.ts
index 815845479e..b8e8f303cd 100644
--- a/js/app/packages/app/vite-env.d.ts
+++ b/js/app/packages/app/vite-env.d.ts
@@ -4,7 +4,6 @@ interface ImportMetaEnv {
readonly __GIT_BRANCH__: string;
readonly VITE_SEGMENT_WRITE_KEY: string;
- readonly VITE_DD_WEB_APP_ID: string;
readonly VITE_DD_WEB_APP_TOKEN: string;
readonly VITE_DD_HASH: string;
readonly VITE_POSTHOG_API_KEY: string;
diff --git a/js/app/packages/observability/package.json b/js/app/packages/observability/package.json
index 35f7d290d8..caa9b45841 100644
--- a/js/app/packages/observability/package.json
+++ b/js/app/packages/observability/package.json
@@ -6,7 +6,6 @@
"build": "tsc --noEmit -p ./"
},
"dependencies": {
- "@datadog/browser-logs": "^6.22.0",
- "@datadog/browser-rum": "^6.22.0"
+ "@datadog/browser-logs": "^6.22.0"
}
}
diff --git a/js/app/packages/observability/src/actionTracker.ts b/js/app/packages/observability/src/actionTracker.ts
deleted file mode 100644
index 9b99677a4b..0000000000
--- a/js/app/packages/observability/src/actionTracker.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import { datadogRum } from '@datadog/browser-rum';
-import { isInitialized } from './shared';
-
-export function startAction(name: string, context?: object) {
- if (!isInitialized()) return;
-
- datadogRum.addAction(name, context);
-}
diff --git a/js/app/packages/observability/src/index.ts b/js/app/packages/observability/src/index.ts
index bee094fe0a..f436c45d08 100644
--- a/js/app/packages/observability/src/index.ts
+++ b/js/app/packages/observability/src/index.ts
@@ -1,70 +1,32 @@
/// <reference types="../../app/vite-env.d.ts" />
-import { SERVER_HOSTS } from '@core/constant/servers';
import { datadogLogs } from '@datadog/browser-logs';
-import { datadogRum } from '@datadog/browser-rum';
import { isInitialized, setInitialized } from './shared';
-const applicationId = import.meta.env.VITE_DD_WEB_APP_ID;
const clientToken = import.meta.env.VITE_DD_WEB_APP_TOKEN;
const env = import.meta.env.MODE === 'production' ? 'prod' : 'dev';
const service = 'web-app';
const site = 'us5.datadoghq.com';
-const tracingHosts =
- env === 'prod'
- ? [
- SERVER_HOSTS['auth-service'],
- SERVER_HOSTS['cognition-service'],
- SERVER_HOSTS['document-storage-service'],
- SERVER_HOSTS['email-service'],
- SERVER_HOSTS['notification-service'],
- ]
- : Object.values(SERVER_HOSTS);
+// Route intake through the first-party analytics proxy (Cloudflare Worker) so
+// ad blockers / tracking protection don't drop logs the way they block
+// requests sent straight to *.datadoghq.com. The worker maps the `/i/dd`
+// prefix to the us5 browser intake origin; see js/analytics-proxy.
+const proxy = (options: { path: string; parameters: string }) =>
+ `https://macro-prox.macroverse.workers.dev/i/dd${options.path}?${options.parameters}`;
-export function init(version = import.meta.env.__APP_VERSION__) {
- if (import.meta.hot || isInitialized()) return;
+interface User {
+ id: string;
+ email: string;
+ [key: string]: any;
+}
- datadogRum.init({
- applicationId,
- clientToken,
- env,
- version,
- service,
- site,
- sessionSampleRate: 100,
- sessionReplaySampleRate: 0,
- allowFallbackToLocalStorage: true,
- trackUserInteractions: true,
- trackResources: true,
- trackLongTasks: true,
- actionNameAttribute: 'data-action-name',
- defaultPrivacyLevel: 'mask',
- excludedActivityUrls: [
- (url) => new URL(url).hostname.includes('analytics'),
- ],
- allowedTracingUrls: tracingHosts.map((host) => ({
- match: host,
- propagatorTypes: ['tracecontext'],
- })),
- trackViewsManually: true,
- beforeSend: (event, _context) => {
- if (event.type === 'resource' && event.status_code !== 200) {
- if (event.resource.url.includes('unfurl-service')) return false;
- }
+// init() is deferred to an idle callback, so setUser() can run before the SDK
+// is ready. Buffer the latest user and apply it once initialized.
+let pendingUser: User | undefined;
- // these are from VList and can be ignored: https://github.com/inokawa/virtua?tab=readme-ov-file#what-is-resizeobserver-loop-completed-with-undelivered-notifications-error
- if (
- event.type === 'error' &&
- event.error.message.includes(
- 'ResizeObserver loop completed with undelivered notifications'
- )
- )
- return false;
-
- return true;
- },
- });
+export function init(version = import.meta.env.__APP_VERSION__) {
+ if (import.meta.hot || isInitialized()) return;
datadogLogs.init({
clientToken,
@@ -72,6 +34,16 @@ export function init(version = import.meta.env.__APP_VERSION__) {
version,
service,
site,
+ proxy,
+ // Catch exceptions without RUM: forwards uncaught exceptions, unhandled
+ // promise rejections, and failed network requests (XHR/fetch) to Datadog
+ // as error-level logs (with stack traces).
+ forwardErrorsToLogs: true,
+ // Also forward explicit console.error() calls.
+ forwardConsoleLogs: ['error'],
+ // Forward browser Reporting API entries (CSP violations, deprecations,
+ // interventions).
+ forwardReports: 'all',
telemetrySampleRate: 0,
beforeSend: (event, _context) => {
if (event.message.includes('unfurl-service')) return false;
@@ -89,18 +61,20 @@ export function init(version = import.meta.env.__APP_VERSION__) {
});
setInitialized(true);
-}
-interface User {
- id: string;
- email: string;
- [key: string]: any;
+ if (pendingUser) datadogLogs.setUser(pendingUser);
}
+
export function setUser(user: User) {
- datadogRum.setUser(user);
- datadogLogs.setUser(user);
+ pendingUser = user;
+ if (isInitialized()) datadogLogs.setUser(user);
+}
+
+// Drop the user from log context on logout so logs aren't attributed to a
+// signed-out user. Mirrors the analytics.reset() in the logout flow.
+export function clearUser() {
+ pendingUser = undefined;
+ if (isInitialized()) datadogLogs.clearUser();
}
-export { startAction } from './actionTracker';
export { error, log, logger } from './logger';
-export { useObserveRouting } from './routingTracker';
diff --git a/js/app/packages/observability/src/routingTracker.ts b/js/app/packages/observability/src/routingTracker.ts
deleted file mode 100644
index fcf49e3d7b..0000000000
--- a/js/app/packages/observability/src/routingTracker.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-import { datadogRum } from '@datadog/browser-rum';
-import { useLocation } from '@solidjs/router';
-import { createEffect, createMemo, on } from 'solid-js';
-import { isInitialized } from './shared';
-
-export function useObserveRouting() {
- const location = useLocation();
- const pathSegments = createMemo(() =>
- location.pathname
- .split('/')
- .filter((segment) => !!segment && segment !== 'app')
- );
- const viewName = () =>
- pathSegments().at(0) === 'component'
- ? pathSegments().at(1)
- : pathSegments().at(0);
- createEffect(
- on(viewName, (name, prevName) => {
- if (!isInitialized() || !name) return;
-
- if (name !== prevName) {
- datadogRum.startView({
- name,
- context: {
- pathname: location.pathname,
- search: location.search,
- hash: location.hash,
- },
- });
- }
-
- return name;
- })
- );
-
- const joinedPath = createMemo(() => pathSegments().join('/'));
- createEffect((prevSplits) => {
- const splits = joinedPath();
-
- if (!isInitialized()) return;
- if (splits !== prevSplits) {
- datadogRum.addAction('split changed', {
- from: prevSplits,
- to: splits,
- });
- }
-
- return splits;
- });
-}