Documentation
¶
Overview ¶
Package checkend provides error monitoring for Go applications.
Checkend is a lightweight, zero-dependency error monitoring SDK that sends errors to the Checkend service for tracking and analysis.
Basic usage:
import "github.com/Checkend/checkend-go"
func main() {
checkend.Configure(checkend.Config{
APIKey: "your-api-key",
})
defer checkend.Stop()
// Your application code...
if err != nil {
checkend.Notify(err)
}
}
Index ¶
- Constants
- Variables
- func ClearTesting()
- func Flush()
- func Notify(err error, opts ...NotifyOption)
- func NotifyWithContext(ctx context.Context, err error, opts ...NotifyOption)
- func Reset()
- func SetContext(ctx context.Context, data map[string]interface{}) context.Context
- func SetRequest(ctx context.Context, request map[string]interface{}) context.Context
- func SetUser(ctx context.Context, user map[string]interface{}) context.Context
- func SetupTesting()
- func Stop()
- func TeardownTesting()
- func TestingClearNotices()
- func TestingHasNotices() bool
- func TestingNoticeCount() int
- func WithContextData(ctx context.Context, data *ContextData) context.Context
- type APIResponse
- type Client
- type Config
- type Configuration
- type ContextData
- type ErrorPayload
- type IgnoreFilter
- type Notice
- type NoticeBuilder
- type NotifierInfo
- type NotifyOption
- type Payload
- type SanitizeFilter
- type ServerInfo
- type Worker
Constants ¶
const DefaultConnectTimeout = 5 * time.Second
DefaultConnectTimeout is the default connection establishment timeout.
const DefaultEndpoint = "https://app.checkend.io"
DefaultEndpoint is the default Checkend API endpoint.
const DefaultMaxQueueSize = 1000
DefaultMaxQueueSize is the default maximum queue size for async sending.
const DefaultShutdownTimeout = 5 * time.Second
DefaultShutdownTimeout is the default graceful shutdown timeout.
const DefaultTimeout = 15 * time.Second
DefaultTimeout is the default HTTP request timeout.
const Version = "0.1.0"
Version is the SDK version.
Variables ¶
var DefaultFilterKeys = []string{
"password",
"password_confirmation",
"secret",
"secret_key",
"api_key",
"apikey",
"access_token",
"auth_token",
"authorization",
"token",
"credit_card",
"card_number",
"cvv",
"cvc",
"ssn",
"social_security",
}
DefaultFilterKeys are the default keys to filter from payloads.
Functions ¶
func Notify ¶
func Notify(err error, opts ...NotifyOption)
Notify sends an error to Checkend asynchronously.
func NotifyWithContext ¶
func NotifyWithContext(ctx context.Context, err error, opts ...NotifyOption)
NotifyWithContext sends an error to Checkend asynchronously with context.
func SetContext ¶
SetContext adds context data to the given context.
func SetRequest ¶
SetRequest sets request information in the given context.
func TestingClearNotices ¶
func TestingClearNotices()
TestingClearNotices clears all captured notices.
func TestingHasNotices ¶
func TestingHasNotices() bool
TestingHasNotices returns true if any notices have been captured.
func TestingNoticeCount ¶
func TestingNoticeCount() int
TestingNoticeCount returns the number of captured notices.
func WithContextData ¶
func WithContextData(ctx context.Context, data *ContextData) context.Context
WithContextData returns a new context with Checkend data.
Types ¶
type APIResponse ¶
APIResponse represents the response from the Checkend API.
func NotifySync ¶
func NotifySync(err error, opts ...NotifyOption) *APIResponse
NotifySync sends an error to Checkend synchronously and returns the response.
func NotifySyncWithContext ¶
func NotifySyncWithContext(ctx context.Context, err error, opts ...NotifyOption) *APIResponse
NotifySyncWithContext sends an error to Checkend synchronously with context.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the HTTP client for the Checkend API.
func (*Client) Send ¶
func (c *Client) Send(notice *Notice) *APIResponse
Send sends a notice to Checkend.
type Config ¶
type Config struct {
// APIKey is your Checkend ingestion API key (required).
APIKey string
// Endpoint is the API endpoint URL.
Endpoint string
// Environment is the environment name (e.g., "production", "staging").
Environment string
// Enabled controls whether error reporting is active.
Enabled *bool
// AsyncSend controls whether errors are sent asynchronously.
AsyncSend bool
// MaxQueueSize is the maximum queue size for async sending.
MaxQueueSize int
// Timeout is the HTTP request timeout.
Timeout time.Duration
// ConnectTimeout is the connection establishment timeout.
ConnectTimeout time.Duration
// ShutdownTimeout is the graceful shutdown timeout.
ShutdownTimeout time.Duration
// FilterKeys are additional keys to filter from payloads.
FilterKeys []string
// IgnoredErrors are error types or patterns to ignore.
IgnoredErrors []interface{}
// BeforeNotify are callbacks to run before sending a notice.
// Return false to skip sending.
BeforeNotify []func(*Notice) bool
// Debug enables debug logging.
Debug bool
// AppName is the application identifier.
AppName string
// Revision is the code revision or commit hash.
Revision string
// RootPath is the application root path for cleaning backtraces.
RootPath string
// SendRequestData controls whether request data is included in notices.
SendRequestData *bool
// SendSessionData controls whether session data is included in notices.
SendSessionData *bool
// SendEnvironment controls whether environment variables are included in notices.
SendEnvironment *bool
// SendUserData controls whether user data is included in notices.
SendUserData *bool
// Proxy is the HTTP proxy URL.
Proxy string
// SSLVerify controls TLS certificate verification.
SSLVerify *bool
}
Config holds the configuration options for Checkend.
type Configuration ¶
type Configuration struct {
APIKey string
Endpoint string
Environment string
Enabled bool
AsyncSend bool
MaxQueueSize int
Timeout time.Duration
ConnectTimeout time.Duration
ShutdownTimeout time.Duration
FilterKeys []string
IgnoredErrors []interface{}
BeforeNotify []func(*Notice) bool
Debug bool
AppName string
Revision string
RootPath string
SendRequestData bool
SendSessionData bool
SendEnvironment bool
SendUserData bool
Proxy string
SSLVerify bool
}
Configuration is the resolved configuration for the SDK.
func Configure ¶
func Configure(cfg Config) *Configuration
Configure initializes the Checkend SDK with the given configuration.
func GetConfiguration ¶
func GetConfiguration() *Configuration
GetConfiguration returns the current configuration.
func NewConfiguration ¶
func NewConfiguration(cfg Config) *Configuration
NewConfiguration creates a new Configuration from Config.
type ContextData ¶
type ContextData struct {
Context map[string]interface{}
User map[string]interface{}
Request map[string]interface{}
}
ContextData holds request-scoped Checkend data.
func GetContextData ¶
func GetContextData(ctx context.Context) *ContextData
GetContextData retrieves Checkend data from the context.
type ErrorPayload ¶
type ErrorPayload struct {
Class string `json:"class"`
Message string `json:"message"`
Backtrace []string `json:"backtrace"`
Fingerprint string `json:"fingerprint,omitempty"`
Tags []string `json:"tags,omitempty"`
OccurredAt string `json:"occurred_at"`
}
ErrorPayload represents the error portion of the payload.
type IgnoreFilter ¶
type IgnoreFilter = filters.IgnoreFilter
IgnoreFilter wraps the filters package IgnoreFilter for internal use.
func NewIgnoreFilter ¶
func NewIgnoreFilter(patterns []interface{}) *IgnoreFilter
NewIgnoreFilter creates a new IgnoreFilter.
type Notice ¶
type Notice struct {
ErrorClass string `json:"error_class"`
Message string `json:"message"`
Backtrace []string `json:"backtrace"`
Fingerprint string `json:"fingerprint,omitempty"`
Tags []string `json:"tags,omitempty"`
Context map[string]interface{} `json:"context,omitempty"`
Request map[string]interface{} `json:"request,omitempty"`
User map[string]interface{} `json:"user,omitempty"`
Environment string `json:"environment"`
OccurredAt time.Time `json:"occurred_at"`
Notifier NotifierInfo `json:"notifier"`
AppName string `json:"app_name,omitempty"`
Revision string `json:"revision,omitempty"`
Hostname string `json:"hostname,omitempty"`
}
Notice represents an error notice to be sent to Checkend.
func TestingFirstNotice ¶
func TestingFirstNotice() *Notice
TestingFirstNotice returns the first captured notice.
func TestingLastNotice ¶
func TestingLastNotice() *Notice
TestingLastNotice returns the last captured notice.
type NoticeBuilder ¶
type NoticeBuilder struct {
// contains filtered or unexported fields
}
NoticeBuilder builds Notice objects from errors.
func NewNoticeBuilder ¶
func NewNoticeBuilder(config *Configuration) *NoticeBuilder
NewNoticeBuilder creates a new NoticeBuilder.
type NotifierInfo ¶
type NotifierInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Language string `json:"language"`
LanguageVersion string `json:"language_version"`
}
NotifierInfo contains SDK metadata.
type NotifyOption ¶
type NotifyOption func(*notifyOptions)
NotifyOption is a functional option for Notify.
func WithContext ¶
func WithContext(ctx map[string]interface{}) NotifyOption
WithContext sets additional context data.
func WithFingerprint ¶
func WithFingerprint(fingerprint string) NotifyOption
WithFingerprint sets a custom fingerprint for error grouping.
func WithRequest ¶
func WithRequest(request map[string]interface{}) NotifyOption
WithRequest sets request information.
func WithUser ¶
func WithUser(user map[string]interface{}) NotifyOption
WithUser sets user information.
type Payload ¶
type Payload struct {
Error ErrorPayload `json:"error"`
Context map[string]interface{} `json:"context"`
Request map[string]interface{} `json:"request,omitempty"`
User map[string]interface{} `json:"user,omitempty"`
Notifier NotifierInfo `json:"notifier"`
Server *ServerInfo `json:"server,omitempty"`
}
Payload represents the API request payload.
type SanitizeFilter ¶
type SanitizeFilter = filters.SanitizeFilter
SanitizeFilter wraps the filters package SanitizeFilter for internal use.
func NewSanitizeFilter ¶
func NewSanitizeFilter(filterKeys []string) *SanitizeFilter
NewSanitizeFilter creates a new SanitizeFilter.
type ServerInfo ¶
type ServerInfo struct {
AppName string `json:"app_name,omitempty"`
Revision string `json:"revision,omitempty"`
Hostname string `json:"hostname,omitempty"`
}
ServerInfo contains server/application metadata.