Documentation
¶
Overview ¶
Package report turns an app's unexpected errors and panics, on the server and in the browser, into reports grouped by cause, and sends them to an error tracker such as Sentry:
reporter := report.New(report.Options{Sinks: []report.Sink{sentry.New(sentry.Options{})}})
server, err := ternApp(kit.WithReporter(reporter))
kit reports what it would log as an unexpected error: errors that loads, actions and endpoints return that aren't answers (NotFound, Fail, redirects), panics, and, with the client's help, uncaught errors in the browser. Each report has the error, its stack where there is one, the request, the route, the trace and the user, if a hook added one to the logging context (c.LogWith(slog.String("user", id))).
Reports with the same cause share a group: the same error type and message, numbers and IDs aside, at the same route, or for panics, the same place in the code. Each group is sent a few times a minute at most, and counted. Under tern dev, the log view lists the groups.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fingerprint ¶
Fingerprint is a report's group: for a panic, the error and the innermost frames of the app's code; otherwise the type, the normalized message and the route.
func Normalize ¶
Normalize is a message with what changes between occurrences of the same problem taken out: quoted values, UUIDs, hex and numbers.
func SetDefault ¶
func SetDefault(r *Reporter)
SetDefault makes r the reporter for code outside requests, such as jobs.
Types ¶
type Frame ¶
type Frame struct {
Function string `json:"function"`
File string `json:"file"`
Line int `json:"line"`
// InApp is set for the app's own code, not Go's or a dependency's.
InApp bool `json:"inApp,omitempty"`
}
Frame is a place in the code.
type Group ¶
type Group struct {
ID string `json:"id"`
Type string `json:"type"`
Message string `json:"message"`
Route string `json:"route,omitempty"`
Source string `json:"source"`
Count int `json:"count"`
FirstSeen time.Time `json:"firstSeen"`
LastSeen time.Time `json:"lastSeen"`
// Last is the latest report.
Last Report `json:"last"`
// contains filtered or unexported fields
}
Group is a cause and how often it happened.
type Options ¶
type Options struct {
// Sinks get the reports.
Sinks []Sink
// Release names the build, such as a version or commit. The default is
// TERN_RELEASE's, or the VCS revision Go stamped into the binary.
Release string
// Environment is "production", "staging"… The default is TERN_ENV's.
Environment string
// PerMinute is how many reports of one group are sent each minute;
// the rest are counted. The default is 10.
PerMinute int
// Batch says how reports are batched and retried.
Batch batch.Options
}
Options configures a reporter.
type Report ¶
type Report struct {
ID string `json:"id"` // 32 hex digits
Time time.Time `json:"time"`
// Source is "server", "browser" or "job".
Source string `json:"source"`
// Type is the error's Go type, "panic", or the JavaScript error's
// name; Message is its text.
Type string `json:"type"`
Message string `json:"message"`
Panic bool `json:"panic,omitempty"`
Stack []Frame `json:"stack,omitempty"` // innermost first
// Group identifies the cause: reports with the same group are the
// same problem.
Group string `json:"group"`
Method string `json:"method,omitempty"`
URL string `json:"url,omitempty"`
Route string `json:"route,omitempty"`
// UserAgent is the browser's, for browser errors.
UserAgent string `json:"userAgent,omitempty"`
RequestID string `json:"requestId,omitempty"`
TraceID string `json:"traceId,omitempty"`
SpanID string `json:"spanId,omitempty"`
User string `json:"user,omitempty"`
// Attrs are the other attributes of the request's logging context.
Attrs map[string]any `json:"attrs,omitempty"`
Release string `json:"release,omitempty"`
Environment string `json:"environment,omitempty"`
}
Report is one unexpected error.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter groups reports and sends them. Make one with New.
func DevOnly ¶
func DevOnly() *Reporter
DevOnly returns a reporter that only feeds tern dev's log view, or nil outside tern dev. kit uses it when the app has no reporter of its own.
func New ¶
New returns a reporter. Under tern dev, it also sends reports to the dev server's log view.
func (*Reporter) Groups ¶
Groups returns the groups seen since the process started, most recent first.