@@ -50,7 +50,9 @@ func (_ nullClient) Close() error {
5050 return nil
5151}
5252
53- func init () {
53+ // Initialize the telemetry client.
54+ // This should be called once at startup either from the root command or from a subcommand that overrides the default PersistentPreRun.
55+ func Init (isLoggingEnabled bool ) {
5456 // Opt-out mechanism
5557 disableTelemetry := os .Getenv ("AKITA_DISABLE_TELEMETRY" )
5658 if disableTelemetry != "" {
@@ -70,31 +72,37 @@ func init() {
7072 segmentKey = defaultSegmentKey
7173 }
7274 if segmentKey == "" {
73- printer .Infof ("Telemetry unavailable; no Segment key configured.\n " )
74- printer .Infof ("This is caused by building from source rather than using an official build.\n " )
75+ if isLoggingEnabled {
76+ printer .Infof ("Telemetry unavailable; no Segment key configured.\n " )
77+ printer .Infof ("This is caused by building from source rather than using an official build.\n " )
78+ }
7579 analyticsClient = nullClient {}
7680 return
7781 }
7882
7983 var err error
80- analyticsClient , err = analytics .NewClient (analytics.Config {
81- WriteKey : segmentKey ,
82- SegmentEndpoint : segmentEndpoint ,
83- App : analytics.AppInfo {
84- Name : "akita-cli" ,
85- Version : version .ReleaseVersion ().String (),
86- Build : version .GitVersion (),
87- Namespace : "" ,
84+ analyticsClient , err = analytics .NewClient (
85+ analytics.Config {
86+ WriteKey : segmentKey ,
87+ SegmentEndpoint : segmentEndpoint ,
88+ App : analytics.AppInfo {
89+ Name : "akita-cli" ,
90+ Version : version .ReleaseVersion ().String (),
91+ Build : version .GitVersion (),
92+ Namespace : "" ,
93+ },
94+ // No output from the Segment library
95+ IsLoggingEnabled : false ,
96+ // IsMixpanelEnabled: false, -- irrelevant for us, leaving at default value
97+ BatchSize : 1 , // disable batching
8898 },
89- // No output from the Segment library
90- IsLoggingEnabled : false ,
91- // IsMixpanelEnabled: false, -- irrelevant for us, leaving at default value
92- BatchSize : 1 , // disable batching
93- })
99+ )
94100 if err != nil {
95- printer .Infof ("Telemetry unavailable; error setting up Segment client: %v\n " , err )
96- printer .Infof ("Akita support will not be able to see any errors you encounter.\n " )
97- printer .Infof ("Please send this log message to support@akitasoftware.com.\n " )
101+ if isLoggingEnabled {
102+ printer .Infof ("Telemetry unavailable; error setting up Segment client: %v\n " , err )
103+ printer .Infof ("Akita support will not be able to see any errors you encounter.\n " )
104+ printer .Infof ("Please send this log message to support@akitasoftware.com.\n " )
105+ }
98106 analyticsClient = nullClient {}
99107 } else {
100108 analyticsEnabled = true
0 commit comments