rkmidtrace

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package rkmidtrace is a middleware for recording tracing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFileExporter

func NewFileExporter(outputPath string, opts ...stdouttrace.Option) sdktrace.SpanExporter

NewFileExporter create a file exporter whose default output is stdout.

func NewJaegerExporter

func NewJaegerExporter(opt jaeger.EndpointOption) sdktrace.SpanExporter

NewJaegerExporter Create jaeger exporter with bellow condition.

1: If no option provided, then export to jaeger agent at localhost:6831 2: Jaeger agent

If no jaeger agent host was provided, then use localhost
If no jaeger agent port was provided, then use 6831

3: Jaeger collector

If no jaeger collector endpoint was provided, then use http://localhost:14268/api/traces

func NewNoopExporter

func NewNoopExporter() sdktrace.SpanExporter

NewNoopExporter create a noop exporter

Types

type AfterCtx

type AfterCtx struct {
	Input struct {
		ResCode    int
		ResMsg     string
		Attributes []attribute.KeyValue
	}
	Output struct{}
}

AfterCtx context for After() function

func NewAfterCtx

func NewAfterCtx() *AfterCtx

NewAfterCtx create new AfterCtx with fields initialized

type BeforeCtx

type BeforeCtx struct {
	Input struct {
		UrlPath    string
		SpanName   string
		IsClient   bool
		Attributes []attribute.KeyValue
		RequestCtx context.Context
		Carrier    propagation.TextMapCarrier
	}
	Output struct {
		NewCtx context.Context
		Span   oteltrace.Span
	}
}

BeforeCtx context for Before() function

func NewBeforeCtx

func NewBeforeCtx() *BeforeCtx

NewBeforeCtx create new BeforeCtx with fields initialized

type BootConfig

type BootConfig struct {
	Enabled  bool     `yaml:"enabled" json:"enabled"`
	Ignore   []string `yaml:"ignore" json:"ignore"`
	Exporter struct {
		File struct {
			Enabled    bool   `yaml:"enabled" json:"enabled"`
			OutputPath string `yaml:"outputPath" json:"outputPath"`
		} `yaml:"file" json:"file"`
		Jaeger struct {
			Agent struct {
				Enabled bool   `yaml:"enabled" json:"enabled"`
				Host    string `yaml:"host" json:"host"`
				Port    int    `yaml:"port" json:"port"`
			} `yaml:"agent" json:"agent"`
			Collector struct {
				Enabled  bool   `yaml:"enabled" json:"enabled"`
				Endpoint string `yaml:"endpoint" json:"endpoint"`
				Username string `yaml:"username" json:"username"`
				Password string `yaml:"password" json:"password"`
			} `yaml:"collector" json:"collector"`
		} `yaml:"jaeger" json:"jaeger"`
	} `yaml:"exporter" json:"exporter"`
}

BootConfig for YAML

type NoopExporter

type NoopExporter struct{}

NoopExporter noop

func (*NoopExporter) ExportSpans

func (nsb *NoopExporter) ExportSpans(context.Context, []sdktrace.ReadOnlySpan) error

ExportSpans handles export of SpanSnapshots by dropping them.

func (*NoopExporter) Shutdown

func (nsb *NoopExporter) Shutdown(context.Context) error

Shutdown stops the exporter by doing nothing.

type Option

type Option func(*optionSet)

Option is used while creating middleware as param

func ToOptions

func ToOptions(config *BootConfig, entryName, entryType string) []Option

ToOptions convert BootConfig into Option list

func WithEntryNameAndType

func WithEntryNameAndType(entryName, entryType string) Option

WithEntryNameAndType provide entry name and entry type.

func WithExporter

func WithExporter(exporter sdktrace.SpanExporter) Option

WithExporter Provide sdktrace.SpanExporter.

func WithMockOptionSet

func WithMockOptionSet(mock OptionSetInterface) Option

WithMockOptionSet provide mock OptionSetInterface

func WithPathToIgnore

func WithPathToIgnore(paths ...string) Option

WithPathToIgnore provide paths prefix that will ignore.

func WithPropagator

func WithPropagator(propagator propagation.TextMapPropagator) Option

WithPropagator provide propagation.TextMapPropagator.

func WithSpanProcessor

func WithSpanProcessor(processor sdktrace.SpanProcessor) Option

WithSpanProcessor provide sdktrace.SpanProcessor.

func WithTracerProvider

func WithTracerProvider(provider *sdktrace.TracerProvider) Option

WithTracerProvider provide *sdktrace.TracerProvider.

type OptionSetInterface

type OptionSetInterface interface {
	GetEntryName() string

	GetEntryType() string

	BeforeCtx(req *http.Request, isClient bool, attrs ...attribute.KeyValue) *BeforeCtx

	Before(*BeforeCtx)

	AfterCtx(resCode int, resMsg string, attrs ...attribute.KeyValue) *AfterCtx

	After(before *BeforeCtx, after *AfterCtx)

	GetTracer() oteltrace.Tracer

	GetProvider() *sdktrace.TracerProvider

	GetPropagator() propagation.TextMapPropagator

	ShouldIgnore(string) bool
}

OptionSetInterface mainly for testing purpose

func NewOptionSet

func NewOptionSet(opts ...Option) OptionSetInterface

NewOptionSet Create new optionSet with options.

func NewOptionSetMock

func NewOptionSetMock(before *BeforeCtx, after *AfterCtx,
	tracer oteltrace.Tracer,
	provider *sdktrace.TracerProvider,
	propagator propagation.TextMapPropagator) OptionSetInterface

NewOptionSetMock for testing purpose

Jump to

Keyboard shortcuts

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