Skip to content

Commit b030a12

Browse files
CNS - Initialize AI logging as early as possible (#2437)
app insights should be initialized as early as possible in order to ship important cns start up information to kusto
1 parent 6221cb6 commit b030a12

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

cns/service/main.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,27 @@ func main() {
550550
}
551551
}
552552
configuration.SetCNSConfigDefaults(cnsconfig)
553+
554+
disableTelemetry := cnsconfig.TelemetrySettings.DisableAll
555+
if !disableTelemetry {
556+
ts := cnsconfig.TelemetrySettings
557+
aiConfig := aitelemetry.AIConfig{
558+
AppName: name,
559+
AppVersion: version,
560+
BatchSize: ts.TelemetryBatchSizeBytes,
561+
BatchInterval: ts.TelemetryBatchIntervalInSecs,
562+
RefreshTimeout: ts.RefreshIntervalInSecs,
563+
DisableMetadataRefreshThread: ts.DisableMetadataRefreshThread,
564+
DebugMode: ts.DebugMode,
565+
}
566+
567+
if aiKey := cnsconfig.TelemetrySettings.AppInsightsInstrumentationKey; aiKey != "" {
568+
logger.InitAIWithIKey(aiConfig, aiKey, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
569+
} else {
570+
logger.InitAI(aiConfig, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
571+
}
572+
}
573+
553574
logger.Printf("[Azure CNS] Using config: %+v", cnsconfig)
554575

555576
_, envEnableConflistGeneration := os.LookupEnv(envVarEnableCNIConflistGeneration)
@@ -639,25 +660,6 @@ func main() {
639660
config.ChannelMode = cns.Managed
640661
}
641662

642-
disableTelemetry := cnsconfig.TelemetrySettings.DisableAll
643-
if !disableTelemetry {
644-
ts := cnsconfig.TelemetrySettings
645-
aiConfig := aitelemetry.AIConfig{
646-
AppName: name,
647-
AppVersion: version,
648-
BatchSize: ts.TelemetryBatchSizeBytes,
649-
BatchInterval: ts.TelemetryBatchIntervalInSecs,
650-
RefreshTimeout: ts.RefreshIntervalInSecs,
651-
DisableMetadataRefreshThread: ts.DisableMetadataRefreshThread,
652-
DebugMode: ts.DebugMode,
653-
}
654-
655-
if aiKey := cnsconfig.TelemetrySettings.AppInsightsInstrumentationKey; aiKey != "" {
656-
logger.InitAIWithIKey(aiConfig, aiKey, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
657-
} else {
658-
logger.InitAI(aiConfig, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
659-
}
660-
}
661663
if telemetryDaemonEnabled {
662664
log.Printf("CNI Telemtry is enabled")
663665
go startTelemetryService(rootCtx)

0 commit comments

Comments
 (0)