Documentation
¶
Overview ¶
Package errorgap is the Go notifier for the Errorgap error-tracking platform. Use Init to configure the package-level default client and Notify / Flush / Close as the simple, package-level entry points.
For libraries or apps that want isolated state (e.g. tests), instantiate a Client directly with NewClient.
Index ¶
- Constants
- Variables
- func Close(ctx context.Context) error
- func FilterParams(params map[string]any, filterKeys []string) map[string]any
- func Flush(ctx context.Context) error
- func Init(cfg Config) error
- func Recover()
- type Client
- type Config
- type ErrorEntry
- type Frame
- type Notice
- type NoticeOptions
- type Result
Constants ¶
const Version = "0.1.0"
Version is the SDK version, embedded in every notice's User-Agent header.
Variables ¶
var ( // ErrMissingProjectSlug is returned from validation when ProjectSlug // is empty. ErrMissingProjectSlug = errors.New("errorgap: ProjectSlug is required") // ErrMissingEndpoint is returned from validation when Endpoint is // empty. ErrMissingEndpoint = errors.New("errorgap: Endpoint is required") )
var DefaultFilterKeys = []string{
"password",
"password_confirmation",
"token",
"secret",
"api_key",
"authorization",
"cookie",
}
DefaultFilterKeys are matched (case-insensitive substring) against param keys to mask sensitive values before delivery.
Functions ¶
func FilterParams ¶
FilterParams masks sensitive keys (case-insensitive substring match) in a params map. Nested maps are walked; arrays/slices are not recursed into.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client posts notices to an Errorgap server. Safe for concurrent use.
func NewClient ¶
NewClient validates the config, applies defaults, and starts the async delivery goroutine. The caller should defer Close() to flush in-flight deliveries during shutdown.
type Config ¶
type Config struct {
// Endpoint is the base URL of the Errorgap server (no trailing slash).
// Defaults to $ERRORGAP_ENDPOINT or http://127.0.0.1:3030.
Endpoint string
// ProjectSlug is the slug used in the ingestion URL.
// Defaults to $ERRORGAP_PROJECT_SLUG. Required.
ProjectSlug string
// ProjectID is optional and embedded in the notice payload.
// Defaults to $ERRORGAP_PROJECT_ID.
ProjectID string
// APIKey is sent as the x-errorgap-project-key header.
// Defaults to $ERRORGAP_API_KEY.
APIKey string
// Environment labels the deployment ("production", "staging").
// Defaults to $ERRORGAP_ENVIRONMENT or "production".
Environment string
// Release is the application version embedded in the notice context.
Release string
// Async controls fire-and-forget delivery. Defaults to true.
Async bool
// Logger receives SDK warnings. Defaults to slog.Default().
// Set to a no-op handler to silence.
Logger *slog.Logger
// FilterKeys overrides DefaultFilterKeys.
FilterKeys []string
// HTTPClient lets callers plug in a custom transport.
// Defaults to a copy of http.DefaultClient with a 5s timeout.
HTTPClient *http.Client
// Timeout for the default HTTP client. Ignored if HTTPClient is set.
Timeout time.Duration
// QueueSize bounds the in-flight notice channel when Async is true.
// Drops oldest in-flight notice when full. Defaults to 100.
QueueSize int
// CaptureGlobals installs a recover-and-log hook at the entry point.
// (Go doesn't allow process-wide panic handlers; use the middleware
// adapters instead.) Currently unused; reserved for future use.
CaptureGlobals bool
}
Config controls notifier behavior.
type ErrorEntry ¶
type ErrorEntry struct {
Type string `json:"type"`
Message string `json:"message"`
Backtrace []Frame `json:"backtrace"`
}
ErrorEntry is one entry in the notice's errors array.
type Frame ¶
type Frame struct {
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Function string `json:"function,omitempty"`
InApp bool `json:"in_app"`
Index int `json:"index"`
}
Frame is a single backtrace entry in the notice envelope.
type Notice ¶
type Notice struct {
ProjectID string `json:"project_id,omitempty"`
ReceivedAt string `json:"received_at"`
Errors []ErrorEntry `json:"errors"`
Context map[string]any `json:"context"`
Environment map[string]any `json:"environment"`
Session map[string]any `json:"session"`
Params map[string]any `json:"params"`
}
Notice is the wire envelope POSTed to /api/projects/:slug/notices.
type NoticeOptions ¶
type NoticeOptions struct {
Context map[string]any
Environment map[string]any
Session map[string]any
Params map[string]any
// Skip extra runtime.Caller frames when capturing the backtrace.
// Useful when Notify is wrapped by another helper.
BacktraceSkip int
}
NoticeOptions allows callers to add per-notice context.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
testutil
Package testutil hosts test helpers shared across the package.
|
Package testutil hosts test helpers shared across the package. |
|
Package stdhttp provides a net/http middleware that reports panics to Errorgap.
|
Package stdhttp provides a net/http middleware that reports panics to Errorgap. |