Documentation
¶
Index ¶
- Constants
- func CaptureCmd(cmd *cobra.Command, err ...error)
- func CaptureCmdString(cmdString string, err ...error)
- func IsCI() bool
- func PosthogClientProvider(token string, config *posthog.Config) (posthog.Client, error)
- func PreserveCIEnvVars() map[string]string
- func PrintTelemetryDisclosure()
- func RestoreCIEnvVars(envVars map[string]string)
- type Options
- type PosthogLogger
- func (p *PosthogLogger) Debugf(format string, args ...interface{})
- func (p *PosthogLogger) Errorf(format string, args ...interface{})
- func (p *PosthogLogger) Infof(format string, args ...interface{})
- func (p *PosthogLogger) Logf(format string, args ...interface{})
- func (p *PosthogLogger) Printf(format string, args ...interface{})
- func (p *PosthogLogger) Warnf(format string, args ...interface{})
- type SilentLogger
- func (s *SilentLogger) Debugf(format string, args ...interface{})
- func (s *SilentLogger) Errorf(format string, args ...interface{})
- func (s *SilentLogger) Infof(format string, args ...interface{})
- func (s *SilentLogger) Logf(format string, args ...interface{})
- func (s *SilentLogger) Printf(format string, args ...interface{})
- func (s *SilentLogger) Warnf(format string, args ...interface{})
- type Telemetry
- type TelemetryClientProvider
Constants ¶
const CommandEventName = "command"
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 IsCI ¶ added in v1.194.0
func IsCI() bool
IsCI determines if the current environment is a CI/CD environment. Returns true if CI=true or if a specific CI provider is detected.
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 to stderr with markdown formatting 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 Options ¶ added in v1.191.0
type Options struct {
Endpoint string // PostHog endpoint URL
DistinctID string // Unique identifier for the user/instance
Logging bool // Whether PostHog internal logging is enabled
}
Options contains optional configuration for telemetry.
type PosthogLogger ¶ added in v1.191.0
type PosthogLogger struct {
// contains filtered or unexported fields
}
PosthogLogger is an adapter that implements the posthog.Logger interface using Atmos's charmbracelet/log. This ensures PostHog messages are properly integrated with Atmos logging and respect log levels. It also prevents PostHog errors from being printed directly to stdout/stderr.
func NewPosthogLogger ¶ added in v1.191.0
func NewPosthogLogger() *PosthogLogger
NewPosthogLogger creates a new PosthogLogger instance.
func (*PosthogLogger) Debugf ¶ added in v1.191.0
func (p *PosthogLogger) Debugf(format string, args ...interface{})
Debugf logs debug messages from PostHog using Atmos's logger.
func (*PosthogLogger) Errorf ¶ added in v1.191.0
func (p *PosthogLogger) Errorf(format string, args ...interface{})
Errorf logs error messages from PostHog using Atmos's logger. This prevents PostHog errors from being printed directly to stderr.
func (*PosthogLogger) Infof ¶ added in v1.191.0
func (p *PosthogLogger) Infof(format string, args ...interface{})
Infof logs info messages from PostHog using Atmos's logger. PostHog uses Infof for INFO level messages, but we log them at DEBUG to reduce noise in production.
func (*PosthogLogger) Logf ¶ added in v1.191.0
func (p *PosthogLogger) Logf(format string, args ...interface{})
Logf logs info messages from PostHog using Atmos's logger. PostHog uses Logf for INFO level messages, but we log them at DEBUG to reduce noise in production.
func (*PosthogLogger) Printf ¶ added in v1.191.0
func (p *PosthogLogger) Printf(format string, args ...interface{})
Printf logs messages from PostHog using Atmos's logger. This is a generic print method that PostHog may call. We log at DEBUG level to avoid cluttering user output.
func (*PosthogLogger) Warnf ¶ added in v1.191.0
func (p *PosthogLogger) Warnf(format string, args ...interface{})
Warnf logs warning messages from PostHog using Atmos's logger.
type SilentLogger ¶ added in v1.191.0
type SilentLogger struct{}
SilentLogger is a no-op logger that discards all PostHog messages. It satisfies the posthog.Logger interface but doesn't output anything. This is used when telemetry.posthog_logging is disabled to completely suppress PostHog internal messages.
func NewSilentLogger ¶ added in v1.191.0
func NewSilentLogger() *SilentLogger
NewSilentLogger creates a new SilentLogger instance.
func (*SilentLogger) Debugf ¶ added in v1.191.0
func (s *SilentLogger) Debugf(format string, args ...interface{})
Debugf implements posthog.Logger but does nothing.
func (*SilentLogger) Errorf ¶ added in v1.191.0
func (s *SilentLogger) Errorf(format string, args ...interface{})
Errorf implements posthog.Logger but does nothing.
func (*SilentLogger) Infof ¶ added in v1.191.0
func (s *SilentLogger) Infof(format string, args ...interface{})
Infof implements posthog.Logger but does nothing.
func (*SilentLogger) Logf ¶ added in v1.191.0
func (s *SilentLogger) Logf(format string, args ...interface{})
Logf implements posthog.Logger but does nothing.
func (*SilentLogger) Printf ¶ added in v1.191.0
func (s *SilentLogger) Printf(format string, args ...interface{})
Printf implements posthog.Logger but does nothing.
func (*SilentLogger) Warnf ¶ added in v1.191.0
func (s *SilentLogger) Warnf(format string, args ...interface{})
Warnf implements posthog.Logger but does nothing.
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, opts Options, 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.