Skip to content

Commit

Permalink
CNS - Initialize AI logging as early as possible (#2437)
Browse files Browse the repository at this point in the history
app insights should be initialized as early as possible in order to ship important cns start up information to kusto
  • Loading branch information
ramiro-gamarra authored and paulyufan2 committed Dec 18, 2023
1 parent 5bb7515 commit afe3f2d
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,27 @@ func main() {
}
}
configuration.SetCNSConfigDefaults(cnsconfig)

disableTelemetry := cnsconfig.TelemetrySettings.DisableAll
if !disableTelemetry {
ts := cnsconfig.TelemetrySettings
aiConfig := aitelemetry.AIConfig{
AppName: name,
AppVersion: version,
BatchSize: ts.TelemetryBatchSizeBytes,
BatchInterval: ts.TelemetryBatchIntervalInSecs,
RefreshTimeout: ts.RefreshIntervalInSecs,
DisableMetadataRefreshThread: ts.DisableMetadataRefreshThread,
DebugMode: ts.DebugMode,
}

if aiKey := cnsconfig.TelemetrySettings.AppInsightsInstrumentationKey; aiKey != "" {
logger.InitAIWithIKey(aiConfig, aiKey, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
} else {
logger.InitAI(aiConfig, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
}
}

logger.Printf("[Azure CNS] Using config: %+v", cnsconfig)

_, envEnableConflistGeneration := os.LookupEnv(envVarEnableCNIConflistGeneration)
Expand Down Expand Up @@ -639,25 +660,6 @@ func main() {
config.ChannelMode = cns.Managed
}

disableTelemetry := cnsconfig.TelemetrySettings.DisableAll
if !disableTelemetry {
ts := cnsconfig.TelemetrySettings
aiConfig := aitelemetry.AIConfig{
AppName: name,
AppVersion: version,
BatchSize: ts.TelemetryBatchSizeBytes,
BatchInterval: ts.TelemetryBatchIntervalInSecs,
RefreshTimeout: ts.RefreshIntervalInSecs,
DisableMetadataRefreshThread: ts.DisableMetadataRefreshThread,
DebugMode: ts.DebugMode,
}

if aiKey := cnsconfig.TelemetrySettings.AppInsightsInstrumentationKey; aiKey != "" {
logger.InitAIWithIKey(aiConfig, aiKey, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
} else {
logger.InitAI(aiConfig, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
}
}
if telemetryDaemonEnabled {
log.Printf("CNI Telemtry is enabled")
go startTelemetryService(rootCtx)
Expand Down

0 comments on commit afe3f2d

Please sign in to comment.