Add Sentry and Baselime packages in the monitoring section

This commit introduces Sentry and Baselime packages into the monitoring section, complete with associated dependencies and scripts. These changes also reflect necessary updates to the 'pnpm-lock.yaml' file to account for these new dependencies.
This commit is contained in:
giancarlo
2024-04-04 01:09:19 +08:00
parent 67763d3e1f
commit 24a68b2b1f
24 changed files with 2147 additions and 983 deletions

View File

@@ -0,0 +1,46 @@
/**
* @name DEFAULT_INSTRUMENTATION_PROVIDER
* @description Register monitoring instrumentation based on the MONITORING_INSTRUMENTATION_PROVIDER environment variable.
*/
const DEFAULT_INSTRUMENTATION_PROVIDER =
process.env.MONITORING_INSTRUMENTATION_PROVIDER;
enum InstrumentationProvider {
Baselime = 'baselime',
Sentry = 'sentry',
}
/**
* @name registerInstrumentation
* @description Register monitoring instrumentation based on the MONITORING_INSTRUMENTATION_PROVIDER environment variable.
*
* Please set the MONITORING_INSTRUMENTATION_PROVIDER environment variable to register the monitoring instrumentation provider.
*/
export async function registerInstrumentation() {
// Only run instrumentation in Node.js environment
if (
process.env.NEXT_RUNTIME !== 'nodejs' ||
!DEFAULT_INSTRUMENTATION_PROVIDER
) {
return;
}
switch (DEFAULT_INSTRUMENTATION_PROVIDER) {
case InstrumentationProvider.Baselime: {
const { registerBaselimeInstrumentation } = await import('@kit/baselime');
return registerBaselimeInstrumentation();
}
case InstrumentationProvider.Sentry: {
const { registerSentryInstrumentation } = await import('@kit/sentry');
return registerSentryInstrumentation();
}
default:
throw new Error(
`Unknown instrumentation provider: ${DEFAULT_INSTRUMENTATION_PROVIDER}`,
);
}
}