Documentation
¶
Index ¶
- Constants
- Variables
- func CountryFromContext(ctx context.Context) string
- func DebugIDFromContext(ctx context.Context) uint64
- func IPFromContext(ctx context.Context) string
- func IsDevelFromContext(ctx context.Context) bool
- func MethodFromContext(ctx context.Context) string
- func NewCountryContext(ctx context.Context, country string) context.Context
- func NewDebugIDContext(ctx context.Context, debugID uint64) context.Context
- func NewIPContext(ctx context.Context, ip string) context.Context
- func NewIsDevelContext(ctx context.Context, isDevel bool) context.Context
- func NewMethodContext(ctx context.Context, method string) context.Context
- func NewNotificationContext(ctx context.Context) context.Context
- func NewPlatformContext(ctx context.Context, platform string) context.Context
- func NewSQLGroupContext(ctx context.Context, group string) context.Context
- func NewSQLQueryLogger() *sqlQueryLogger
- func NewUserAgentContext(ctx context.Context, ua string) context.Context
- func NewVersionContext(ctx context.Context, version string) context.Context
- func NewXRequestIDContext(ctx context.Context, requestID string) context.Context
- func NotificationFromContext(ctx context.Context) bool
- func PlatformFromContext(ctx context.Context) string
- func SQLGroupFromContext(ctx context.Context) string
- func UserAgentFromContext(ctx context.Context) string
- func VersionFromContext(ctx context.Context) string
- func WithAPILogger(pf Printf, serverName string) zenrpc.MiddlewareFunc
- func WithDevel(isDevel bool) zenrpc.MiddlewareFunc
- func WithErrorLogger(pf Printf, serverName string) zenrpc.MiddlewareFunc
- func WithErrorSLog(pf Print, serverName string, fn LogAttrs) zenrpc.MiddlewareFunc
- func WithHeaders() zenrpc.MiddlewareFunc
- func WithMetrics(serverName string) zenrpc.MiddlewareFunc
- func WithNoCancelContext() zenrpc.MiddlewareFunc
- func WithSLog(pf Print, serverName string, fn LogAttrs) zenrpc.MiddlewareFunc
- func WithSQLLogger(db *pg.DB, isDevel bool, allowDebugFunc, allowSQLDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc
- func WithSentry(serverName string) zenrpc.MiddlewareFunc
- func WithTiming(isDevel bool, allowDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc
- func XRequestIDFromContext(ctx context.Context) string
- type AllowDebugFunc
- type Duration
- type LogAttrs
- type Print
- type Printf
Constants ¶
const (
// DefaultServerName is a global default name, mostly used for metrics.
DefaultServerName = ""
)
Variables ¶
var ErrSkipLog = errors.New("skip log")
ErrSkipLog is a special error for LogAttrs func. Log lines can be skipped.
Functions ¶
func CountryFromContext ¶ added in v1.1.6
CountryFromContext returns country from context. Deprecated: use appkit.CountryFromContext.
func DebugIDFromContext ¶ added in v1.1.1
DebugIDFromContext returns debug id from context. Deprecated: use appkit.DebugIDFromContext.
func IPFromContext ¶
IPFromContext returns IP from context. Deprecated: use appkit.IPFromContext.
func IsDevelFromContext ¶
IsDevelFromContext returns isDevel flag from context. Deprecated: use appkit.IsDevelFromContext.
func MethodFromContext ¶ added in v1.2.0
MethodFromContext returns Method from context. Deprecated: use appkit.MethodFromContext.
func NewCountryContext ¶ added in v1.1.6
NewCountryContext creates new context with country. Deprecated: use appkit.NewCountryContext.
func NewDebugIDContext ¶ added in v1.1.1
NewDebugIDContext creates new context with debug ID. Deprecated: use appkit.NewDebugIDContext.
func NewIPContext ¶
NewIPContext creates new context with IP. Deprecated: use appkit.NewIPContext.
func NewIsDevelContext ¶ added in v1.1.1
NewIsDevelContext creates new context with isDevel flag. Deprecated: use appkit.NewIsDevelContext.
func NewMethodContext ¶ added in v1.2.0
NewMethodContext creates new context with Method. Deprecated: use appkit.NewMethodContext.
func NewNotificationContext ¶ added in v1.1.4
NewNotificationContext creates new context with JSONRPC2 notification flag. Deprecated: use appkit.NewNotificationContext.
func NewPlatformContext ¶ added in v1.1.0
NewPlatformContext creates new context with platform. Deprecated: use appkit.NewPlatformContext.
func NewSQLGroupContext ¶ added in v1.2.0
NewSQLGroupContext creates new context with SQL Group for debug SQL logging. Deprecated: use appkit.NewSQLGroupContext.
func NewSQLQueryLogger ¶ added in v1.2.0
func NewSQLQueryLogger() *sqlQueryLogger
func NewUserAgentContext ¶ added in v1.1.0
NewUserAgentContext creates new context with User-Agent. Deprecated: use appkit.NewUserAgentContext.
func NewVersionContext ¶ added in v1.1.0
NewVersionContext creates new context with version. Deprecated: use appkit.NewVersionContext.
func NewXRequestIDContext ¶ added in v1.1.0
NewXRequestIDContext creates new context with X-Request-ID. Deprecated: use appkit.NewXRequestIDContext.
func NotificationFromContext ¶ added in v1.1.4
NotificationFromContext returns JSONRPC2 notification flag from context. Deprecated: use appkit.NotificationFromContext.
func PlatformFromContext ¶
PlatformFromContext returns platform from context. Deprecated: use appkit.PlatformFromContext.
func SQLGroupFromContext ¶ added in v1.2.0
SQLGroupFromContext returns sql group from context. Deprecated: use appkit.SQLGroupFromContext.
func UserAgentFromContext ¶
UserAgentFromContext returns userAgent from context. Deprecated: use appkit.UserAgentFromContext.
func VersionFromContext ¶
VersionFromContext returns version from context. Deprecated: use appkit.VersionFromContext.
func WithAPILogger ¶
func WithAPILogger(pf Printf, serverName string) zenrpc.MiddlewareFunc
WithAPILogger logs via Printf function (e.g. log.Printf) all requests.
func WithDevel ¶
func WithDevel(isDevel bool) zenrpc.MiddlewareFunc
WithDevel sets bool flag to context for detecting development environment.
func WithErrorLogger ¶
func WithErrorLogger(pf Printf, serverName string) zenrpc.MiddlewareFunc
WithErrorLogger logs all errors (ErrorCode==500 or < 0) via Printf func and sends them to Sentry. It also removes sensitive error data from response. It is good to use pkg/errors for stack trace support in sentry.
func WithErrorSLog ¶ added in v1.2.0
func WithErrorSLog(pf Print, serverName string, fn LogAttrs) zenrpc.MiddlewareFunc
WithErrorSLog logs all errors (ErrorCode==500 or < 0) via [slog.ErrorContext] func and sends them to Sentry. It also removes sensitive error data from response. It is good to use pkg/errors for stack trace support in sentry.
func WithHeaders ¶
func WithHeaders() zenrpc.MiddlewareFunc
WithHeaders sets User-Agent, Platform, Version, X-Country headers to context. User-Agent strips to 2048 chars, Platform and Version – to 64, X-Country - to 16.
func WithMetrics ¶
func WithMetrics(serverName string) zenrpc.MiddlewareFunc
WithMetrics logs duration of RPC requests via Prometheus. Default serverName is rpc will be in server label. It exposes two metrics: `app_rpc_error_requests_total` and `app_rpc_responses_duration_seconds`. Labels: method, code, platform, version, server.
func WithNoCancelContext ¶
func WithNoCancelContext() zenrpc.MiddlewareFunc
WithNoCancelContext ignores Cancel func from context. This is useful for passing context to `go-pg`.
func WithSLog ¶ added in v1.2.0
func WithSLog(pf Print, serverName string, fn LogAttrs) zenrpc.MiddlewareFunc
WithSLog logs via slog function (e.g. slog.InfoContext) all requests.
func WithSQLLogger ¶
func WithSQLLogger(db *pg.DB, isDevel bool, allowDebugFunc, allowSQLDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc
WithSQLLogger adds `SQL` or `DurationSQL` fields in JSON-RPC 2.0 Response `extensions` field (not in spec). `DurationSQL` field is set then `isDevel=true` or AllowDebugFunc(allowDebugFunc) returns `true` and http request is set. `SQL` field is set then `isDevel=true` or AllowDebugFunc(allowDebugFunc, allowSQLDebugFunc) returns `true` and http request is set.
func WithSentry ¶
func WithSentry(serverName string) zenrpc.MiddlewareFunc
WithSentry sets additional parameters for current Sentry scope. Extras: params, duration, ip. Tags: platform, version, method. It's also handles panic.
func WithTiming ¶
func WithTiming(isDevel bool, allowDebugFunc AllowDebugFunc) zenrpc.MiddlewareFunc
WithTiming adds timings in JSON-RPC 2.0 Response via `extensions` field (not in spec). Middleware is active when `isDevel=true` or AllowDebugFunc returns `true` and http request is set. `DurationLocal` – total method execution time in ms. If `DurationRemote` or `DurationDiff` are set then `DurationLocal` excludes these values.
func XRequestIDFromContext ¶ added in v1.1.0
XRequestIDFromContext returns X-Request-ID from context. Deprecated: use appkit.XRequestIDFromContext.