Implement Baselime monitoring and update error handling
This commit introduces the integration of Baselime for monitoring, accounting for various error scenarios and improved console error logging. Request handling has been updated to assign unique IDs for each request, aiding in tracing/logs. The environment variable key was updated, and the `MonitoringProvider` was nested in the root providers. In the base monitoring service, a function to format errors for logging was added. The provider logic was updated to create a new instance of service for each request, improving memory efficiency.
This commit is contained in:
45
packages/monitoring/src/components/provider.tsx
Normal file
45
packages/monitoring/src/components/provider.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
|
||||
import { lazy } from 'react';
|
||||
|
||||
import { getMonitoringProvider } from '../get-monitoring-provider';
|
||||
import { InstrumentationProvider } from '../monitoring-providers.enum';
|
||||
|
||||
const BaselimeProvider = lazy(async () => {
|
||||
const { BaselimeProvider } = await import('@kit/baselime/provider');
|
||||
|
||||
return {
|
||||
default: BaselimeProvider,
|
||||
};
|
||||
});
|
||||
|
||||
type Config = {
|
||||
provider: InstrumentationProvider;
|
||||
providerToken: string;
|
||||
};
|
||||
|
||||
export function MonitoringProvider(
|
||||
props: React.PropsWithChildren<{ config?: Config }>,
|
||||
) {
|
||||
const provider = getMonitoringProvider();
|
||||
|
||||
if (!props.config) {
|
||||
return <>{props.children}</>;
|
||||
}
|
||||
|
||||
switch (provider) {
|
||||
case InstrumentationProvider.Baselime:
|
||||
return (
|
||||
<BaselimeProvider apiKey={props.config?.providerToken} enableWebVitals>
|
||||
{props.children}
|
||||
</BaselimeProvider>
|
||||
);
|
||||
|
||||
// sentry does not require a provider
|
||||
case InstrumentationProvider.Sentry:
|
||||
return <>{props.children}</>;
|
||||
|
||||
default:
|
||||
return <>{props.children}</>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user