Documentation
¶
Index ¶
- Variables
- func AddCustomAttributes(c *gin.Context, attrs ...slog.Attr)
- func AddSpanAttribute(c *gin.Context, key, value string)
- func AddSpanAttributes(c *gin.Context, attrs map[string]string)
- func AddSpanEvent(c *gin.Context, name string, attrs map[string]string)
- func CustomTracingMiddleware(tm *libTracing.TracingManager) gin.HandlerFunc
- func GetRequestID(c *gin.Context) string
- func GetSpanFromContext(c *gin.Context) trace.Span
- func Gin(handler any) gin.HandlerFunc
- func New(logger *slog.Logger) gin.HandlerFunc
- func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc
- func RecordSpanError(c *gin.Context, err error, attrs map[string]string)
- func TracingMiddleware() gin.HandlerFunc
- type Config
- type Filter
- func Accept(filter Filter) Filter
- func AcceptHost(hosts ...string) Filter
- func AcceptHostContains(parts ...string) Filter
- func AcceptHostMatch(regs ...regexp.Regexp) Filter
- func AcceptHostPrefix(prefixs ...string) Filter
- func AcceptHostSuffix(prefixs ...string) Filter
- func AcceptMethod(methods ...string) Filter
- func AcceptPath(urls ...string) Filter
- func AcceptPathContains(parts ...string) Filter
- func AcceptPathMatch(regs ...regexp.Regexp) Filter
- func AcceptPathPrefix(prefixs ...string) Filter
- func AcceptPathSuffix(prefixs ...string) Filter
- func AcceptStatus(statuses ...int) Filter
- func AcceptStatusGreaterThan(status int) Filter
- func AcceptStatusGreaterThanOrEqual(status int) Filter
- func AcceptStatusLessThan(status int) Filter
- func AcceptStatusLessThanOrEqual(status int) Filter
- func Ignore(filter Filter) Filter
- func IgnoreHost(hosts ...string) Filter
- func IgnoreHostContains(parts ...string) Filter
- func IgnoreHostMatch(regs ...regexp.Regexp) Filter
- func IgnoreHostPrefix(prefixs ...string) Filter
- func IgnoreHostSuffix(suffixs ...string) Filter
- func IgnoreMethod(methods ...string) Filter
- func IgnorePath(urls ...string) Filter
- func IgnorePathContains(parts ...string) Filter
- func IgnorePathMatch(regs ...regexp.Regexp) Filter
- func IgnorePathPrefix(prefixs ...string) Filter
- func IgnorePathSuffix(suffixs ...string) Filter
- func IgnoreStatus(statuses ...int) Filter
- func IgnoreStatusGreaterThan(status int) Filter
- func IgnoreStatusGreaterThanOrEqual(status int) Filter
- func IgnoreStatusLessThan(status int) Filter
- func IgnoreStatusLessThanOrEqual(status int) Filter
- type GinParser
- func (c GinParser) Abort() error
- func (c GinParser) AddCustomAttributes(attr slog.Attr)
- func (c GinParser) AddSpanAttribute(key, value string)
- func (c GinParser) AddSpanAttributes(attrs map[string]string)
- func (c GinParser) AddSpanEvent(name string, attrs map[string]string)
- func (c GinParser) CheckUrlParam(name string) (string, bool)
- func (c GinParser) FileAttachment(path, fileName string)
- func (c GinParser) FormValue(name string) string
- func (c GinParser) GetArgs(args ...any) map[string]string
- func (c GinParser) GetBody(target any) error
- func (c GinParser) GetContext() context.Context
- func (c GinParser) GetHeader(target webFramework.HeaderInterface) error
- func (c GinParser) GetHeaderValue(name string) string
- func (c GinParser) GetHttpHeader() http.Header
- func (c GinParser) GetLocal(name string) any
- func (c GinParser) GetLocalString(name string) string
- func (c GinParser) GetMethod() string
- func (c GinParser) GetPath() string
- func (c GinParser) GetRawUrlQuery() string
- func (c GinParser) GetTraceContext() trace.SpanContext
- func (c GinParser) GetUri(target any) error
- func (c GinParser) GetUrlParam(name string) string
- func (c GinParser) GetUrlParams() map[string]string
- func (c GinParser) GetUrlQuery(target any) error
- func (c GinParser) Next() error
- func (c GinParser) ParseCommand(command, title string, request webFramework.RecordData, ...) string
- func (c GinParser) RecordSpanError(err error, attrs map[string]string)
- func (c GinParser) SaveFile(formTagName, path string) error
- func (c GinParser) SendJSONRespBody(status int, resp any) error
- func (c GinParser) SetContext(ctx context.Context)
- func (c GinParser) SetLocal(name string, value any)
- func (c GinParser) SetReqHeader(name string, value string)
- func (c GinParser) SetRespHeader(name string, value string)
- func (c GinParser) SetTraceContext(spanCtx trace.SpanContext)
- func (c GinParser) StartSpan(name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
Constants ¶
This section is empty.
Variables ¶
var ( TraceIDKey = "trace_id" SpanIDKey = "span_id" RequestIDKey = "id" RequestBodyMaxSize = 64 * 1024 // 64KB ResponseBodyMaxSize = 64 * 1024 // 64KB HiddenRequestHeaders = map[string]struct{}{ "authorization": {}, "cookie": {}, "set-cookie": {}, "x-auth-token": {}, "x-csrf-token": {}, "x-xsrf-token": {}, } HiddenResponseHeaders = map[string]struct{}{ "set-cookie": {}, } // Formatted with http.CanonicalHeaderKey RequestIDHeaderKey = "X-Request-Id" RequestIDContextKey = "slog-gin.request-id" )
Functions ¶
func AddCustomAttributes ¶ added in v0.22.2
AddCustomAttributes adds custom attributes to the request context.
func AddSpanAttribute ¶ added in v0.18.0
AddSpanAttribute adds an attribute to the current span in Gin context
func AddSpanAttributes ¶ added in v0.18.0
AddSpanAttributes adds multiple attributes to the current span
func AddSpanEvent ¶ added in v0.18.0
AddSpanEvent adds an event to the current span
func CustomTracingMiddleware ¶ added in v0.18.0
func CustomTracingMiddleware(tm *libTracing.TracingManager) gin.HandlerFunc
CustomTracingMiddleware creates a custom Gin middleware with more control
func GetRequestID ¶ added in v0.22.2
GetRequestID returns the request identifier.
func GetSpanFromContext ¶ added in v0.18.0
GetSpanFromContext gets the span from Gin context
func Gin ¶
func Gin(handler any) gin.HandlerFunc
func New ¶ added in v0.22.2
func New(logger *slog.Logger) gin.HandlerFunc
New returns a gin.HandlerFunc (middleware) that logs requests using slog.
Requests with errors are logged using slog.Error(). Requests without errors are logged using slog.Info().
func NewWithConfig ¶ added in v0.22.2
func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc
NewWithConfig returns a gin.HandlerFunc (middleware) that logs requests using slog.
func RecordSpanError ¶ added in v0.18.0
RecordSpanError records an error in the current span
func TracingMiddleware ¶ added in v0.18.0
func TracingMiddleware() gin.HandlerFunc
TracingMiddleware creates Gin middleware for OpenTelemetry tracing
Types ¶
type Config ¶ added in v0.22.2
type Config struct {
DefaultLevel slog.Level
ClientErrorLevel slog.Level
ServerErrorLevel slog.Level
WithUserAgent bool
WithRequestID bool
WithRequestBody bool
WithRequestHeader bool
WithResponseBody bool
WithResponseHeader bool
WithSpanID bool
WithTraceID bool
WithClientIP bool
HandleGinDebug bool
Filters []Filter
}
type Filter ¶ added in v0.22.2
func AcceptHostContains ¶ added in v0.22.2
func AcceptHostMatch ¶ added in v0.22.2
func AcceptHostPrefix ¶ added in v0.22.2
func AcceptHostSuffix ¶ added in v0.22.2
func AcceptPathContains ¶ added in v0.22.2
func AcceptPathMatch ¶ added in v0.22.2
func AcceptPathPrefix ¶ added in v0.22.2
func AcceptPathSuffix ¶ added in v0.22.2
func AcceptStatusGreaterThan ¶ added in v0.22.2
func AcceptStatusGreaterThanOrEqual ¶ added in v0.22.2
func AcceptStatusLessThan ¶ added in v0.22.2
func AcceptStatusLessThanOrEqual ¶ added in v0.22.2
func IgnoreHost ¶ added in v0.22.2
func IgnoreHostContains ¶ added in v0.22.2
func IgnoreHostMatch ¶ added in v0.22.2
func IgnoreHostPrefix ¶ added in v0.22.2
func IgnoreHostSuffix ¶ added in v0.22.2
func IgnoreMethod ¶ added in v0.22.2
func IgnorePath ¶ added in v0.22.2
func IgnorePathContains ¶ added in v0.22.2
func IgnorePathMatch ¶ added in v0.22.2
func IgnorePathPrefix ¶ added in v0.22.2
func IgnorePathSuffix ¶ added in v0.22.2
func IgnoreStatus ¶ added in v0.22.2
func IgnoreStatusGreaterThan ¶ added in v0.22.2
func IgnoreStatusGreaterThanOrEqual ¶ added in v0.22.2
func IgnoreStatusLessThan ¶ added in v0.22.2
func IgnoreStatusLessThanOrEqual ¶ added in v0.22.2
type GinParser ¶
func InitContext ¶
func (GinParser) AddCustomAttributes ¶ added in v0.13.2
func (GinParser) AddSpanAttribute ¶ added in v0.18.0
func (GinParser) AddSpanAttributes ¶ added in v0.18.0
func (GinParser) AddSpanEvent ¶ added in v0.18.0
func (GinParser) FileAttachment ¶ added in v0.10.4
func (GinParser) GetContext ¶ added in v0.22.0
GetContext returns the context from the Gin request
func (GinParser) GetHeader ¶
func (c GinParser) GetHeader(target webFramework.HeaderInterface) error
func (GinParser) GetHeaderValue ¶
func (GinParser) GetHttpHeader ¶
func (GinParser) GetLocalString ¶
func (GinParser) GetRawUrlQuery ¶
func (GinParser) GetTraceContext ¶ added in v0.18.0
func (c GinParser) GetTraceContext() trace.SpanContext
Tracing methods for GinParser
func (GinParser) GetUrlParam ¶
func (GinParser) GetUrlParams ¶
func (GinParser) GetUrlQuery ¶
func (GinParser) ParseCommand ¶
func (c GinParser) ParseCommand(command, title string, request webFramework.RecordData, parser webFramework.FieldParser) string
func (GinParser) RecordSpanError ¶ added in v0.18.0
func (GinParser) SendJSONRespBody ¶ added in v0.7.0
func (GinParser) SetContext ¶ added in v0.22.0
SetContext updates the context in the Gin request
func (GinParser) SetReqHeader ¶ added in v0.7.5
func (GinParser) SetRespHeader ¶ added in v0.10.28
func (GinParser) SetTraceContext ¶ added in v0.18.0
func (c GinParser) SetTraceContext(spanCtx trace.SpanContext)