wrapper

package
v3.10.58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package wrapper provides wrapper for Logger

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultClientCallObserver called by wrapper in client Call
	DefaultClientCallObserver = func(ctx context.Context, req client.Request, rsp interface{}, opts []client.CallOption, err error) []string {
		labels := []string{"service", req.Service(), "endpoint", req.Endpoint()}
		if err != nil {
			labels = append(labels, "error", err.Error())
		}
		return labels
	}

	// DefaultClientStreamObserver called by wrapper in client Stream
	DefaultClientStreamObserver = func(ctx context.Context, req client.Request, opts []client.CallOption, stream client.Stream, err error) []string {
		labels := []string{"service", req.Service(), "endpoint", req.Endpoint()}
		if err != nil {
			labels = append(labels, "error", err.Error())
		}
		return labels
	}

	// DefaultClientPublishObserver called by wrapper in client Publish
	DefaultClientPublishObserver = func(ctx context.Context, msg client.Message, opts []client.PublishOption, err error) []string {
		labels := []string{"endpoint", msg.Topic()}
		if err != nil {
			labels = append(labels, "error", err.Error())
		}
		return labels
	}

	// DefaultServerHandlerObserver called by wrapper in server Handler
	DefaultServerHandlerObserver = func(ctx context.Context, req server.Request, rsp interface{}, err error) []string {
		labels := []string{"service", req.Service(), "endpoint", req.Endpoint()}
		if err != nil {
			labels = append(labels, "error", err.Error())
		}
		return labels
	}

	// DefaultServerSubscriberObserver called by wrapper in server Subscriber
	DefaultServerSubscriberObserver = func(ctx context.Context, msg server.Message, err error) []string {
		labels := []string{"endpoint", msg.Topic()}
		if err != nil {
			labels = append(labels, "error", err.Error())
		}
		return labels
	}

	// DefaultClientCallFuncObserver called by wrapper in client CallFunc
	DefaultClientCallFuncObserver = func(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions, err error) []string {
		labels := []string{"service", req.Service(), "endpoint", req.Endpoint()}
		if err != nil {
			labels = append(labels, "error", err.Error())
		}
		return labels
	}

	// DefaultSkipEndpoints wrapper not called for this endpoints
	DefaultSkipEndpoints = []string{"Meter.Metrics", "Health.Live", "Health.Ready", "Health.Version"}
)

Functions

func NewClientCallWrapper

func NewClientCallWrapper(opts ...Option) client.CallWrapper

NewClientCallWrapper accepts an options and returns a Call Wrapper

func NewClientWrapper

func NewClientWrapper(opts ...Option) client.Wrapper

NewClientWrapper accepts an open options and returns a Client Wrapper

func NewServerHandlerWrapper

func NewServerHandlerWrapper(opts ...Option) server.HandlerWrapper

NewServerHandlerWrapper accepts an options and returns a Handler Wrapper

func NewServerSubscriberWrapper

func NewServerSubscriberWrapper(opts ...Option) server.SubscriberWrapper

NewServerSubscriberWrapper accepts an options and returns a Subscriber Wrapper

Types

type ClientCallFuncObserver

type ClientCallFuncObserver func(context.Context, string, client.Request, interface{}, client.CallOptions, error) []string

ClientCallFuncObserver func signature

type ClientCallObserver

type ClientCallObserver func(context.Context, client.Request, interface{}, []client.CallOption, error) []string

ClientCallObserver func signature

type ClientPublishObserver

type ClientPublishObserver func(context.Context, client.Message, []client.PublishOption, error) []string

ClientPublishObserver func signature

type ClientStreamObserver

type ClientStreamObserver func(context.Context, client.Request, []client.CallOption, client.Stream, error) []string

ClientStreamObserver func signature

type Option

type Option func(*Options)

Option func signature

func SkipEndpoints

func SkipEndpoints(eps ...string) Option

SkipEndpoins

func WithClientCallFuncObservers

func WithClientCallFuncObservers(ob ...ClientCallFuncObserver) Option

WithClientCallFuncObservers funcs

func WithClientCallObservers

func WithClientCallObservers(ob ...ClientCallObserver) Option

WithClientCallObservers funcs

func WithClientPublishObservers

func WithClientPublishObservers(ob ...ClientPublishObserver) Option

WithClientPublishObservers funcs

func WithClientStreamObservers

func WithClientStreamObservers(ob ...ClientStreamObserver) Option

WithClientStreamObservers funcs

func WithEnabled

func WithEnabled(b bool) Option

WithEnabled enable/diable flag

func WithLevel

func WithLevel(l logger.Level) Option

WithLevel log level

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger logger

func WithServerHandlerObservers

func WithServerHandlerObservers(ob ...ServerHandlerObserver) Option

WithServerHandlerObservers funcs

func WithServerSubscriberObservers

func WithServerSubscriberObservers(ob ...ServerSubscriberObserver) Option

WithServerSubscriberObservers funcs

type Options

type Options struct {
	// Logger that used for log
	Logger logger.Logger
	// ServerHandlerObservers funcs
	ServerHandlerObservers []ServerHandlerObserver
	// ServerSubscriberObservers funcs
	ServerSubscriberObservers []ServerSubscriberObserver
	// ClientCallObservers funcs
	ClientCallObservers []ClientCallObserver
	// ClientStreamObservers funcs
	ClientStreamObservers []ClientStreamObserver
	// ClientPublishObservers funcs
	ClientPublishObservers []ClientPublishObserver
	// ClientCallFuncObservers funcs
	ClientCallFuncObservers []ClientCallFuncObserver
	// SkipEndpoints
	SkipEndpoints []string
	// Level for logger
	Level logger.Level
	// Enabled flag
	Enabled bool
}

Options struct for wrapper

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions creates Options from Option slice

type ServerHandlerObserver

type ServerHandlerObserver func(context.Context, server.Request, interface{}, error) []string

ServerHandlerObserver func signature

type ServerSubscriberObserver

type ServerSubscriberObserver func(context.Context, server.Message, error) []string

ServerSubscriberObserver func signature

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL