Refactor monitoring instrumentation setup
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.
This commit is contained in:
@@ -53,4 +53,8 @@ NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=
|
||||
NEXT_PUBLIC_ENABLE_ACCOUNT_DELETION=true
|
||||
NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_BILLING=true
|
||||
NEXT_PUBLIC_ENABLE_ORGANIZATION_DELETION=true
|
||||
NEXT_PUBLIC_ENABLE_ORGANIZATION_BILLING=true
|
||||
NEXT_PUBLIC_ENABLE_ORGANIZATION_BILLING=true
|
||||
|
||||
# MONITORING
|
||||
MONITORING_PROVIDER=
|
||||
MONITORING_INSTRUMENTATION_ENABLED=false
|
||||
@@ -3,14 +3,12 @@
|
||||
* for your Next.js application.
|
||||
*/
|
||||
|
||||
const RUNTIME = process.env.NEXT_RUNTIME;
|
||||
|
||||
const ENABLE_INSTRUMENTATION =
|
||||
process.env.MONITORING_INSTRUMENTATION_ENABLED === 'true';
|
||||
|
||||
export async function register() {
|
||||
// only run in nodejs runtime
|
||||
if (RUNTIME === 'nodejs' && ENABLE_INSTRUMENTATION) {
|
||||
if (
|
||||
process.env.NEXT_RUNTIME === 'nodejs' &&
|
||||
process.env.MONITORING_INSTRUMENTATION_ENABLED
|
||||
) {
|
||||
const { registerMonitoringInstrumentation } = await import(
|
||||
'@kit/monitoring/instrumentation'
|
||||
);
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function registerInstrumentation() {
|
||||
resource: new Resource({
|
||||
[SEMRESATTRS_SERVICE_NAME]: serviceName,
|
||||
}),
|
||||
spanProcessor: new SentrySpanProcessor(),
|
||||
spanProcessors: [new SentrySpanProcessor()],
|
||||
textMapPropagator: new SentryPropagator(),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import { InstrumentationProvider } from './monitoring-providers.enum';
|
||||
|
||||
/**
|
||||
* @name MONITORING_PROVIDER
|
||||
* @description Register monitoring instrumentation based on the MONITORING_PROVIDER environment variable.
|
||||
*/
|
||||
const MONITORING_PROVIDER = process.env.MONITORING_PROVIDER as
|
||||
| InstrumentationProvider
|
||||
| undefined;
|
||||
|
||||
/**
|
||||
* @name registerMonitoringInstrumentation
|
||||
* @description Register monitoring instrumentation based on the MONITORING_PROVIDER environment variable.
|
||||
@@ -15,13 +7,13 @@ const MONITORING_PROVIDER = process.env.MONITORING_PROVIDER as
|
||||
* Please set the MONITORING_PROVIDER environment variable to register the monitoring instrumentation provider.
|
||||
*/
|
||||
export async function registerMonitoringInstrumentation() {
|
||||
if (!MONITORING_PROVIDER) {
|
||||
if (!process.env.MONITORING_PROVIDER) {
|
||||
console.info(`No instrumentation provider specified. Skipping...`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (MONITORING_PROVIDER) {
|
||||
switch (process.env.MONITORING_PROVIDER as InstrumentationProvider) {
|
||||
case InstrumentationProvider.Baselime: {
|
||||
const { registerInstrumentation } = await import(
|
||||
'@kit/baselime/instrumentation'
|
||||
@@ -40,7 +32,7 @@ export async function registerMonitoringInstrumentation() {
|
||||
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown instrumentation provider: ${MONITORING_PROVIDER as string}`,
|
||||
`Unknown instrumentation provider: ${process.env.MONITORING_PROVIDER}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user