Documentation
¶
Overview ¶
Package codeskop is the Codeskop server SDK for Go: errors, panics, incoming requests and outgoing HTTP calls (docs/10 in the backend repo).
codeskop.Init(codeskop.Options{APIKey: os.Getenv("CODESKOP_API_KEY")})
defer codeskop.Close(2 * time.Second)
http.ListenAndServe(":8080", codeskop.Middleware(mux))
Every function is safe to call before Init (it does nothing) and never panics.
Index ¶
- Constants
- func CaptureError(ctx context.Context, err error, tags map[string]string)
- func CaptureMessage(ctx context.Context, message string)
- func Close(timeout time.Duration)
- func Flush(timeout time.Duration) bool
- func Middleware(next http.Handler) http.Handler
- func NormalizePath(path string) string
- func Recover(ctx context.Context)
- func SetFramework(name string)
- func SetUser(ctx context.Context, userID string)
- func TemplateRoute(route string) string
- func Transport(base http.RoundTripper) http.RoundTripper
- func WithUser(ctx context.Context, userID string) context.Context
- type Client
- type Event
- type Options
- type Recorder
- func (rec *Recorder) Error(ctx context.Context, err error, route, mechanism string)
- func (rec *Recorder) Finish(route string, status int, reqBytes, resBytes int64)
- func (rec *Recorder) Panic(ctx context.Context, p any, route, mechanism string)
- func (rec *Recorder) Trust(r *http.Request) (blocked bool)
Constants ¶
const BlockedBody = `{"error":"consumer_blocked"}`
BlockedBody is the JSON body sent to consumers blocked by API Trust.
const Version = "0.1.1"
Version of the SDK.
Variables ¶
This section is empty.
Functions ¶
func CaptureError ¶
CaptureError records an error with the stack of the caller.
func CaptureMessage ¶
CaptureMessage records a message as an issue.
func Middleware ¶
Middleware records every request (by ServeMux pattern on Go 1.23+), reports panics (answering 500) and handles API Trust. Wrap your mux: http.ListenAndServe(":8080", codeskop.Middleware(mux)).
func NormalizePath ¶
NormalizePath applies the server's templating: no query; numeric, UUID and long-hex segments become {id}.
func Recover ¶
Recover reports a panic in the current goroutine and re-panics: `defer codeskop.Recover(ctx)`.
func SetFramework ¶
func SetFramework(name string)
SetFramework names the framework on events (integrations call it).
func SetUser ¶
SetUser attributes the current request's events to userID (inside an integration-wrapped handler).
func TemplateRoute ¶
TemplateRoute turns a router pattern into our {name} form: "GET /users/{id}", "/users/:id", "/files/{path...}".
func Transport ¶
func Transport(base http.RoundTripper) http.RoundTripper
Transport wraps an http.RoundTripper so outgoing calls become api_timing / api_error events: client := &http.Client{Transport: codeskop.Transport(http.DefaultTransport)}.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client holds the queue and sends events in the background.
type Options ¶
type Options struct {
APIKey string
Endpoint string
Environment string
Release string
DisableRequests bool
DisableOutgoing bool
SampleRates map[string]float64
IgnoreRoutes []string
IgnoreErrors []string
BeforeSend func(Event) Event
DisableUserID bool
MaxQueueEvents int
FlushInterval time.Duration
Debug bool
Disabled bool
APITrustResolver func(r *http.Request) string
TrustProxy *bool
}
Options configure the SDK (docs/10 §10.3). Zero values read CODESKOP_* environment variables.
type Recorder ¶
Recorder tracks one incoming request; framework integrations (net/http, Gin, Echo) use it.
func StartRequest ¶
StartRequest begins recording r and returns the recorder plus a context carrying the request's user holder.
Directories
¶
| Path | Synopsis |
|---|---|
|
integrations
|
|
|
echo
Package codeskopecho integrates Codeskop with Echo: e.Use(codeskopecho.Middleware()).
|
Package codeskopecho integrates Codeskop with Echo: e.Use(codeskopecho.Middleware()). |
|
gin
Package codeskopgin integrates Codeskop with Gin: router.Use(codeskopgin.Middleware()).
|
Package codeskopgin integrates Codeskop with Gin: router.Use(codeskopgin.Middleware()). |
|
internal
|
|
|
mockingest
Package mockingest is a mock Codeskop ingest API for tests (docs/10 §10.10).
|
Package mockingest is a mock Codeskop ingest API for tests (docs/10 §10.10). |