wrapper

package
v3.3.17 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package wrapper provides wrapper for Tracer

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultClientCallObserver = func(ctx context.Context, req client.Request, rsp interface{}, opts []client.CallOption, sp tracer.Span, err error) {
		sp.SetName(fmt.Sprintf("%s.%s", req.Service(), req.Endpoint()))
		var labels []tracer.Label
		if md, ok := metadata.FromOutgoingContext(ctx); ok {
			labels = make([]tracer.Label, 0, len(md))
			for k, v := range md {
				labels = append(labels, tracer.String(k, v))
			}
		}
		if err != nil {
			labels = append(labels, tracer.Bool("error", true))
		}
		sp.SetLabels(labels...)
	}

	DefaultClientStreamObserver = func(ctx context.Context, req client.Request, opts []client.CallOption, stream client.Stream, sp tracer.Span, err error) {
		sp.SetName(fmt.Sprintf("%s.%s", req.Service(), req.Endpoint()))
		var labels []tracer.Label
		if md, ok := metadata.FromOutgoingContext(ctx); ok {
			labels = make([]tracer.Label, 0, len(md))
			for k, v := range md {
				labels = append(labels, tracer.String(k, v))
			}
		}
		if err != nil {
			labels = append(labels, tracer.Bool("error", true))
		}
		sp.SetLabels(labels...)
	}

	DefaultClientPublishObserver = func(ctx context.Context, msg client.Message, opts []client.PublishOption, sp tracer.Span, err error) {
		sp.SetName(fmt.Sprintf("Pub to %s", msg.Topic()))
		var labels []tracer.Label
		if md, ok := metadata.FromOutgoingContext(ctx); ok {
			labels = make([]tracer.Label, 0, len(md))
			for k, v := range md {
				labels = append(labels, tracer.String(k, v))
			}
		}
		if err != nil {
			labels = append(labels, tracer.Bool("error", true))
		}
		sp.SetLabels(labels...)
	}

	DefaultServerHandlerObserver = func(ctx context.Context, req server.Request, rsp interface{}, sp tracer.Span, err error) {
		sp.SetName(fmt.Sprintf("%s.%s", req.Service(), req.Endpoint()))
		var labels []tracer.Label
		if md, ok := metadata.FromIncomingContext(ctx); ok {
			labels = make([]tracer.Label, 0, len(md))
			for k, v := range md {
				labels = append(labels, tracer.String(k, v))
			}
		}
		if err != nil {
			labels = append(labels, tracer.Bool("error", true))
		}
		sp.SetLabels(labels...)
	}

	DefaultServerSubscriberObserver = func(ctx context.Context, msg server.Message, sp tracer.Span, err error) {
		sp.SetName(fmt.Sprintf("Sub from %s", msg.Topic()))
		var labels []tracer.Label
		if md, ok := metadata.FromIncomingContext(ctx); ok {
			labels = make([]tracer.Label, 0, len(md))
			for k, v := range md {
				labels = append(labels, tracer.String(k, v))
			}
		}
		if err != nil {
			labels = append(labels, tracer.Bool("error", true))
		}
		sp.SetLabels(labels...)
	}

	DefaultClientCallFuncObserver = func(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions, sp tracer.Span, err error) {
		sp.SetName(fmt.Sprintf("%s.%s", req.Service(), req.Endpoint()))
		var labels []tracer.Label
		if md, ok := metadata.FromOutgoingContext(ctx); ok {
			labels = make([]tracer.Label, 0, len(md))
			for k, v := range md {
				labels = append(labels, tracer.String(k, v))
			}
		}
		if err != nil {
			labels = append(labels, tracer.Bool("error", true))
		}
		sp.SetLabels(labels...)
	}

	DefaultSkipEndpoints = []string{"Meter.Metrics"}
)

Functions

func NewClientCallWrapper

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

NewClientCallWrapper accepts an opentracing Tracer and returns a Call Wrapper

func NewClientWrapper

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

NewClientWrapper accepts an open tracing Trace 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 opentracing Tracer and returns a Subscriber Wrapper

Types

type ClientCallFuncObserver

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

type ClientCallObserver

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

type ClientPublishObserver

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

type Option

type Option func(*Options)

Option func signature

func SkipEndpoins added in v3.3.3

func SkipEndpoins(eps ...string) Option

SkipEndponts

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 WithServerHandlerObservers

func WithServerHandlerObservers(ob ...ServerHandlerObserver) Option

WithServerHandlerObservers funcs

func WithServerSubscriberObservers

func WithServerSubscriberObservers(ob ...ServerSubscriberObserver) Option

WithServerSubscriberObservers funcs

func WithTracer

func WithTracer(t tracer.Tracer) Option

WithTracer pass tracer

type Options

type Options struct {
	// Tracer that used for tracing
	Tracer tracer.Tracer
	// ClientCallObservers funcs
	ClientCallObservers []ClientCallObserver
	// ClientStreamObservers funcs
	ClientStreamObservers []ClientStreamObserver
	// ClientPublishObservers funcs
	ClientPublishObservers []ClientPublishObserver
	// ClientCallFuncObservers funcs
	ClientCallFuncObservers []ClientCallFuncObserver
	// ServerHandlerObservers funcs
	ServerHandlerObservers []ServerHandlerObserver
	// ServerSubscriberObservers funcs
	ServerSubscriberObservers []ServerSubscriberObserver
	// SkipEndpoints
	SkipEndpoints []string
}

Options struct

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions create Options from Option slice

type ServerHandlerObserver

type ServerHandlerObserver func(context.Context, server.Request, interface{}, tracer.Span, error)

type ServerSubscriberObserver

type ServerSubscriberObserver func(context.Context, server.Message, tracer.Span, error)

Jump to

Keyboard shortcuts

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