Yuki Takei 11 месяцев назад
Родитель
Сommit
c10383e88c
1 измененных файлов с 12 добавлено и 4 удалено
  1. 12 4
      apps/app/src/features/opentelemetry/server/node-sdk.ts

+ 12 - 4
apps/app/src/features/opentelemetry/server/node-sdk.ts

@@ -73,7 +73,11 @@ For more information, see https://docs.growi.org/en/admin-guide/admin-cookbook/t
 export const detectServiceInstanceId = async(): Promise<void> => {
   const instrumentationEnabled = configManager.getConfig('otel:enabled', ConfigSource.env);
 
-  if (instrumentationEnabled && sdkInstance != null) {
+  if (instrumentationEnabled) {
+    if (sdkInstance == null) {
+      throw new Error('OpenTelemetry SDK instance is not initialized');
+    }
+
     const { generateNodeSDKConfiguration } = await import('./node-sdk-configuration');
 
     const serviceInstanceId = configManager.getConfig('otel:serviceInstanceId')
@@ -90,15 +94,19 @@ export const detectServiceInstanceId = async(): Promise<void> => {
 export const startOpenTelemetry = (): void => {
   const instrumentationEnabled = configManager.getConfig('otel:enabled', ConfigSource.env);
 
-  if (instrumentationEnabled && sdkInstance != null) {
+  if (instrumentationEnabled) {
+    if (sdkInstance == null) {
+      throw new Error('OpenTelemetry SDK instance is not initialized');
+    }
+
     sdkInstance.start();
   }
 };
 
 // For testing purposes only
 export const __testing__ = {
-  getSdkInstance: () => sdkInstance,
-  reset: () => {
+  getSdkInstance: (): NodeSDK | undefined => sdkInstance,
+  reset: (): void => {
     sdkInstance = undefined;
   },
 };