Documentation ¶
Overview ¶
Package sampling provides a handler for sampling records at request level.
It discards records with lower than the minimum level if request is unsampled. For example, if the minimum level is slog.LevelError, it logs records with slog.LevelError and above regardless, but discards records with slog.LevelWarn and below unless the request is sampled.
It's ok to discard records with lower level if everything is fine. However, if a record with slog.LevelError logs, it's better to log records with slog.LevelWarn and below around it so developers could have a context for debugging even the request is not sampled. To achieve this, Handler.WithBuffer should be called at the beginning interceptor of the gRPC/HTTP request.
ctx, cancel := h.WithBuffer(ctx) defer cancel()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithBuffer ¶ added in v0.3.0
WithBuffer enables log buffering for the request associated with the given context. It usually should be called at the beginning interceptor of the gRPC/HTTP request.
Canceling this context releases buffer associated with it, so code should call cancel as soon as the operations running in this [Context] complete:
ctx, cancel := h.WithBuffer(ctx) defer cancel()
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler samples records according to the give sampler.
To create a new Handler, call New.