Files
myeasycms-v2/packages/monitoring/baselime/src/instrumentation.ts
giancarlo 4be66cb3da Update logic for enabling monitoring instrumentation
The logic to enable the monitoring instrumentation was updated in both the Sentry and Baselime packages. This change ensures that the instrumentation is only enabled when the ENV variable 'ENABLE_MONITORING_INSTRUMENTATION' is specifically set to 'true' instead of simply checking for its existence.
2024-05-29 13:57:36 +07:00

38 lines
1.1 KiB
TypeScript

/**
* @name registerInstrumentation
* @description This file is used to register Baselime instrumentation for your Next.js application.
*
* Please set the MONITORING_PROVIDER environment variable to 'baselime' to register Baselime instrumentation.
*/
export async function registerInstrumentation() {
if (process.env.ENABLE_MONITORING_INSTRUMENTATION !== 'true') {
return;
}
const serviceName = process.env.INSTRUMENTATION_SERVICE_NAME;
if (!serviceName) {
throw new Error(`
You have set the Baselime instrumentation provider, but have not set the INSTRUMENTATION_SERVICE_NAME environment variable.
Please set the INSTRUMENTATION_SERVICE_NAME environment variable.
`);
}
if (process.env.NEXT_RUNTIME === 'nodejs') {
const { BaselimeSDK, BetterHttpInstrumentation, VercelPlugin } =
await import('@baselime/node-opentelemetry');
const sdk = new BaselimeSDK({
serverless: true,
service: serviceName,
instrumentations: [
new BetterHttpInstrumentation({
plugins: [new VercelPlugin()],
}),
],
});
sdk.start();
}
}