diff --git a/.changeset/angry-emus-cry.md b/.changeset/angry-emus-cry.md new file mode 100644 index 000000000..36a739612 --- /dev/null +++ b/.changeset/angry-emus-cry.md @@ -0,0 +1,6 @@ +--- +"@hyperdx/app": patch +"@hyperdx/api": patch +--- + +feat: added configuration to disable frontend otel exporter diff --git a/packages/app/Dockerfile b/packages/app/Dockerfile index 4c7525d2a..9e782e341 100644 --- a/packages/app/Dockerfile +++ b/packages/app/Dockerfile @@ -26,9 +26,11 @@ FROM base AS builder # Expose custom env variables to the browser (needs NEXT_PUBLIC_ prefix) # doc: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser ARG OTEL_EXPORTER_OTLP_ENDPOINT +ARG OTEL_EXPORTER_ENABLED ARG OTEL_SERVICE_NAME ARG IS_LOCAL_MODE ENV NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT $OTEL_EXPORTER_OTLP_ENDPOINT +ENV NEXT_PUBLIC_OTEL_EXPORTER_ENABLED $OTEL_EXPORTER_ENABLED ENV NEXT_PUBLIC_OTEL_SERVICE_NAME $OTEL_SERVICE_NAME ENV NEXT_PUBLIC_IS_LOCAL_MODE $IS_LOCAL_MODE ENV NX_DAEMON false diff --git a/packages/app/pages/_app.tsx b/packages/app/pages/_app.tsx index e8da0f974..2de312d1d 100644 --- a/packages/app/pages/_app.tsx +++ b/packages/app/pages/_app.tsx @@ -21,6 +21,7 @@ import { ThemeWrapper } from '@/ThemeWrapper'; import { useConfirmModal } from '@/useConfirm'; import { QueryParamProvider as HDXQueryParamProvider } from '@/useQueryParam'; import { useBackground, useUserPreferences } from '@/useUserPreferences'; +import { NextApiConfigResponseData } from '@/types'; import '@mantine/core/styles.css'; import '@mantine/notifications/styles.css'; @@ -68,26 +69,20 @@ export default function MyApp({ Component, pageProps }: AppPropsWithLayout) { } fetch('/api/config') .then(res => res.json()) - .then(_jsonData => { - if (_jsonData?.apiKey) { - let hostname; - try { - const url = new URL(_jsonData.apiServerUrl); - hostname = url.hostname; - } catch (err) { - // ignore - } + .then((_jsonData?: NextApiConfigResponseData) => { + if (!_jsonData?.exporterEnabled){ + console.info('OTEL exporter disabled'); + } else if (_jsonData?.apiKey) { HyperDX.init({ apiKey: _jsonData.apiKey, consoleCapture: true, maskAllInputs: true, maskAllText: true, service: _jsonData.serviceName, - // tracePropagationTargets: [new RegExp(hostname ?? 'localhost', 'i')], url: _jsonData.collectorUrl, }); } else { - console.warn('No API key found'); + console.warn('No API key found to enable OTEL exporter'); } }) .catch(err => { diff --git a/packages/app/pages/api/config.ts b/packages/app/pages/api/config.ts index c2641d685..82d8d1a1f 100644 --- a/packages/app/pages/api/config.ts +++ b/packages/app/pages/api/config.ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from 'next'; -import { HDX_API_KEY, HDX_COLLECTOR_URL, HDX_SERVICE_NAME } from '@/config'; +import { HDX_API_KEY, HDX_EXPORTER_ENABLED, HDX_COLLECTOR_URL, HDX_SERVICE_NAME } from '@/config'; import type { NextApiConfigResponseData } from '@/types'; export default function handler( @@ -8,6 +8,7 @@ export default function handler( res: NextApiResponse, ) { res.status(200).json({ + exporterEnabled: HDX_EXPORTER_ENABLED, apiKey: HDX_API_KEY, collectorUrl: HDX_COLLECTOR_URL, serviceName: HDX_SERVICE_NAME, diff --git a/packages/app/src/config.ts b/packages/app/src/config.ts index 47cb480f9..466b42e1a 100644 --- a/packages/app/src/config.ts +++ b/packages/app/src/config.ts @@ -16,6 +16,8 @@ export const NODE_ENV = process.env.NODE_ENV as string; export const HDX_API_KEY = process.env.HYPERDX_API_KEY as string; // for nextjs server export const HDX_SERVICE_NAME = process.env.NEXT_PUBLIC_OTEL_SERVICE_NAME ?? 'hdx-oss-dev-app'; +export const HDX_EXPORTER_ENABLED = + (process.env.NEXT_PUBLIC_OTEL_EXPORTER_ENABLED ?? 'true') === 'true'; export const HDX_COLLECTOR_URL = process.env.NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT ?? 'http://localhost:4318'; diff --git a/packages/app/src/types.ts b/packages/app/src/types.ts index 85222d146..ea84d378c 100644 --- a/packages/app/src/types.ts +++ b/packages/app/src/types.ts @@ -264,6 +264,7 @@ export type Webhook = { }; export type NextApiConfigResponseData = { + exporterEnabled: boolean; apiKey: string; collectorUrl: string; serviceName: string;