Refactor Baselime monitoring provider for optional API key
The code was adjusted to not require an API key for the Baselime monitoring provider. Now, a warning will be logged if no key is provided. Dependencies in pnpm-lock.yaml and error message in baselime-server-monitoring.service.ts were also updated accordingly to reflect this change, primarily to utilize the variable 'NEXT_PUBLIC_BASELIME_KEY' instead of 'BASELIME_API_KEY'.
This commit is contained in:
@@ -12,13 +12,24 @@ export function BaselimeProvider({
|
|||||||
enableWebVitals,
|
enableWebVitals,
|
||||||
ErrorPage,
|
ErrorPage,
|
||||||
}: React.PropsWithChildren<{
|
}: React.PropsWithChildren<{
|
||||||
apiKey: string;
|
apiKey?: string;
|
||||||
enableWebVitals?: boolean;
|
enableWebVitals?: boolean;
|
||||||
ErrorPage?: React.ReactElement;
|
ErrorPage?: React.ReactElement;
|
||||||
}>) {
|
}>) {
|
||||||
|
const key = apiKey ?? process.env.NEXT_PUBLIC_BASELIME_KEY ?? '';
|
||||||
|
|
||||||
|
if (!key) {
|
||||||
|
console.warn(
|
||||||
|
'You configured Baselime as monitoring provider but did not provide a key. ' +
|
||||||
|
'Please provide a key to enable monitoring with Baselime using the variable NEXT_PUBLIC_BASELIME_KEY.',
|
||||||
|
);
|
||||||
|
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaselimeRum
|
<BaselimeRum
|
||||||
apiKey={apiKey}
|
apiKey={key}
|
||||||
enableWebVitals={enableWebVitals}
|
enableWebVitals={enableWebVitals}
|
||||||
fallback={ErrorPage ?? null}
|
fallback={ErrorPage ?? null}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import { MonitoringService } from '@kit/monitoring-core';
|
|||||||
|
|
||||||
const apiKey = z
|
const apiKey = z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'BASELIME_API_KEY is required',
|
required_error: 'NEXT_PUBLIC_BASELIME_KEY is required',
|
||||||
})
|
})
|
||||||
.parse(process.env.BASELIME_API_KEY);
|
.parse(process.env.NEXT_PUBLIC_BASELIME_KEY);
|
||||||
|
|
||||||
export class BaselimeServerMonitoringService implements MonitoringService {
|
export class BaselimeServerMonitoringService implements MonitoringService {
|
||||||
userId: string | null = null;
|
userId: string | null = null;
|
||||||
|
|||||||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@@ -1029,10 +1029,6 @@ importers:
|
|||||||
version: 18.2.0
|
version: 18.2.0
|
||||||
|
|
||||||
packages/next:
|
packages/next:
|
||||||
dependencies:
|
|
||||||
'@kit/monitoring':
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../monitoring/api
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@kit/auth':
|
'@kit/auth':
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
@@ -1040,6 +1036,9 @@ importers:
|
|||||||
'@kit/eslint-config':
|
'@kit/eslint-config':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../tooling/eslint
|
version: link:../../tooling/eslint
|
||||||
|
'@kit/monitoring':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../monitoring/api
|
||||||
'@kit/prettier-config':
|
'@kit/prettier-config':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../tooling/prettier
|
version: link:../../tooling/prettier
|
||||||
|
|||||||
Reference in New Issue
Block a user