Skip to content

Commit b8cf975

Browse files
committed
feat: allow disabling otel exporter
1 parent b7789ce commit b8cf975

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

packages/app/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ FROM base AS builder
2626
# Expose custom env variables to the browser (needs NEXT_PUBLIC_ prefix)
2727
# doc: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser
2828
ARG OTEL_EXPORTER_OTLP_ENDPOINT
29+
ARG OTEL_EXPORTER_ENABLED
2930
ARG OTEL_SERVICE_NAME
3031
ARG IS_LOCAL_MODE
3132
ENV NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT $OTEL_EXPORTER_OTLP_ENDPOINT
33+
ENV NEXT_PUBLIC_OTEL_EXPORTER_ENABLED $OTEL_EXPORTER_ENABLED
3234
ENV NEXT_PUBLIC_OTEL_SERVICE_NAME $OTEL_SERVICE_NAME
3335
ENV NEXT_PUBLIC_IS_LOCAL_MODE $IS_LOCAL_MODE
3436
ENV NX_DAEMON false

packages/app/pages/_app.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ThemeWrapper } from '@/ThemeWrapper';
2121
import { useConfirmModal } from '@/useConfirm';
2222
import { QueryParamProvider as HDXQueryParamProvider } from '@/useQueryParam';
2323
import { useBackground, useUserPreferences } from '@/useUserPreferences';
24+
import { NextApiConfigResponseData } from '@/types';
2425

2526
import '@mantine/core/styles.css';
2627
import '@mantine/notifications/styles.css';
@@ -68,26 +69,20 @@ export default function MyApp({ Component, pageProps }: AppPropsWithLayout) {
6869
}
6970
fetch('/api/config')
7071
.then(res => res.json())
71-
.then(_jsonData => {
72-
if (_jsonData?.apiKey) {
73-
let hostname;
74-
try {
75-
const url = new URL(_jsonData.apiServerUrl);
76-
hostname = url.hostname;
77-
} catch (err) {
78-
// ignore
79-
}
72+
.then((_jsonData?: NextApiConfigResponseData) => {
73+
if (!_jsonData?.exporterEnabled){
74+
console.info('OTEL exporter disabled');
75+
} else if (_jsonData?.apiKey) {
8076
HyperDX.init({
8177
apiKey: _jsonData.apiKey,
8278
consoleCapture: true,
8379
maskAllInputs: true,
8480
maskAllText: true,
8581
service: _jsonData.serviceName,
86-
// tracePropagationTargets: [new RegExp(hostname ?? 'localhost', 'i')],
8782
url: _jsonData.collectorUrl,
8883
});
8984
} else {
90-
console.warn('No API key found');
85+
console.warn('No API key found to enable OTEL exporter');
9186
}
9287
})
9388
.catch(err => {

packages/app/pages/api/config.ts

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

3-
import { HDX_API_KEY, HDX_COLLECTOR_URL, HDX_SERVICE_NAME } from '@/config';
3+
import { HDX_API_KEY, HDX_EXPORTER_ENABLED, HDX_COLLECTOR_URL, HDX_SERVICE_NAME } from '@/config';
44
import type { NextApiConfigResponseData } from '@/types';
55

66
export default function handler(
77
req: NextApiRequest,
88
res: NextApiResponse<NextApiConfigResponseData>,
99
) {
1010
res.status(200).json({
11+
exporterEnabled: HDX_EXPORTER_ENABLED,
1112
apiKey: HDX_API_KEY,
1213
collectorUrl: HDX_COLLECTOR_URL,
1314
serviceName: HDX_SERVICE_NAME,

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.NEXT_PUBLIC_OTEL_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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export type Webhook = {
264264
};
265265

266266
export type NextApiConfigResponseData = {
267+
exporterEnabled: boolean;
267268
apiKey: string;
268269
collectorUrl: string;
269270
serviceName: string;

0 commit comments

Comments
 (0)