Skip to content

Commit

Permalink
Boyscout some types, change condition, add trackEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
timvanoostrom committed Feb 3, 2025
1 parent a76c8f2 commit 4df5516
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
24 changes: 16 additions & 8 deletions src/client/helpers/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const severityMap: Record<Severity, string> = {
};

export type Properties = {
properties?: Record<string, any>;
properties?: Record<string, unknown>;
severity?: Severity;
};

Expand Down Expand Up @@ -58,9 +58,13 @@ export function captureException(error: unknown, properties?: Properties) {
properties,
};

IS_DEVELOPMENT
? MA_APP_MODE !== 'unittest' && console.log('Capture exception', payload)
: appInsights.trackException(payload);
if (IS_DEVELOPMENT) {
if (MA_APP_MODE !== 'unittest') {
console.log('Capture exception', payload);
}
} else {
appInsights.trackException(payload);
}
}

export function captureMessage(message: string, properties?: Properties) {
Expand All @@ -70,12 +74,16 @@ export function captureMessage(message: string, properties?: Properties) {

const payload = { message, severity, properties };

IS_DEVELOPMENT
? MA_APP_MODE !== 'unittest' && console.log('Capture message', payload)
: appInsights.trackTrace(payload);
if (IS_DEVELOPMENT) {
if (MA_APP_MODE !== 'unittest') {
console.log('Capture message', payload);
}
} else {
appInsights.trackTrace(payload);
}
}

export function trackEvent(name: string, properties: Record<string, any>) {
export function trackEvent(name: string, properties: Record<string, unknown>) {
return IS_DEVELOPMENT
? MA_APP_MODE !== 'unittest' && console.log('Track event', name, properties)
: appInsights.trackEvent({
Expand Down
10 changes: 3 additions & 7 deletions src/client/hooks/useTrackThemas.hook.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useEffect } from 'react';

import { useSessionStorage } from './storage.hook';
import { useAppStateGetter } from './useAppState';
import { useThemaMenuItems } from './useThemaMenuItems';
import { ThemaMenuItemTransformed } from '../config/thema';
import { trackEvent } from '../helpers/monitoring';

type ThemaTitleAndId = Record<'title' | 'id', string>;
type ThemaTitleAndId = Pick<ThemaMenuItemTransformed, 'title' | 'id'>;

export function useTrackThemas() {
const appState = useAppStateGetter();
const [storedThemas, setStoredThemas] = useSessionStorage('themas', null);

const themasState = useThemaMenuItems();
Expand All @@ -17,10 +16,7 @@ export function useTrackThemas() {
if (!storedThemas && !themasState.isLoading) {
const themaTitlesAndIds: ThemaTitleAndId[] = themasState.items.map(
(item) => ({
title:
typeof item.title === 'function'
? item.title(appState)
: item.title,
title: item.title,
id: item.id,
})
);
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/afis/afis-facturen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { encryptSessionIdWithRouteIdParam } from '../../helpers/encrypt-decrypt'
import { requestData } from '../../helpers/source-api-request';
import { BffEndpoints } from '../../routing/bff-routes';
import { generateFullApiUrlBFF } from '../../routing/route-helpers';
import { captureMessage } from '../monitoring';
import { captureMessage, trackEvent } from '../monitoring';
import { getAfisApiConfig, getFeedEntryProperties } from './afis-helpers';
import {
AccountingDocumentType,
Expand Down Expand Up @@ -548,7 +548,7 @@ export async function fetchAfisFacturenOverview(

if (Object.keys(countByState).length > 0) {
// Log the count of facturen per state in Application Insights
captureMessage(`AFIS Facturen per categorie`, countByState);
trackEvent('afis-facturen-per-categorie', countByState);
}

return apiSuccessResult(facturenOverview, failedDependencies);
Expand Down
9 changes: 9 additions & 0 deletions src/server/services/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ export function captureMessage(message: string, properties?: Properties) {
}
}

export function trackEvent(name: string, properties: Record<string, unknown>) {
return IS_DEVELOPMENT
? MA_APP_MODE !== 'unittest' && console.log('Track event', name, properties)
: client?.trackEvent({
name,
properties,
});
}

interface TrackRequestProps {
name: string;
url: string;
Expand Down

0 comments on commit 4df5516

Please sign in to comment.