From eafe101cc94cefcec2cd628f30e4deb5fa5e8731 Mon Sep 17 00:00:00 2001 From: tidnav <90849097+tidnav@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:34:45 +0100 Subject: [PATCH] :loud_sound: Bruk nye loggmetoder (#141) --- auth/beskyttetApi.ts | 14 ++-- auth/beskyttetSide.ts | 10 +-- lib/utils/TokenxProxy.ts | 8 +-- package.json | 8 +-- pages/[step].tsx | 18 +++--- pages/api/buckets/lagre.ts | 5 +- pages/api/buckets/les.ts | 5 +- pages/api/buckets/slett.ts | 3 +- pages/api/innsending/soknadapi.ts | 3 +- pages/api/innsending/soknadinnsending.ts | 5 +- pages/api/mellomlagring/lagre.ts | 5 +- pages/api/mellomlagring/les.ts | 5 +- pages/api/mellomlagring/slett.ts | 3 +- pages/api/oppslag/barn.ts | 5 +- pages/api/oppslag/krr.ts | 5 +- pages/api/oppslag/soeker.ts | 3 +- pages/api/oppslag/soekerUtenBarn.ts | 3 +- pages/api/oppslagapi/fastlege.ts | 5 +- pages/api/oppslagapi/person.ts | 5 +- pages/api/vedlegg/lagre.ts | 5 +- pages/api/vedlegg/slett.ts | 3 +- pages/api/vedlegginnsending/lagre.ts | 3 +- pages/api/vedlegginnsending/slett.ts | 4 +- pages/index.tsx | 12 ++-- utils/metrics.ts | 4 +- yarn.lock | 82 +++++++----------------- 26 files changed, 88 insertions(+), 143 deletions(-) diff --git a/auth/beskyttetApi.ts b/auth/beskyttetApi.ts index 61405028..95f3fbf8 100644 --- a/auth/beskyttetApi.ts +++ b/auth/beskyttetApi.ts @@ -1,8 +1,8 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { isMock } from '../utils/environments'; import { verifyIdportenAccessToken } from './verifyIdPortenAccessToken'; -import { logger } from '@navikt/aap-felles-utils'; import { ErrorMedStatus } from './ErrorMedStatus'; +import { logError, logInfo, logWarning } from '@navikt/aap-felles-utils'; type ApiHandler = (req: NextApiRequest, res: NextApiResponse) => void | Promise; @@ -17,27 +17,27 @@ export function beskyttetApi(handler: ApiHandler): ApiHandler { try { if (isMock()) { - logger.warn('handling request for mocked environment, should not happen in production'); + logWarning('handling request for mocked environment, should not happen in production'); return handler(req, res); } const bearerToken: string | null | undefined = req.headers['authorization']; if (!bearerToken) { - logger.warn({ message: 'ingen bearer token', path: req?.url }); + logWarning(`ingen bearer token, path: ${req?.url}`); return send401(); } try { await verifyIdportenAccessToken(bearerToken); } catch (e) { - logger.error(e, 'kunne ikke validere idportentoken i beskyttetApi'); + logError('kunne ikke validere idportentoken i beskyttetApi', e); return send401(); } return handler(req, res); } catch (e) { - logger.error(e); - logger.info('handling error in beskyttetApi'); + logError('beskyttetApi', e); + logInfo('handling error in beskyttetApi'); if (e instanceof ErrorMedStatus) { - logger.info(`sending error with status ${e.status} and message ${e.message}`); + logInfo(`sending error with status ${e.status} and message ${e.message}`); return res.status(e.status).json({ message: e.message, navCallId: e.navCallId }); } } diff --git a/auth/beskyttetSide.ts b/auth/beskyttetSide.ts index d307b865..3cf6d66f 100644 --- a/auth/beskyttetSide.ts +++ b/auth/beskyttetSide.ts @@ -1,8 +1,8 @@ import { NextPageContext, GetServerSidePropsResult } from 'next'; -import { isMock } from '../utils/environments'; +import { isMock } from 'utils/environments'; import { getAccessToken } from './accessToken'; import { verifyIdportenAccessToken } from './verifyIdPortenAccessToken'; -import { logger } from '@navikt/aap-felles-utils'; +import { logError } from '@navikt/aap-felles-utils'; type PageHandler = (context: NextPageContext) => void | Promise>; @@ -15,7 +15,7 @@ const wonderwallRedirect = { export function beskyttetSide(handler: PageHandler) { return async function withBearerTokenHandler( - context: NextPageContext + context: NextPageContext, ): Promise> { if (isMock()) { return handler(context); @@ -30,7 +30,7 @@ export function beskyttetSide(handler: PageHandler) { try { await verifyIdportenAccessToken(bearerToken); } catch (e) { - logger.error(e, 'kunne ikke validere idportentoken i beskyttetSide'); + logError('kunne ikke validere idportentoken i beskyttetSide', e); return wonderwallRedirect; } return handler(context); @@ -42,5 +42,5 @@ export const beskyttetSideUtenProps = beskyttetSide( return { props: {}, }; - } + }, ); diff --git a/lib/utils/TokenxProxy.ts b/lib/utils/TokenxProxy.ts index 99f07852..3081c02a 100644 --- a/lib/utils/TokenxProxy.ts +++ b/lib/utils/TokenxProxy.ts @@ -1,20 +1,20 @@ import { proxyApiRouteRequest } from '@navikt/next-api-proxy'; import { NextApiRequest, NextApiResponse } from 'next'; -import { getAccessTokenFromRequest, getTokenX, logger } from '@navikt/aap-felles-utils'; +import { getAccessTokenFromRequest, getTokenX, logError, logInfo } from '@navikt/aap-felles-utils'; import metrics from '../../utils/metrics'; export const tokenXProxy = async ( req: NextApiRequest, res: NextApiResponse, path: string, - prometheusPath: string + prometheusPath: string, ) => { const accessToken = getAccessTokenFromRequest(req)?.substring('Bearer '.length)!; let tokenxToken; try { tokenxToken = await getTokenX(accessToken, process.env.SOKNAD_API_AUDIENCE!); } catch (err: any) { - logger.error({ msg: 'getTokenXError', error: err }); + logError('getTokenXError', err); } const stopTimer = metrics.backendApiDurationHistogram.startTimer({ path: prometheusPath }); const result = await proxyApiRouteRequest({ @@ -26,7 +26,7 @@ export const tokenXProxy = async ( https: false, }); - logger.info(`res from tokenXProxy: ${JSON.stringify(res.status)}`); + logInfo(`res from tokenXProxy: ${res.status}`); stopTimer(); return result; diff --git a/package.json b/package.json index 237feb73..c2cfe6ac 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,10 @@ "dependencies": { "@amplitude/analytics-browser": "^2.4.0", "@grafana/faro-web-sdk": "^1.3.7", - "@navikt/aap-felles-css": "^0.0.96", - "@navikt/aap-felles-react": "^0.0.96", - "@navikt/aap-felles-utils": "^0.0.96", - "@navikt/aap-felles-utils-client": "^0.0.96", + "@navikt/aap-felles-css": "^0.0.97", + "@navikt/aap-felles-react": "^0.0.97", + "@navikt/aap-felles-utils": "^0.0.97", + "@navikt/aap-felles-utils-client": "^0.0.97", "@navikt/ds-css": "^5.17.4", "@navikt/ds-icons": "^3.4.3", "@navikt/ds-react": "^5.17.4", diff --git a/pages/[step].tsx b/pages/[step].tsx index bdfb83d7..6bb4b1dd 100644 --- a/pages/[step].tsx +++ b/pages/[step].tsx @@ -35,7 +35,6 @@ import { scrollRefIntoView } from 'utils/dom'; import { Steg0 } from 'components/pageComponents/standard/Steg0/Steg0'; import * as classes from './step.module.css'; import { FormattedMessage, useIntl } from 'react-intl'; -import { logger } from '@navikt/aap-felles-utils'; import { SoknadContextProvider, SoknadContextState } from 'context/soknadcontext/soknadContext'; import { useSoknad } from 'hooks/SoknadHook'; import { @@ -49,6 +48,7 @@ import { Barn, getBarn } from 'pages/api/oppslag/barn'; import { formatNavn } from 'utils/StringFormatters'; import { hentMellomlagring } from 'pages/api/mellomlagring/les'; import { RequiredVedlegg } from 'types/SoknadContext'; +import { logError, logInfo, logWarning } from '@navikt/aap-felles-utils'; interface PageProps { søker: SokerOppslagState; @@ -235,7 +235,7 @@ export const getServerSideProps = beskyttetSide( try { kontaktinformasjon = await getKrr(bearerToken); } catch (e) { - logger.error({ message: `Noe gikk galt i kallet mot oppslag/krr: ${e?.toString()}` }); + logError(`Noe gikk galt i kallet mot oppslag/krr`, e); } let mellomlagretSøknad: SoknadContextState | undefined; @@ -245,23 +245,23 @@ export const getServerSideProps = beskyttetSide( await Promise.all([lesBucket('STANDARD', bearerToken), hentMellomlagring(bearerToken)]); if (mellomlagretSøknadFraAapInnsending && mellomlagretSøknadFraSoknadApi) { - logger.error('pages/step: finner mellomlagring fra begge kilder'); + logError('pages/step: finner mellomlagring fra begge kilder'); } if (mellomlagretSøknadFraSoknadApi) { - logger.info('pages/step: velger mellomlagring fra søknad-api'); + logInfo('pages/step: velger mellomlagring fra søknad-api'); mellomlagretSøknad = { ...mellomlagretSøknadFraSoknadApi, brukerMellomLagretSøknadFraAApInnsending: false, }; } else if (mellomlagretSøknadFraAapInnsending) { - logger.info('pages/step: velger mellomlagring fra innsending'); + logInfo('pages/step: velger mellomlagring fra innsending'); mellomlagretSøknad = { ...mellomlagretSøknadFraAapInnsending, brukerMellomLagretSøknadFraAApInnsending: true, }; } } catch (e) { - logger.error('Noe gikk galt i innhenting av mellomlagret søknad', e); + logError('Noe gikk galt i innhenting av mellomlagret søknad', e); } let barn: Barn[] = søker?.søker?.barn?.map((barn) => { @@ -271,17 +271,17 @@ export const getServerSideProps = beskyttetSide( try { barn = await getBarn(bearerToken); } catch (e) { - logger.error('Noe gikk galt i kallet mot barn fra aap-oppslag', e); + logError('Noe gikk galt i kallet mot barn fra aap-oppslag', e); } stopTimer(); if (mellomlagretSøknad && !mellomlagretSøknad.lagretStepList) { - logger.error('Mellomlagret søknad finnes, men mangler stepList'); + logError('Mellomlagret søknad finnes, men mangler stepList'); } if (!mellomlagretSøknad?.lagretStepList) { - logger.warn('lagretStepList mangler i mellomlagret søknad, redirecter til startsiden'); + logWarning('lagretStepList mangler i mellomlagret søknad, redirecter til startsiden'); return { redirect: { destination: '/', diff --git a/pages/api/buckets/lagre.ts b/pages/api/buckets/lagre.ts index 34080f8c..77368abf 100644 --- a/pages/api/buckets/lagre.ts +++ b/pages/api/buckets/lagre.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { tokenXApiProxy, logger } from '@navikt/aap-felles-utils'; +import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils'; import { lagreCache } from 'mock/mellomlagringsCache'; import { erGyldigSøknadsType, GYLDIGE_SØKNADS_TYPER, SøknadsType } from 'utils/api'; import { isFunctionalTest, isMock } from 'utils/environments'; @@ -28,7 +28,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) = (e: StepType) => e.active, )?.stepIndex; - logger.error( + logError( `Overskriver eksisterende søknad med en tom søknad på side ${activeStepIndex ?? 'ukjent'}`, ); } @@ -49,7 +49,6 @@ export const lagreBucket = async (type: SøknadsType, data: string, accessToken? bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); return; }; diff --git a/pages/api/buckets/les.ts b/pages/api/buckets/les.ts index 3dd4782b..be81855d 100644 --- a/pages/api/buckets/les.ts +++ b/pages/api/buckets/les.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { logInfo, tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { erGyldigSøknadsType, GYLDIGE_SØKNADS_TYPER, SøknadsType } from 'utils/api'; import { isMock } from 'utils/environments'; @@ -40,7 +40,6 @@ export const lesBucket = async ( bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); if (!mellomlagretSøknad) { @@ -54,7 +53,7 @@ export const lesBucket = async ( await new Promise((resolve) => setTimeout(resolve, 300)); return await lesBucket(type, accessToken, retryCount - 1); } - logger.info('Fant ingen mellomlagret søknad hos soknad-api'); + logInfo('Fant ingen mellomlagret søknad hos soknad-api'); return undefined; } }; diff --git a/pages/api/buckets/slett.ts b/pages/api/buckets/slett.ts index 4dbad9eb..6a77cb1c 100644 --- a/pages/api/buckets/slett.ts +++ b/pages/api/buckets/slett.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { tokenXApiProxy, logger } from '@navikt/aap-felles-utils'; +import { tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { deleteCache } from 'mock/mellomlagringsCache'; import { erGyldigSøknadsType, GYLDIGE_SØKNADS_TYPER, SøknadsType } from 'utils/api'; @@ -34,7 +34,6 @@ export const slettBucket = async (type: SøknadsType, accessToken?: string) => { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); }; diff --git a/pages/api/innsending/soknadapi.ts b/pages/api/innsending/soknadapi.ts index e731387f..f469a411 100644 --- a/pages/api/innsending/soknadapi.ts +++ b/pages/api/innsending/soknadapi.ts @@ -2,7 +2,7 @@ import { randomUUID } from 'crypto'; import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { tokenXApiProxy, logger } from '@navikt/aap-felles-utils'; +import { tokenXApiProxy } from '@navikt/aap-felles-utils'; import { isFunctionalTest, isMock } from 'utils/environments'; import { slettBucket } from '../buckets/slett'; import { ErrorMedStatus } from 'auth/ErrorMedStatus'; @@ -40,7 +40,6 @@ export const sendSoknad = async (data: string, accessToken?: string) => { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); return søknad; }; diff --git a/pages/api/innsending/soknadinnsending.ts b/pages/api/innsending/soknadinnsending.ts index 6f0db24d..6636321e 100644 --- a/pages/api/innsending/soknadinnsending.ts +++ b/pages/api/innsending/soknadinnsending.ts @@ -1,5 +1,5 @@ import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils'; import { NextApiRequest, NextApiResponse } from 'next'; import metrics from 'utils/metrics'; import { ErrorMedStatus } from 'auth/ErrorMedStatus'; @@ -113,7 +113,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) = metrics.sendSoknadCounter.inc({ type: 'STANDARD' }); res.status(201).send('Vi har mottat søknaden'); } catch (err) { - logger.error(`Noe gikk galt ved innsending av søknad: ${err?.toString()}`); + logError(`Noe gikk galt ved innsending av søknad`, err); if (err instanceof ErrorMedStatus) { res.status(err.status).json({ navCallId: err.navCallId }); @@ -164,7 +164,6 @@ export const sendSoknadViaAapInnsending = async ( bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, noResponse: true, }); return søknad; diff --git a/pages/api/mellomlagring/lagre.ts b/pages/api/mellomlagring/lagre.ts index fe3ff7c0..7b9db328 100644 --- a/pages/api/mellomlagring/lagre.ts +++ b/pages/api/mellomlagring/lagre.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils'; import { lagreCache } from 'mock/mellomlagringsCache'; import { isFunctionalTest, isMock } from 'utils/environments'; import metrics from 'utils/metrics'; @@ -23,7 +23,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) = (e: StepType) => e.active, )?.stepIndex; - logger.error( + logError( `Overskriver eksisterende søknad med en tom søknad på side ${activeStepIndex ?? 'ukjent'}`, ); } @@ -44,7 +44,6 @@ export const lagreBucket = async (data: string, accessToken?: string) => { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); return; }; diff --git a/pages/api/mellomlagring/les.ts b/pages/api/mellomlagring/les.ts index 37777e65..00abe479 100644 --- a/pages/api/mellomlagring/les.ts +++ b/pages/api/mellomlagring/les.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { lesCache } from 'mock/mellomlagringsCache'; import { isFunctionalTest, isMock } from 'utils/environments'; @@ -39,12 +39,11 @@ export const hentMellomlagring = async ( bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); return mellomlagretSøknad; } catch (error: any) { - logger.error('Noe gikk galt i henting av mellomlagring fra aap-innsending', error); + logError('Noe gikk galt i henting av mellomlagring fra aap-innsending', error); return undefined; } }; diff --git a/pages/api/mellomlagring/slett.ts b/pages/api/mellomlagring/slett.ts index ad077b98..8b6ce975 100644 --- a/pages/api/mellomlagring/slett.ts +++ b/pages/api/mellomlagring/slett.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { deleteCache } from 'mock/mellomlagringsCache'; import { isMock } from 'utils/environments'; @@ -27,7 +27,6 @@ export const slettBucket = async (accessToken?: string) => { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); }; diff --git a/pages/api/oppslag/barn.ts b/pages/api/oppslag/barn.ts index a2d57bf4..5771cea8 100644 --- a/pages/api/oppslag/barn.ts +++ b/pages/api/oppslag/barn.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { z } from 'zod'; @@ -25,12 +25,11 @@ export const getBarn = async (accessToken?: string): Promise> => { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); const validatedResponse = z.array(Barn).safeParse(barn); if (!validatedResponse.success) { - logger.error({ message: `oppslag/barn valideringsfeil: ${validatedResponse.error.message}` }); + logError(`oppslag/barn valideringsfeil: ${validatedResponse.error.message}`); return []; } return validatedResponse.data; diff --git a/pages/api/oppslag/krr.ts b/pages/api/oppslag/krr.ts index 580d9b61..80e32257 100644 --- a/pages/api/oppslag/krr.ts +++ b/pages/api/oppslag/krr.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils'; import { isMock } from 'utils/environments'; import metrics from 'utils/metrics'; import { KontaktInfoView } from 'context/sokerOppslagContext'; @@ -28,11 +28,10 @@ export const getKrr = async (accessToken?: string) => { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); const validatedResponse = KrrInfo.safeParse(krr); if (!validatedResponse.success) { - logger.error({ message: `oppslag/krr valideringsfeil: ${validatedResponse.error.message}` }); + logError(`oppslag/krr valideringsfeil: ${validatedResponse.error.message}`); return {}; } return validatedResponse.data; diff --git a/pages/api/oppslag/soeker.ts b/pages/api/oppslag/soeker.ts index 567cbe7c..50aa798a 100644 --- a/pages/api/oppslag/soeker.ts +++ b/pages/api/oppslag/soeker.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { tokenXApiProxy, logger } from '@navikt/aap-felles-utils'; +import { tokenXApiProxy } from '@navikt/aap-felles-utils'; import { mockSøker } from 'mock/søker'; import { isMock } from 'utils/environments'; import metrics from 'utils/metrics'; @@ -21,7 +21,6 @@ export const getSøker = async (accessToken?: string): Promise { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); return søker; }; diff --git a/pages/api/oppslagapi/fastlege.ts b/pages/api/oppslagapi/fastlege.ts index 8b354d00..247a8946 100644 --- a/pages/api/oppslagapi/fastlege.ts +++ b/pages/api/oppslagapi/fastlege.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { OppslagBehandler } from 'context/sokerOppslagContext'; import { z } from 'zod'; @@ -30,12 +30,11 @@ export const getFastlege = async (accessToken?: string) => { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); const validatedResponse = z.array(Fastlege).safeParse(fastlege); if (!validatedResponse.success) { - logger.error({ message: `oppslag/person valideringsfeil: ${validatedResponse.error.message}` }); + logError(`oppslag/person valideringsfeil: ${validatedResponse.error.message}`); return {}; } return validatedResponse.data; diff --git a/pages/api/oppslagapi/person.ts b/pages/api/oppslagapi/person.ts index 90521dc1..7954268e 100644 --- a/pages/api/oppslagapi/person.ts +++ b/pages/api/oppslagapi/person.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { z } from 'zod'; @@ -27,11 +27,10 @@ export const getPerson = async (accessToken?: string) => { bearerToken: accessToken, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, - logger: logger, }); const validatedResponse = Person.safeParse(person); if (!validatedResponse.success) { - logger.error({ message: `oppslag/person valideringsfeil: ${validatedResponse.error.message}` }); + logError(`oppslag/person valideringsfeil: ${validatedResponse.error.message}`); return {}; } return validatedResponse.data; diff --git a/pages/api/vedlegg/lagre.ts b/pages/api/vedlegg/lagre.ts index 64bda974..608f9df8 100644 --- a/pages/api/vedlegg/lagre.ts +++ b/pages/api/vedlegg/lagre.ts @@ -1,12 +1,12 @@ import { randomUUID } from 'crypto'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { tokenXApiStreamProxy, logger } from '@navikt/aap-felles-utils'; +import { tokenXApiStreamProxy, logInfo } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { isMock } from 'utils/environments'; const handler = beskyttetApi(async (req, res) => { - logger.info('Har mottatt request om filopplasting'); + logInfo('Har mottatt request om filopplasting'); const accessToken = getAccessTokenFromRequest(req); if (isMock()) { res.status(201).json(randomUUID()); @@ -18,7 +18,6 @@ const handler = beskyttetApi(async (req, res) => { res, audience: process.env.SOKNAD_API_AUDIENCE!, bearerToken: accessToken, - logger: logger, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, }); diff --git a/pages/api/vedlegg/slett.ts b/pages/api/vedlegg/slett.ts index c885a57a..1d1f6a45 100644 --- a/pages/api/vedlegg/slett.ts +++ b/pages/api/vedlegg/slett.ts @@ -1,6 +1,6 @@ import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { isMock } from 'utils/environments'; import { getCommaSeparatedStringFromStringOrArray } from 'utils/string'; @@ -25,7 +25,6 @@ export const slettVedlegg = async (uuids: string | string[], accessToken?: strin noResponse: true, audience: process.env.SOKNAD_API_AUDIENCE!, bearerToken: accessToken, - logger: logger, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, }); diff --git a/pages/api/vedlegginnsending/lagre.ts b/pages/api/vedlegginnsending/lagre.ts index 30d104a6..45a61564 100644 --- a/pages/api/vedlegginnsending/lagre.ts +++ b/pages/api/vedlegginnsending/lagre.ts @@ -1,7 +1,7 @@ import { randomUUID } from 'crypto'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { tokenXApiStreamProxy, logger } from '@navikt/aap-felles-utils'; +import { tokenXApiStreamProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { isMock } from 'utils/environments'; @@ -15,7 +15,6 @@ const handler = beskyttetApi(async (req, res) => { res, audience: process.env.INNSENDING_AUDIENCE!, bearerToken: accessToken, - logger: logger, metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, metricsTimer: metrics.backendApiDurationHistogram, }); diff --git a/pages/api/vedlegginnsending/slett.ts b/pages/api/vedlegginnsending/slett.ts index 4211f842..97b56d5c 100644 --- a/pages/api/vedlegginnsending/slett.ts +++ b/pages/api/vedlegginnsending/slett.ts @@ -1,4 +1,4 @@ -import { getTokenX, logger } from '@navikt/aap-felles-utils'; +import { getTokenX, logError } from '@navikt/aap-felles-utils'; import { proxyApiRouteRequest } from '@navikt/next-api-proxy'; import { NextApiRequest, NextApiResponse } from 'next'; import { beskyttetApi } from 'auth/beskyttetApi'; @@ -28,7 +28,7 @@ export const slettVedleggInnsending = async ( try { tokenXToken = await getTokenX(idportenToken, process.env.INNSENDING_AUDIENCE!); } catch (error) { - logger.error('Kunne ikke hente tokenXToken i sletting av vedlegg i ny innsending', error); + logError('Kunne ikke hente tokenXToken i sletting av vedlegg i ny innsending', error); throw error; } diff --git a/pages/index.tsx b/pages/index.tsx index 23f60229..1aaa71e0 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -12,11 +12,11 @@ import { logSkjemaStartetEvent } from 'utils/amplitude'; import metrics from 'utils/metrics'; import { scrollRefIntoView } from 'utils/dom'; import { getSøkerUtenBarn } from 'pages/api/oppslag/soekerUtenBarn'; -import { logger } from '@navikt/aap-felles-utils'; import { getFulltNavn } from 'lib/søker'; import { SOKNAD_VERSION, SoknadContextState } from 'context/soknadcontext/soknadContext'; import { hentMellomlagring } from 'pages/api/mellomlagring/les'; import { isFunctionalTest } from 'utils/environments'; +import { logError, logInfo } from '@navikt/aap-felles-utils'; interface PageProps { søker: Soker; @@ -118,23 +118,23 @@ export const getServerSideProps = beskyttetSide( await Promise.all([lesBucket('STANDARD', bearerToken), hentMellomlagring(bearerToken)]); if (mellomlagretSøknadFraAapInnsending && mellomlagretSøknadFraSoknadApi) { - logger.error('pages/index: finner mellomlagring fra begge kilder'); + logError('pages/index: finner mellomlagring fra begge kilder'); } if (mellomlagretSøknadFraSoknadApi) { - logger.info('pages/index: velger mellomlagring fra søknad-api'); + logInfo('pages/index: velger mellomlagring fra søknad-api'); mellomlagretSøknad = { ...mellomlagretSøknadFraSoknadApi, brukerMellomLagretSøknadFraAApInnsending: false, }; } else if (mellomlagretSøknadFraAapInnsending) { - logger.info('pages/index: velger mellomlagring fra innsending'); + logInfo('pages/index: velger mellomlagring fra innsending'); mellomlagretSøknad = { ...mellomlagretSøknadFraAapInnsending, brukerMellomLagretSøknadFraAApInnsending: true, }; } } catch (e) { - logger.error('Noe gikk galt i innhenting av mellomlagret søknad', e); + logError('Noe gikk galt i innhenting av mellomlagret søknad', e); } const activeStep = mellomlagretSøknad?.lagretStepList?.find((e: StepType) => e.active); @@ -142,7 +142,7 @@ export const getServerSideProps = beskyttetSide( stopTimer(); if (activeIndex && !isFunctionalTest()) { - logger.info('Starter påbegynt søknad'); + logInfo('Starter påbegynt søknad'); return { redirect: { destination: `/${activeIndex}`, diff --git a/utils/metrics.ts b/utils/metrics.ts index 78e6ef7e..61c1c2d3 100644 --- a/utils/metrics.ts +++ b/utils/metrics.ts @@ -1,5 +1,5 @@ import { collectDefaultMetrics, Counter, Histogram } from 'prom-client'; -import { logger } from '@navikt/aap-felles-utils'; +import { logInfo } from '@navikt/aap-felles-utils'; declare global { var _metrics: AppMetrics; @@ -7,7 +7,7 @@ declare global { export class AppMetrics { constructor() { - logger.info('Initializing metrics client'); + logInfo('Initializing metrics client'); collectDefaultMetrics(); } diff --git a/yarn.lock b/yarn.lock index d5e89241..53f0720e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -587,24 +587,6 @@ __metadata: languageName: node linkType: hard -"@elastic/ecs-helpers@npm:^1.1.0": - version: 1.1.0 - resolution: "@elastic/ecs-helpers@npm:1.1.0" - dependencies: - fast-json-stringify: "npm:^2.4.1" - checksum: 10c0/31774ba70e5728146acfc8813cecce64d7acccd195216ac6833c45f447b36847849fbb9de416b73cfcdfe837e1452c10610d6ead7b9851173ff42728968d0cd4 - languageName: node - linkType: hard - -"@elastic/ecs-pino-format@npm:1.3.0": - version: 1.3.0 - resolution: "@elastic/ecs-pino-format@npm:1.3.0" - dependencies: - "@elastic/ecs-helpers": "npm:^1.1.0" - checksum: 10c0/30ccf54f380c373dff1f4eed995da012560c001a7b1bcdafa918352c0992765305c12f6b95c5784fe0a73551670eb95d12506e8a160b3d471d62532f68ba04e3 - languageName: node - linkType: hard - "@eslint-community/eslint-utils@npm:^4.2.0, @eslint-community/eslint-utils@npm:^4.4.0": version: 4.4.0 resolution: "@eslint-community/eslint-utils@npm:4.4.0" @@ -1232,16 +1214,16 @@ __metadata: languageName: node linkType: hard -"@navikt/aap-felles-css@npm:^0.0.96": - version: 0.0.96 - resolution: "@navikt/aap-felles-css@npm:0.0.96::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40navikt%2Faap-felles-css%2F0.0.96%2F6b9a731d948521b52b602f466637beed6084fbcd" - checksum: 10c0/1985a4fdc8884898b3412c1de5b4a2759c45ebdd95dcf71312cd200cf2bb22548adb9136690544c974f0f7fe1311db6975b829e5e2e4aa5df93f8dded436f4d3 +"@navikt/aap-felles-css@npm:^0.0.97": + version: 0.0.97 + resolution: "@navikt/aap-felles-css@npm:0.0.97::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40navikt%2Faap-felles-css%2F0.0.97%2Fdd5e06805adc3c96cd8a6ce88223233e791a8ea2" + checksum: 10c0/26d235cf502a68da5f556ba1a2f8982cee0169ce111a5adc02ec09e03ebc07c56f5c67b51d1e6f71ebd40985543af5b598660b085b53997acfe4f744a55dba7c languageName: node linkType: hard -"@navikt/aap-felles-react@npm:^0.0.96": - version: 0.0.96 - resolution: "@navikt/aap-felles-react@npm:0.0.96::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40navikt%2Faap-felles-react%2F0.0.96%2F65937f7aa3d79752515a8b06ab0662bc9d789702" +"@navikt/aap-felles-react@npm:^0.0.97": + version: 0.0.97 + resolution: "@navikt/aap-felles-react@npm:0.0.97::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40navikt%2Faap-felles-react%2F0.0.97%2Fa67c15a05b97b73afe8da85721cdb6316ecc9181" dependencies: "@navikt/aksel-icons": "npm:^5.4.1" "@navikt/ds-css": "npm:^5.4.1" @@ -1249,31 +1231,30 @@ __metadata: prop-types: "npm:^15.8.1" react: "npm:^18.2.0" uuid: "npm:^9.0.1" - checksum: 10c0/81f6d4aab2ff0a8015cbfa0368c03c1fb97e43b7d624fa4c0af1adfffbd17900f5aa6fb47f53acec408c3ec12486cafa38d01a615c2588fc82514240714f553b + checksum: 10c0/53f1332b2673151a1a9f7af4cf091de4593626d6e90fca70eb646b136eff381aba0723c277ed905699d170566d9aa4f1e55a6d24d4d01be53a95a6e934359fd0 languageName: node linkType: hard -"@navikt/aap-felles-utils-client@npm:^0.0.96": - version: 0.0.96 - resolution: "@navikt/aap-felles-utils-client@npm:0.0.96::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40navikt%2Faap-felles-utils-client%2F0.0.96%2F2505bdb6d9c43004b436703cf1b0b38d72d0df39" +"@navikt/aap-felles-utils-client@npm:^0.0.97": + version: 0.0.97 + resolution: "@navikt/aap-felles-utils-client@npm:0.0.97::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40navikt%2Faap-felles-utils-client%2F0.0.97%2F6ad59f49e97f9f53746c8e4d721b51182e82bf24" dependencies: date-fns: "npm:^2.30.0" - checksum: 10c0/e389ab2aa0405401fde22293bb6a69f03292f15fa197d39cf113f165208feca2b41bdcfef4a4d4dc27546c3de1ca4b58303ad0204d2bee698a2a0b4cd48d8d0c + checksum: 10c0/97c87ea94fa1720330e400d7e209de4252fe8420d2b38d9f9964d2efb8ee0ac34aa1a14d86420fbf476821db8488533167fa9b6d52f230d773912683f0797dc7 languageName: node linkType: hard -"@navikt/aap-felles-utils@npm:^0.0.96": - version: 0.0.96 - resolution: "@navikt/aap-felles-utils@npm:0.0.96::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40navikt%2Faap-felles-utils%2F0.0.96%2F0f25a01b13d402450682520794d37a9a0ec47d62" +"@navikt/aap-felles-utils@npm:^0.0.97": + version: 0.0.97 + resolution: "@navikt/aap-felles-utils@npm:0.0.97::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40navikt%2Faap-felles-utils%2F0.0.97%2Fb0f0ced925e86f382d9815189d41a03bbba6fb66" dependencies: - "@elastic/ecs-pino-format": "npm:1.3.0" axios: "npm:^1.2.1" jose: "npm:^4.11.1" next: "npm:14.1.0" openid-client: "npm:^5.3.1" pino: "npm:^8.8.0" prom-client: "npm:^14.1.0" - checksum: 10c0/6eaf607e14022027f0ecfa41d498e521c1dcc06d3681e1ec92346f855a290a6e35da1d8abb54c9c0e9b59318ae2ed52d82cac72c0c071205916d7c95823e5d8b + checksum: 10c0/e3521875305edac6dcaa8d0ec44b370b15307c6d3090b1bfc6acf1f0962c7a6782c6c8af3deb096977c12d088b1616b40ce6e9c1b4c861412d5763234781bb0c languageName: node linkType: hard @@ -2858,10 +2839,10 @@ __metadata: "@amplitude/analytics-browser": "npm:^2.4.0" "@axe-core/playwright": "npm:^4.8.4" "@grafana/faro-web-sdk": "npm:^1.3.7" - "@navikt/aap-felles-css": "npm:^0.0.96" - "@navikt/aap-felles-react": "npm:^0.0.96" - "@navikt/aap-felles-utils": "npm:^0.0.96" - "@navikt/aap-felles-utils-client": "npm:^0.0.96" + "@navikt/aap-felles-css": "npm:^0.0.97" + "@navikt/aap-felles-react": "npm:^0.0.97" + "@navikt/aap-felles-utils": "npm:^0.0.97" + "@navikt/aap-felles-utils-client": "npm:^0.0.97" "@navikt/ds-css": "npm:^5.17.4" "@navikt/ds-icons": "npm:^3.4.3" "@navikt/ds-react": "npm:^5.17.4" @@ -3030,7 +3011,7 @@ __metadata: languageName: node linkType: hard -"ajv@npm:^6.11.0, ajv@npm:^6.12.4": +"ajv@npm:^6.12.4": version: 6.12.6 resolution: "ajv@npm:6.12.6" dependencies: @@ -4779,18 +4760,6 @@ __metadata: languageName: node linkType: hard -"fast-json-stringify@npm:^2.4.1": - version: 2.7.13 - resolution: "fast-json-stringify@npm:2.7.13" - dependencies: - ajv: "npm:^6.11.0" - deepmerge: "npm:^4.2.2" - rfdc: "npm:^1.2.0" - string-similarity: "npm:^4.0.1" - checksum: 10c0/9c63e9e575bd75153afe456bd5c1d8afbfade79c79578f89fc0b8d599cdd65f3e731c826241caf472e11a915e6351a4c4c3f8295096be3fb01a79d2dbbbb22ed - languageName: node - linkType: hard - "fast-levenshtein@npm:^2.0.6, fast-levenshtein@npm:~2.0.6": version: 2.0.6 resolution: "fast-levenshtein@npm:2.0.6" @@ -8439,7 +8408,7 @@ __metadata: languageName: node linkType: hard -"rfdc@npm:^1.2.0, rfdc@npm:^1.3.0": +"rfdc@npm:^1.3.0": version: 1.3.0 resolution: "rfdc@npm:1.3.0" checksum: 10c0/a17fd7b81f42c7ae4cb932abd7b2f677b04cc462a03619fb46945ae1ccae17c3bc87c020ffdde1751cbfa8549860a2883486fdcabc9b9de3f3108af32b69a667 @@ -8808,13 +8777,6 @@ __metadata: languageName: node linkType: hard -"string-similarity@npm:^4.0.1": - version: 4.0.4 - resolution: "string-similarity@npm:4.0.4" - checksum: 10c0/fce331b818efafa701f692ddc2e170bd3ceaf6e7ca56a445b36b139981effe0884d8edc794a65005e54304da55ba054edfcff16a339bd301c9b94983fbc62047 - languageName: node - linkType: hard - "string-width-cjs@npm:string-width@^4.2.0, string-width@npm:^4.1.0, string-width@npm:^4.2.0, string-width@npm:^4.2.3": version: 4.2.3 resolution: "string-width@npm:4.2.3"