Skip to content

Commit

Permalink
fixup! Bruk faro til frontend observability
Browse files Browse the repository at this point in the history
  • Loading branch information
LudvigHz committed May 27, 2024
1 parent a6314fe commit ded784f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 deletions.
13 changes: 7 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
<script src="%VITE_HODE_URL_V2%/latest/dist/bundle.js"></script>
<link rel="stylesheet" href="%VITE_HODE_URL_V2%/latest/dist/index.css" />

<script type="application/javascript">
const global = globalThis;
</script>

<script type="module" src="/src/index.tsx"></script>

<script unleash toggles="modiapersonoversikt.decorator-v3,modiapersonoversikt.enable-faro">
const applicationFeatureToggles = {
useNewDecorator: "$unleash{modiapersonoversikt.decorator-v3}"
enableFaro: "$unleash{modiapersonoversikt.enable-faro}"
};
window.applicationFeatureToggles = applicationFeatureToggles;
</script>

<script type="application/javascript">
const global = globalThis;
</script>

<script type="module" src="/src/index.tsx"></script>

<title>Modia Personoversikt</title>
</head>
<body>
Expand Down
5 changes: 2 additions & 3 deletions src/app/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import { LandingPage } from './internarbeidsflatedecorator/LandingPage';
import { createBrowserHistory } from 'history';
import { ConnectedRouter, routerMiddleware } from 'connected-react-router';
import { initializeObservability } from '../utils/observability';
import { FaroRoute } from '@grafana/faro-react';

const AppStyle = styled.div`
height: 100vh;
Expand Down Expand Up @@ -145,12 +144,12 @@ function AppContainer() {
<SentryRoute path={paths.landingPage}>
<LandingPage />
</SentryRoute>
<FaroRoute>
<SentryRoute>
<AppStyle>
{!window.erChatvisning && <Decorator />}
<App />
</AppStyle>
</FaroRoute>
</SentryRoute>
</Switch>
</ConnectedRouter>
</Provider>
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ setupTimeSpentMetrics();

if (import.meta.env.DEV) {
window.applicationFeatureToggles = {
useNewDecorator: true
useNewDecorator: true,
enableFaro: true
};
}

Expand Down
4 changes: 0 additions & 4 deletions src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,3 @@ setupStandardteksterMock(mock);
setUpSaksbehandlersEnheterMock(mock);
setupSaksbehandlerInnstillingerMock(mock);
setupDraftMock(mock);

window.applicationFeatureToggles = {
useNewDecorator: true
};
3 changes: 0 additions & 3 deletions src/sentry-route.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/sentry-route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { ComponentProps } from 'react';
import { FaroRoute } from '@grafana/faro-react';
import { Route } from 'react-router-dom';

export const SentryRoute = ({ children, ...props }: ComponentProps<typeof FaroRoute>) => {
if (window.faro) {
return <FaroRoute {...props}>{children}</FaroRoute>;
}
return <Route {...props}>{children}</Route>;
};
19 changes: 15 additions & 4 deletions src/utils/observability.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import { getWebInstrumentations, initializeFaro, ReactIntegration, ReactRouterVersion } from '@grafana/faro-react';
import {
getWebInstrumentations,
initializeFaro,
InternalLoggerLevel,
ReactIntegration,
ReactRouterVersion
} from '@grafana/faro-react';
import { History } from 'history';
import { Route } from 'react-router-dom';
import { getEnvFromHost } from './environment';
import { getWindowFeature } from './featureToggles';

export const initializeObservability = (history: History) => {
if (!getWindowFeature('enableFaro')) return;
if (!getWindowFeature('enableFaro') && !import.meta.env.VITE_GRAFANA_COLLECTOR) return;

const env = getEnvFromHost();
if (!['q2'].includes(env)) {
if (!['q2'].includes(env) && !import.meta.env.VITE_GRAFANA_COLLECTOR) {
console.info('Not running in GCP, web observability disabled');
}

console.log(import.meta.env.VITE_GRAFANA_COLLECTOR);
initializeFaro({
url: env === 'prod' ? 'https://telemetry.nav.no/collect' : 'https://telemetry.ekstern.dev.nav.no/collect',
url:
import.meta.env.VITE_GRAFANA_COLLECTOR ??
(env === 'prod' ? 'https://telemetry.nav.no/collect' : 'https://telemetry.ekstern.dev.nav.no/collect'),
app: {
name: 'modiapersonoversikt'
},
internalLoggerLevel: InternalLoggerLevel.VERBOSE,
instrumentations: [
...getWebInstrumentations(),
new ReactIntegration({
Expand Down
4 changes: 4 additions & 0 deletions src/window-variabler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Faro } from "@grafana/faro-web-sdk";

declare global {
interface Window {
erChatvisning: boolean;
applicationFeatureToggles: {
useNewDecorator: string | boolean;
enableFaro: string | boolean;
};
faro?: Faro
}
}

Expand Down

0 comments on commit ded784f

Please sign in to comment.