159 lines
4.6 KiB
Go
159 lines
4.6 KiB
Go
package irontelemetry
|
|
|
|
import "time"
|
|
|
|
// SeverityLevel represents the severity of an event
|
|
type SeverityLevel string
|
|
|
|
const (
|
|
SeverityDebug SeverityLevel = "debug"
|
|
SeverityInfo SeverityLevel = "info"
|
|
SeverityWarning SeverityLevel = "warning"
|
|
SeverityError SeverityLevel = "error"
|
|
SeverityFatal SeverityLevel = "fatal"
|
|
)
|
|
|
|
// BreadcrumbCategory represents the category of a breadcrumb
|
|
type BreadcrumbCategory string
|
|
|
|
const (
|
|
CategoryUI BreadcrumbCategory = "ui"
|
|
CategoryHTTP BreadcrumbCategory = "http"
|
|
CategoryNavigation BreadcrumbCategory = "navigation"
|
|
CategoryConsole BreadcrumbCategory = "console"
|
|
CategoryAuth BreadcrumbCategory = "auth"
|
|
CategoryBusiness BreadcrumbCategory = "business"
|
|
CategoryNotification BreadcrumbCategory = "notification"
|
|
CategoryCustom BreadcrumbCategory = "custom"
|
|
)
|
|
|
|
// Breadcrumb represents an event leading up to an error
|
|
type Breadcrumb struct {
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Category BreadcrumbCategory `json:"category"`
|
|
Message string `json:"message"`
|
|
Level SeverityLevel `json:"level,omitempty"`
|
|
Data map[string]any `json:"data,omitempty"`
|
|
}
|
|
|
|
// User represents user information for context
|
|
type User struct {
|
|
ID string `json:"id"`
|
|
Email string `json:"email,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
Data map[string]any `json:"data,omitempty"`
|
|
}
|
|
|
|
// StackFrame represents a single frame in a stack trace
|
|
type StackFrame struct {
|
|
Function string `json:"function,omitempty"`
|
|
Filename string `json:"filename,omitempty"`
|
|
Lineno int `json:"lineno,omitempty"`
|
|
Colno int `json:"colno,omitempty"`
|
|
Context []string `json:"context,omitempty"`
|
|
}
|
|
|
|
// ExceptionInfo represents exception/error information
|
|
type ExceptionInfo struct {
|
|
Type string `json:"type"`
|
|
Message string `json:"message"`
|
|
Stacktrace []StackFrame `json:"stacktrace,omitempty"`
|
|
}
|
|
|
|
// PlatformInfo represents platform/runtime information
|
|
type PlatformInfo struct {
|
|
Name string `json:"name"`
|
|
Version string `json:"version,omitempty"`
|
|
OS string `json:"os,omitempty"`
|
|
}
|
|
|
|
// JourneyContext represents journey context for tracking user flows
|
|
type JourneyContext struct {
|
|
JourneyID string `json:"journeyId"`
|
|
Name string `json:"name"`
|
|
CurrentStep string `json:"currentStep,omitempty"`
|
|
StartedAt time.Time `json:"startedAt"`
|
|
Metadata map[string]any `json:"metadata"`
|
|
}
|
|
|
|
// TelemetryEvent represents an event payload sent to the server
|
|
type TelemetryEvent struct {
|
|
EventID string `json:"eventId"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Level SeverityLevel `json:"level"`
|
|
Message string `json:"message,omitempty"`
|
|
Exception *ExceptionInfo `json:"exception,omitempty"`
|
|
User *User `json:"user,omitempty"`
|
|
Tags map[string]string `json:"tags"`
|
|
Extra map[string]any `json:"extra"`
|
|
Breadcrumbs []Breadcrumb `json:"breadcrumbs"`
|
|
Journey *JourneyContext `json:"journey,omitempty"`
|
|
Environment string `json:"environment,omitempty"`
|
|
AppVersion string `json:"appVersion,omitempty"`
|
|
Platform PlatformInfo `json:"platform"`
|
|
}
|
|
|
|
// ParsedDSN represents parsed DSN components
|
|
type ParsedDSN struct {
|
|
PublicKey string
|
|
Host string
|
|
Protocol string
|
|
APIBaseURL string
|
|
}
|
|
|
|
// SendResult represents the result of sending an event
|
|
type SendResult struct {
|
|
Success bool
|
|
EventID string
|
|
Error string
|
|
Queued bool
|
|
}
|
|
|
|
// Options represents options for initializing the SDK
|
|
type Options struct {
|
|
// DSN containing the public key
|
|
// Format: https://pk_live_xxx@irontelemetry.com
|
|
DSN string
|
|
|
|
// Environment name (e.g., 'production', 'staging')
|
|
Environment string
|
|
|
|
// Application version
|
|
AppVersion string
|
|
|
|
// Sample rate for events (0.0 to 1.0)
|
|
SampleRate float64
|
|
|
|
// Maximum number of breadcrumbs to keep
|
|
MaxBreadcrumbs int
|
|
|
|
// Enable debug logging
|
|
Debug bool
|
|
|
|
// Hook called before sending an event
|
|
// Return nil to drop the event
|
|
BeforeSend func(*TelemetryEvent) *TelemetryEvent
|
|
|
|
// Enable offline queue for failed events
|
|
EnableOfflineQueue bool
|
|
|
|
// Maximum size of the offline queue
|
|
MaxOfflineQueueSize int
|
|
|
|
// API base URL (defaults to parsed from DSN)
|
|
APIBaseURL string
|
|
}
|
|
|
|
// DefaultOptions returns Options with default values
|
|
func DefaultOptions() Options {
|
|
return Options{
|
|
Environment: "production",
|
|
AppVersion: "0.0.0",
|
|
SampleRate: 1.0,
|
|
MaxBreadcrumbs: 100,
|
|
Debug: false,
|
|
EnableOfflineQueue: true,
|
|
MaxOfflineQueueSize: 500,
|
|
}
|
|
}
|