Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion frontend/src/analyticsSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,32 @@

import { ReactPlugin } from '@microsoft/applicationinsights-react-js';
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
import { privacyTelemetryInitializer } from './lib/analyticsPrivacy';

if (import.meta.env.REACT_APP_APPINSIGHTS_CONNECTION_STRING) {
const reactPlugin = new ReactPlugin();
window.appInsights = new ApplicationInsights({
config: {
connectionString: import.meta.env.REACT_APP_APPINSIGHTS_CONNECTION_STRING,
extensions: [reactPlugin],

// Don't auto-collect anything that carries identifiers.
disableAjaxTracking: true, // K8s API URLs contain ns/resource names
disableFetchTracking: true, // Azure ARM URLs likewise
disableExceptionTracking: true, // we route exceptions ourselves, scrubbed
enableAutoRouteTracking: false, // don't auto-fire pageviews on URL change
autoTrackPageVisitTime: false,

// Drop user/session correlation.
disableCookiesUsage: true,
isStorageUseDisabled: true,
},
});
// Register the privacy scrubber BEFORE loadAppInsights() so any envelope
// the SDK emits or queues during initialization passes through it.
window.appInsights.addTelemetryInitializer(privacyTelemetryInitializer);
window.appInsights.loadAppInsights();
window.appInsights.trackPageView();
// trackPageView() intentionally not called — the page URL contains
Comment thread
gambtho marked this conversation as resolved.
// cluster/namespace/resource names. LIST_VIEW / DETAILS_VIEW events from
// the redux middleware give us per-resource-kind visibility without URLs.
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-1ml9dpn-MuiTable-root"
class="MuiTable-root css-1ok7ihs-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-1ml9dpn-MuiTable-root"
class="MuiTable-root css-1ok7ihs-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-1ml9dpn-MuiTable-root"
class="MuiTable-root css-1ok7ihs-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-1ml9dpn-MuiTable-root"
class="MuiTable-root css-1ok7ihs-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-1ml9dpn-MuiTable-root"
class="MuiTable-root css-1ok7ihs-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2025 The Kubernetes Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import * as analytics from '../../../lib/analytics';
import store from '../../../redux/stores/store';
import ErrorBoundary from './ErrorBoundary';

class CustomDomainError extends Error {
constructor(message: string) {
super(message);
this.name = 'CustomDomainError';
}
}

function Boom({ error }: { error: Error }): JSX.Element {
throw error;
}

describe('ErrorBoundary telemetry', () => {
let trackEventSpy: ReturnType<typeof vi.spyOn>;
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;

beforeEach(() => {
trackEventSpy = vi.spyOn(analytics, 'trackEvent').mockImplementation(() => {});
// React logs caught errors via console.error in dev — silence to keep test output clean.
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(() => {
trackEventSpy.mockRestore();
consoleErrorSpy.mockRestore();
});

it('calls trackEvent with exception name and only error.name in properties', () => {
const err = new CustomDomainError(
"namespace 'payments' not found at https://example.test/api/v1/namespaces/payments"
);

render(
<Provider store={store}>
<ErrorBoundary fallback={<div>fallback</div>}>
<Boom error={err} />
</ErrorBoundary>
</Provider>
);

expect(trackEventSpy).toHaveBeenCalledWith('exception', { errorName: 'CustomDomainError' });

// No call shipped the message or stack.
for (const call of trackEventSpy.mock.calls) {
const [, properties] = call;
if (properties) {
for (const value of Object.values(properties)) {
expect(value).not.toContain('payments');
expect(value).not.toContain('https://');
}
}
}
});

it('uses the default Error.name "Error" for plain errors', () => {
render(
<Provider store={store}>
<ErrorBoundary fallback={<div>fallback</div>}>
<Boom error={new Error('boom')} />
</ErrorBoundary>
</Provider>
);

expect(trackEventSpy).toHaveBeenCalledWith('exception', { errorName: 'Error' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Component, ComponentType, isValidElement, ReactElement, ReactNode } from 'react';
import { trackException } from '../../../lib/analytics';
import { trackEvent } from '../../../lib/analytics';
import { eventAction, HeadlampEventType } from '../../../redux/headlampEventSlice';
import store from '../../../redux/stores/store';

Expand Down Expand Up @@ -60,7 +60,10 @@ export default class ErrorBoundary extends Component<ErrorBoundaryProps, State>
}

componentDidCatch(error: Error) {
trackException(error);
// Send only the constructor name (e.g. "TypeError", "KubeApiError"),
// never the message or stack — error messages routinely contain
// identifiers (namespaces, resource names, URLs, YAML fragments).
trackEvent('exception', { errorName: error.name });
}

componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: State) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-1ml9dpn-MuiTable-root"
class="MuiTable-root css-1ok7ihs-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<tbody
class="MuiTableBody-root css-apqrd9-MuiTableBody-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-r7i92b-MuiTable-root"
class="MuiTable-root css-1f5u0uu-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-r7i92b-MuiTable-root"
class="MuiTable-root css-1f5u0uu-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-bv8t57-MuiTable-root"
class="MuiTable-root css-14jq1ex-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-bv8t57-MuiTable-root"
class="MuiTable-root css-14jq1ex-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-bv8t57-MuiTable-root"
class="MuiTable-root css-14jq1ex-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-qzmaqi-MuiTable-root"
class="MuiTable-root css-fekg5f-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down Expand Up @@ -379,7 +379,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-bv8t57-MuiTable-root"
class="MuiTable-root css-14jq1ex-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-bv8t57-MuiTable-root"
class="MuiTable-root css-14jq1ex-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-bv8t57-MuiTable-root"
class="MuiTable-root css-14jq1ex-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down Expand Up @@ -362,7 +362,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-bv8t57-MuiTable-root"
class="MuiTable-root css-14jq1ex-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
tabindex="0"
>
<table
class="MuiTable-root css-1t02l4h-MuiTable-root"
class="MuiTable-root css-15jmevm-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
Expand Down
Loading
Loading