ParseTelemetryState determines the telemetry state based on environment variables and configuration values. The GH_TELEMETRY environment variable takes precedence, followed by DO_NOT_TRACK, then the configuration value. Recognized values for GH_TELEMETRY and config are "enabled", "disabled", "log",
(configValue string)
| 104 | // The GH_TELEMETRY environment variable takes precedence, followed by DO_NOT_TRACK, then the configuration value. |
| 105 | // Recognized values for GH_TELEMETRY and config are "enabled", "disabled", "log", or any falsey value (e.g. "0", "false", "no") to disable telemetry. |
| 106 | func ParseTelemetryState(configValue string) TelemetryState { |
| 107 | // GH_TELEMETRY env var takes highest precedence |
| 108 | if envVal, ok := lookupEnvFunc("GH_TELEMETRY"); ok { |
| 109 | envVal = strings.TrimSpace(strings.ToLower(envVal)) |
| 110 | |
| 111 | // If falsey, telemetry is disabled. |
| 112 | if slices.Contains(falseyValues, envVal) { |
| 113 | return Disabled |
| 114 | } |
| 115 | |
| 116 | // If logged, telemetry is logged instead of sent. |
| 117 | if envVal == "log" { |
| 118 | return Logged |
| 119 | } |
| 120 | |
| 121 | // Any other value (including "enabled") is treated as enabled. |
| 122 | return Enabled |
| 123 | } |
| 124 | |
| 125 | // DO_NOT_TRACK takes precedence over config |
| 126 | if envVal, ok := lookupEnvFunc("DO_NOT_TRACK"); ok { |
| 127 | envVal = strings.TrimSpace(strings.ToLower(envVal)) |
| 128 | if envVal == "1" || envVal == "true" { |
| 129 | return Disabled |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Then check the config values with the same rules. |
| 134 | configValue = strings.TrimSpace(strings.ToLower(configValue)) |
| 135 | |
| 136 | if slices.Contains(falseyValues, configValue) { |
| 137 | return Disabled |
| 138 | } |
| 139 | |
| 140 | if configValue == "log" { |
| 141 | return Logged |
| 142 | } |
| 143 | |
| 144 | return Enabled |
| 145 | } |
| 146 | |
| 147 | type telemetryServiceOpts struct { |
| 148 | additionalDimensions ghtelemetry.Dimensions |