Removed the MONITORING_PROVIDER constant from the monitoring package, replaced it with direct process.env access. This ensures that environment variables are accessed directly at the time of use without intermediate variables. In the apps/web/instrumentation.ts file, refactored condition checks for runtime environment and instrumentation enablement, using direct access environmental variables. This change simplifies the code and improves readability.
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { InstrumentationProvider } from './monitoring-providers.enum';
|
|
|
|
/**
|
|
* @name registerMonitoringInstrumentation
|
|
* @description Register monitoring instrumentation based on the MONITORING_PROVIDER environment variable.
|
|
*
|
|
* Please set the MONITORING_PROVIDER environment variable to register the monitoring instrumentation provider.
|
|
*/
|
|
export async function registerMonitoringInstrumentation() {
|
|
if (!process.env.MONITORING_PROVIDER) {
|
|
console.info(`No instrumentation provider specified. Skipping...`);
|
|
|
|
return;
|
|
}
|
|
|
|
switch (process.env.MONITORING_PROVIDER as InstrumentationProvider) {
|
|
case InstrumentationProvider.Baselime: {
|
|
const { registerInstrumentation } = await import(
|
|
'@kit/baselime/instrumentation'
|
|
);
|
|
|
|
return registerInstrumentation();
|
|
}
|
|
|
|
case InstrumentationProvider.Sentry: {
|
|
const { registerInstrumentation } = await import(
|
|
'@kit/sentry/instrumentation'
|
|
);
|
|
|
|
return registerInstrumentation();
|
|
}
|
|
|
|
default:
|
|
throw new Error(
|
|
`Unknown instrumentation provider: ${process.env.MONITORING_PROVIDER}`,
|
|
);
|
|
}
|
|
}
|