Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat(boot-settings): runtime enable/disable control for PostHog and Appcues (#11416)

SagarRajput-7bd55e70882f2
diff --git a/frontend/index.html b/frontend/index.html
index 0f328a7e18..250dd770c2 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -94,6 +94,19 @@
}
})();
</script>
+ <script type="application/json" id="signoz-boot-settings">
+ [[.Settings]]
+ </script>
+ <script>
+ try {
+ var _el = document.getElementById('signoz-boot-settings');
+ window.signozBootData = {
+ settings: _el ? JSON.parse(_el.textContent) : null,
+ };
+ } catch (e) {
+ window.signozBootData = { settings: null };
+ }
+ </script>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
@@ -135,7 +148,10 @@
</script>
<script>
var APPCUES_APP_ID = '<%- APPCUES_APP_ID %>';
- if (APPCUES_APP_ID) {
+ var appcuesSettings =
+ ((window.signozBootData || {}).settings || {}).appcues || {};
+ var appcuesEnabled = appcuesSettings.enabled !== false;
+ if (APPCUES_APP_ID && appcuesEnabled) {
(function (d, t) {
var a = d.createElement(t);
a.async = 1;
diff --git a/frontend/src/AppRoutes/index.tsx b/frontend/src/AppRoutes/index.tsx
index 83b9b5b846..b548006d92 100644
--- a/frontend/src/AppRoutes/index.tsx
+++ b/frontend/src/AppRoutes/index.tsx
@@ -35,6 +35,7 @@ import { PreferenceContextProvider } from 'providers/preferences/context/Prefere
import { QueryBuilderProvider } from 'providers/QueryBuilder';
import { LicenseStatus } from 'types/api/licensesV3/getActive';
import { extractDomain } from 'utils/app';
+import { bootSettings } from 'utils/bootData';
import { Home } from './pageComponents';
import PrivateRoute from './Private';
@@ -332,7 +333,7 @@ function App(): JSX.Element {
useEffect(() => {
if (isCloudUser || isEnterpriseSelfHostedUser) {
- if (process.env.POSTHOG_KEY) {
+ if (bootSettings.posthog.enabled && process.env.POSTHOG_KEY) {
posthog.init(process.env.POSTHOG_KEY, {
api_host: 'https://us.i.posthog.com',
person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well
diff --git a/frontend/src/typings/window.ts b/frontend/src/typings/window.ts
index e53991fa86..747fe96e9a 100644
--- a/frontend/src/typings/window.ts
+++ b/frontend/src/typings/window.ts
@@ -1,5 +1,6 @@
// eslint-disable-next-line no-restricted-imports
import { compose, Store } from 'redux';
+import type { WebSettings } from 'types/generated/webSettings';
declare global {
interface Window {
@@ -7,6 +8,7 @@ declare global {
pylon: any;
Appcues: Record<string, any>;
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: typeof compose;
+ signozBootData?: { settings: WebSettings | null };
}
}
diff --git a/frontend/src/utils/__tests__/bootData.test.ts b/frontend/src/utils/__tests__/bootData.test.ts
new file mode 100644
index 0000000000..e9b6b47346
--- /dev/null
+++ b/frontend/src/utils/__tests__/bootData.test.ts
@@ -0,0 +1,74 @@
+export {};
+
+type BootData = typeof import('../bootData');
+
+function loadModule(settings?: object | null): BootData {
+ (window as any).signozBootData =
+ settings !== undefined ? { settings } : undefined;
+ let mod!: BootData;
+ jest.isolateModules(() => {
+ // oxlint-disable-next-line typescript-eslint/no-require-imports, typescript-eslint/no-var-requires
+ mod = require('../bootData');
+ });
+ return mod;
+}
+
+afterEach(() => {
+ delete (window as any).signozBootData;
+});
+
+describe('when window.signozBootData is absent', () => {
+ it('defaults posthog and appcues to enabled', () => {
+ const { bootSettings } = loadModule();
+ expect(bootSettings.posthog.enabled).toBe(true);
+ expect(bootSettings.appcues.enabled).toBe(true);
+ });
+});
+
+describe('when window.signozBootData.settings is null (injection failed)', () => {
+ it('defaults posthog and appcues to enabled', () => {
+ const { bootSettings } = loadModule(null);
+ expect(bootSettings.posthog.enabled).toBe(true);
+ expect(bootSettings.appcues.enabled).toBe(true);
+ });
+});
+
+describe('when window.signozBootData.settings is populated', () => {
+ it('reads posthog enabled: true', () => {
+ const { bootSettings } = loadModule({ posthog: { enabled: true } });
+ expect(bootSettings.posthog.enabled).toBe(true);
+ });
+
+ it('reads posthog enabled: false', () => {
+ const { bootSettings } = loadModule({ posthog: { enabled: false } });
+ expect(bootSettings.posthog.enabled).toBe(false);
+ });
+
+ it('reads appcues enabled: true', () => {
+ const { bootSettings } = loadModule({ appcues: { enabled: true } });
+ expect(bootSettings.appcues.enabled).toBe(true);
+ });
+
+ it('reads appcues enabled: false', () => {
+ const { bootSettings } = loadModule({ appcues: { enabled: false } });
+ expect(bootSettings.appcues.enabled).toBe(false);
+ });
+
+ it('missing sub-namespace defaults to enabled', () => {
+ const { bootSettings } = loadModule({ posthog: { enabled: false } });
+ expect(bootSettings.appcues.enabled).toBe(true);
+ });
+});
+
+describe('when window.signozBootData exists but settings is undefined', () => {
+ it('defaults posthog and appcues to enabled', () => {
+ (window as any).signozBootData = {};
+ let mod!: BootData;
+ jest.isolateModules(() => {
+ // oxlint-disable-next-line typescript-eslint/no-require-imports, typescript-eslint/no-var-requires
+ mod = require('../bootData');
+ });
+ expect(mod.bootSettings.posthog.enabled).toBe(true);
+ expect(mod.bootSettings.appcues.enabled).toBe(true);
+ });
+});
diff --git a/frontend/src/utils/bootData.ts b/frontend/src/utils/bootData.ts
new file mode 100644
index 0000000000..eaef1320b6
--- /dev/null
+++ b/frontend/src/utils/bootData.ts
@@ -0,0 +1,11 @@
+import type { WebSettings } from 'types/generated/webSettings';
+
+const raw = window.signozBootData?.settings as
+ | Partial<WebSettings>
+ | null
+ | undefined;
+
+export const bootSettings: Readonly<WebSettings> = {
+ posthog: { enabled: raw?.posthog?.enabled ?? true },
+ appcues: { enabled: raw?.appcues?.enabled ?? true },
+};
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index c936389a1c..63cac64ba2 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -23,6 +23,20 @@ function devBasePathPlugin(basePath: string): Plugin {
};
}
+function devBootDataPlugin(env: Record<string, string>): Plugin {
+ return {
+ name: 'dev-boot-data',
+ apply: 'serve',
+ transformIndexHtml(html): string {
+ const settings = {
+ posthog: { enabled: env.VITE_POSTHOG_ENABLED !== 'false' },
+ appcues: { enabled: env.VITE_APPCUES_ENABLED !== 'false' },
+ };
+ return html.replaceAll('[[.Settings]]', JSON.stringify(settings));
+ },
+ };
+}
+
function rawMarkdownPlugin(): Plugin {
return {
name: 'raw-markdown',
@@ -47,6 +61,7 @@ export default defineConfig(({ mode }): UserConfig => {
tsconfigPaths(),
rawMarkdownPlugin(),
devBasePathPlugin(basePath),
+ devBootDataPlugin(env),
react(),
createHtmlPlugin({
inject: {