Documentation
¶
Overview ¶
Package telemetry provides privacy-safe analytics instrumentation for the CLI.
It centralizes event schema enforcement, event emission, and integration-call instrumentation so command packages can emit telemetry without handling transport and redaction details directly.
Index ¶
- Constants
- Variables
- func ClearActiveCommand()
- func Configure(cfg Config) error
- func IsDefaultBackendConfigured() bool
- func ResetForTesting()
- func SetDefaultBackendConfiguredForTesting(configured bool) func()
- func SetRecorderForTesting(r recorder, build BuildInfo, distinctID string)
- func Shutdown()
- func StatusCodeBucket(statusCode int) string
- func TrackCommandCompleted(ctx CommandContext, completion CommandCompletion)
- func TrackCommandCrashed(ctx CommandContext, crash CommandCrash)
- func TrackCommandError(ctx CommandContext, commandError CommandError)
- func TrackCommandStarted(ctx CommandContext)
- func TrackIntegrationCall(call IntegrationCall)
- func TrackUpdateBannerShown(event UpdateBannerEvent)
- func WrapHTTPTransport(service string, base http.RoundTripper, resolver OperationResolver) http.RoundTripper
- type BuildInfo
- type CommandCompletion
- type CommandContext
- type CommandCrash
- type CommandError
- type Config
- type IntegrationCall
- type OperationResolver
- type UpdateBannerEvent
Constants ¶
const ( // EventCommandStarted is emitted when command execution begins. EventCommandStarted = "fotingo.command.started" // EventCommandCompleted is emitted after command completion with duration/exit code. EventCommandCompleted = "fotingo.command.completed" // EventCommandError is emitted for handled command failures. EventCommandError = "fotingo.command.error" // EventCommandCrashed is emitted when execution recovers from a panic. EventCommandCrashed = "fotingo.command.crashed" // EventIntegrationCall is emitted for instrumented GitHub/Jira HTTP calls. EventIntegrationCall = "fotingo.integration.call" // EventUpdateBannerShown is emitted when the startup update banner is shown. EventUpdateBannerShown = "fotingo.ui.update_banner.shown" )
const (
// EventSchemaVersion tracks the global telemetry schema contract version.
EventSchemaVersion = "1.0.0"
)
Variables ¶
var EventRegistry = map[string]string{
EventCommandStarted: "command",
EventCommandCompleted: "command",
EventCommandError: "command",
EventCommandCrashed: "command",
EventIntegrationCall: "integration",
EventUpdateBannerShown: "ui",
}
EventRegistry defines stable telemetry event names and their owning domains.
Functions ¶
func ClearActiveCommand ¶
func ClearActiveCommand()
ClearActiveCommand clears active command context for integration event correlation.
func IsDefaultBackendConfigured ¶
func IsDefaultBackendConfigured() bool
IsDefaultBackendConfigured reports whether the process default telemetry backend is configured.
func ResetForTesting ¶
func ResetForTesting()
ResetForTesting resets telemetry runtime state for tests.
func SetDefaultBackendConfiguredForTesting ¶
func SetDefaultBackendConfiguredForTesting(configured bool) func()
SetDefaultBackendConfiguredForTesting forces IsDefaultBackendConfigured for tests.
func SetRecorderForTesting ¶
SetRecorderForTesting replaces the telemetry recorder for tests.
func StatusCodeBucket ¶
StatusCodeBucket maps an HTTP status code into a stable bucket label.
func TrackCommandCompleted ¶
func TrackCommandCompleted(ctx CommandContext, completion CommandCompletion)
TrackCommandCompleted emits command-completed telemetry.
func TrackCommandCrashed ¶
func TrackCommandCrashed(ctx CommandContext, crash CommandCrash)
TrackCommandCrashed emits command-crashed telemetry.
func TrackCommandError ¶
func TrackCommandError(ctx CommandContext, commandError CommandError)
TrackCommandError emits command-error telemetry.
func TrackCommandStarted ¶
func TrackCommandStarted(ctx CommandContext)
TrackCommandStarted emits a command-start event and stores active command context.
func TrackIntegrationCall ¶
func TrackIntegrationCall(call IntegrationCall)
TrackIntegrationCall emits normalized external-service call telemetry.
func TrackUpdateBannerShown ¶
func TrackUpdateBannerShown(event UpdateBannerEvent)
TrackUpdateBannerShown emits update-banner impression telemetry.
func WrapHTTPTransport ¶
func WrapHTTPTransport(service string, base http.RoundTripper, resolver OperationResolver) http.RoundTripper
WrapHTTPTransport instruments an HTTP transport and emits integration-call telemetry.
Service packages are responsible for supplying a low-cardinality operation resolver (with allowlisted operations and "other" fallback).
Types ¶
type CommandCompletion ¶
CommandCompletion captures completion outcome data.
type CommandContext ¶
type CommandContext struct {
CommandName string
CommandPath string
CommandSchemaVersion string
Persona string
InvocationMode string
GlobalFlags map[string]bool
HasBranchOverride bool
OptionFlags map[string]bool
OptionCounts map[string]int
OptionEnums map[string]string
}
CommandContext captures safe command metadata.
type CommandCrash ¶
type CommandCrash struct {
Duration time.Duration
ExitCode int
PanicType string
CrashFingerprint string
TopFrame string
}
CommandCrash captures panic/crash telemetry details.
type CommandError ¶
type CommandError struct {
Duration time.Duration
ExitCode int
ErrorFamily string
ErrorFingerprint string
}
CommandError captures error telemetry details.
type Config ¶
type Config struct {
Enabled bool
DistinctID string
BuildInfo BuildInfo
ShutdownTimeout time.Duration
// contains filtered or unexported fields
}
Config controls telemetry runtime initialization.
type IntegrationCall ¶
type IntegrationCall struct {
Service string
Operation string
Duration time.Duration
Success bool
RetryCount int
CacheHit bool
StatusCodeBucket string
}
IntegrationCall captures normalized integration call metrics.
type OperationResolver ¶
OperationResolver maps an outbound HTTP request to a stable logical operation name.