Skip to content

Commit 679b65d

Browse files
authored
feat: allow disabling otel exporter (#1436)
1 parent 30f4dfd commit 679b65d

5 files changed

Lines changed: 22 additions & 15 deletions

File tree

‎.changeset/angry-emus-cry.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@hyperdx/app": patch
3+
"@hyperdx/api": patch
4+
---
5+
6+
feat: added configuration to disable frontend otel exporter

‎packages/app/pages/_app.tsx‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ import {
2626
import { ibmPlexMono, inter, roboto, robotoMono } from '@/fonts';
2727
import { AppThemeProvider, useAppTheme } from '@/theme/ThemeProvider';
2828
import { ThemeWrapper } from '@/ThemeWrapper';
29+
import { NextApiConfigResponseData } from '@/types';
2930
import { useConfirmModal } from '@/useConfirm';
3031
import { QueryParamProvider as HDXQueryParamProvider } from '@/useQueryParam';
3132
import { useUserPreferences } from '@/useUserPreferences';
3233

3334
import '@mantine/core/styles.css';
34-
import '@mantine/notifications/styles.css';
3535
import '@mantine/dates/styles.css';
3636
import '@mantine/dropzone/styles.css';
37-
import '@styles/globals.css';
37+
import '@mantine/notifications/styles.css';
3838
import '@styles/app.scss';
39-
import 'uplot/dist/uPlot.min.css';
39+
import '@styles/globals.css';
4040
import '@xyflow/react/dist/style.css';
41+
import 'uplot/dist/uPlot.min.css';
4142

4243
// Polyfill crypto.randomUUID for non-HTTPS environments
4344
if (typeof crypto !== 'undefined' && !crypto.randomUUID) {
@@ -137,15 +138,8 @@ export default function MyApp({ Component, pageProps }: AppPropsWithLayout) {
137138
}
138139
fetch('/api/config')
139140
.then(res => res.json())
140-
.then(_jsonData => {
141+
.then((_jsonData?: NextApiConfigResponseData) => {
141142
if (_jsonData?.apiKey) {
142-
let hostname;
143-
try {
144-
const url = new URL(_jsonData.apiServerUrl);
145-
hostname = url.hostname;
146-
} catch (err) {
147-
// ignore
148-
}
149143
HyperDX.init({
150144
apiKey: _jsonData.apiKey,
151145
consoleCapture: true,
@@ -156,7 +150,7 @@ export default function MyApp({ Component, pageProps }: AppPropsWithLayout) {
156150
url: _jsonData.collectorUrl,
157151
});
158152
} else {
159-
console.warn('No API key found');
153+
console.warn('No API key found to enable OTEL exporter');
160154
}
161155
})
162156
.catch(err => {

‎packages/app/pages/api/config.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import type { NextApiRequest, NextApiResponse } from 'next';
22

3-
import { HDX_API_KEY, HDX_COLLECTOR_URL, HDX_SERVICE_NAME } from '@/config';
3+
import {
4+
HDX_API_KEY,
5+
HDX_COLLECTOR_URL,
6+
HDX_EXPORTER_ENABLED,
7+
HDX_SERVICE_NAME,
8+
} from '@/config';
49
import type { NextApiConfigResponseData } from '@/types';
510

611
export default function handler(
712
req: NextApiRequest,
813
res: NextApiResponse<NextApiConfigResponseData>,
914
) {
1015
res.status(200).json({
11-
apiKey: HDX_API_KEY,
16+
apiKey: HDX_EXPORTER_ENABLED ? HDX_API_KEY : undefined,
1217
collectorUrl: HDX_COLLECTOR_URL,
1318
serviceName: HDX_SERVICE_NAME,
1419
});

‎packages/app/src/config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const NODE_ENV = process.env.NODE_ENV as string;
1616
export const HDX_API_KEY = process.env.HYPERDX_API_KEY as string; // for nextjs server
1717
export const HDX_SERVICE_NAME =
1818
process.env.NEXT_PUBLIC_OTEL_SERVICE_NAME ?? 'hdx-oss-dev-app';
19+
export const HDX_EXPORTER_ENABLED =
20+
(process.env.HDX_EXPORTER_ENABLED ?? 'true') === 'true';
1921
export const HDX_COLLECTOR_URL =
2022
process.env.NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT ??
2123
'http://localhost:4318';

‎packages/app/src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export enum KubePhase {
238238
}
239239

240240
export type NextApiConfigResponseData = {
241-
apiKey: string;
241+
apiKey?: string;
242242
collectorUrl: string;
243243
serviceName: string;
244244
};

0 commit comments

Comments
 (0)