Documentation
¶
Index ¶
- Constants
- func CaptureCmd(cmd *cobra.Command, err ...error)
- func CaptureCmdString(cmdString string, err ...error)
- func PosthogClientProvider(token string, config *posthog.Config) (posthog.Client, error)
- func PreserveCIEnvVars() map[string]string
- func PrintTelemetryDisclosure()
- func RestoreCIEnvVars(envVars map[string]string)
- type Telemetry
- type TelemetryClientProvider
Constants ¶
const ( CommandEventName = "command" // DisclosureMessage contains the standard telemetry disclosure message shown to users // when telemetry is first enabled. It explains that Atmos collects anonymous // usage data and provides a link for users to learn more or opt out. DisclosureMessage = `` /* 320-byte string literal not displayed */ )
CommandEventName is the standard event name used for command telemetry.
Variables ¶
This section is empty.
Functions ¶
func CaptureCmd ¶
CaptureCmd is the public API for capturing cobra command telemetry. It accepts an optional error parameter and handles the case where no error is provided.
func CaptureCmdString ¶
CaptureCmdString is the public API for capturing command string telemetry. It accepts an optional error parameter and handles the case where no error is provided.
func PosthogClientProvider ¶
PosthogClientProvider is the default implementation of TelemetryClientProvider that creates a real PostHog client using the provided token and configuration. PosthogClientProvider is the default implementation of TelemetryClientProvider that creates a real PostHog client using the provided token and configuration.
func PreserveCIEnvVars ¶
PreserveCIEnvVars temporarily removes CI-related environment variables from the current process and returns a map containing the original values. This is useful for testing scenarios where you want to ensure a clean environment without CI detection.
The function handles three categories of CI environment variables: 1. Variables from ciProvidersEnvVarsExists (existence-based detection) 2. Variables from ciProvidersEnvVarsEquals (value-based detection) 3. The general "CI" environment variable
Returns a map of preserved environment variable names to their original values.
func PrintTelemetryDisclosure ¶
func PrintTelemetryDisclosure()
PrintTelemetryDisclosure displays the telemetry disclosure message if one is available. It calls disclosureMessage() to get the message and prints as markdown if a message is returned.
func RestoreCIEnvVars ¶
RestoreCIEnvVars restores previously preserved CI environment variables back to the system. This function is typically called in a defer statement after PreserveCIEnvVars to ensure the original environment is restored, even if the calling function panics or returns early.
Parameters:
- envVars: A map of environment variable names to their original values, typically returned from a previous call to PreserveCIEnvVars
Types ¶
type Telemetry ¶
type Telemetry struct {
// contains filtered or unexported fields
}
Telemetry represents a telemetry system that can capture events and send them to a PostHog analytics service. It provides a configurable way to enable/disable telemetry and customize the client provider for testing purposes.
func NewTelemetry ¶
func NewTelemetry(isEnabled bool, token string, endpoint string, distinctId string, clientProvider TelemetryClientProvider) *Telemetry
NewTelemetry creates a new Telemetry instance with the specified configuration. The clientProvider parameter allows for dependency injection, making it easier to test the telemetry system with mock clients.
func (*Telemetry) Capture ¶
Capture sends a telemetry event to PostHog with the given event name and properties. Returns true if the event was successfully captured, false otherwise. The method handles various failure scenarios gracefully: - Telemetry disabled or missing token. - Client creation failures. - Event enqueue failures.
type TelemetryClientProvider ¶
TelemetryClientProvider is a function type that creates a PostHog client given a token and configuration. This allows for dependency injection and easier testing by providing mock implementations. TelemetryClientProvider is a function type that creates a PostHog client given a token and configuration. The configuration is passed by pointer to avoid copying large structs and to allow tests to modify it.