Go API Documentation

github.com/TykTechnologies/tyk/trace/openzipkin

No package summary is available.

Package

Files: 2. Third party imports: 7. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

const Name = "zipkin"

Vars

var _ opentracing.Tracer = (*zipkinTracer)(nil)
var emptyContext spanContext

Types

Span

This type doesn't have documentation.

Field name Field type Comment
span

zipkin.Span

No comment on field.
tr

*zipkinTracer

No comment on field.
type Span struct {
	span	zipkin.Span
	tr	*zipkinTracer
}

Tracer

This type doesn't have documentation.

Field name Field type Comment

opentracing.Tracer

No comment on field.

reporter.Reporter

No comment on field.
type Tracer struct {
	opentracing.Tracer
	reporter.Reporter
}

extractor

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.
type extractor interface {
	extract(carrier interface{}) (spanContext, error)
}

extractorFn

This type doesn't have documentation.

Field name Field type Comment
type

func(carrier interface{}) (spanContext, error)

No comment on field.
type extractorFn func(carrier interface{}) (spanContext, error)

injector

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.
type injector interface {
	inject(ctx spanContext, carrier interface{}) error
}

injectorFn

This type doesn't have documentation.

Field name Field type Comment
type

func(ctx spanContext, carrier interface{}) error

No comment on field.
type injectorFn func(ctx spanContext, carrier interface{}) error

logEncoder

This type doesn't have documentation.

Field name Field type Comment
h

func(string, interface{})

No comment on field.
type logEncoder struct {
	h func(string, interface{})
}

spanContext

This type doesn't have documentation.

Field name Field type Comment

model.SpanContext

No comment on field.
type spanContext struct {
	model.SpanContext
}

zipkinTracer

This type doesn't have documentation.

Field name Field type Comment
zip

*zipkin.Tracer

No comment on field.
extractors

map[any]extractor

No comment on field.
injectors

map[any]injector

No comment on field.
type zipkinTracer struct {
	zip		*zipkin.Tracer
	extractors	map[interface{}]extractor
	injectors	map[interface{}]injector
}

Functions

func Init

func Init(service string, opts map[string]interface{}) (*Tracer, error) {
	c, err := Load(opts)
	if err != nil {
		return nil, err
	}
	if c.Reporter.URL == "" {
		return nil, errors.New("zipkin: missing url")
	}
	r := http.NewReporter(c.Reporter.URL)
	endpoint, err := zipkin.NewEndpoint(service, "")
	if err != nil {
		return nil, err
	}
	sampler, err := getSampler(c.Sampler)
	if err != nil {
		return nil, err
	}
	tr, err := zipkin.NewTracer(r,
		zipkin.WithLocalEndpoint(endpoint),
		zipkin.WithSampler(sampler),
	)
	if err != nil {
		return nil, err
	}
	return &Tracer{Tracer: NewTracer(tr), Reporter: r}, nil
}

Cognitive complexity: 12, Cyclomatic complexity: 6

Uses: errors.New, http.NewReporter, zipkin.NewEndpoint, zipkin.NewTracer, zipkin.WithLocalEndpoint, zipkin.WithSampler.

func Load

Load retusn a zipkin configuration from the opts.

func Load(opts map[string]interface{}) (*config.ZipkinConfig, error) {
	var c config.ZipkinConfig
	if err := config.DecodeJSON(&c, opts); err != nil {
		return nil, err
	}
	return &c, nil
}

Cognitive complexity: 3, Cyclomatic complexity: 2

Uses: config.DecodeJSON, config.ZipkinConfig.

func NewTracer

func NewTracer(zip *zipkin.Tracer) *zipkinTracer {
	return &zipkinTracer{
		zip:	zip,
		extractors: map[interface{}]extractor{
			opentracing.HTTPHeaders: extractorFn(extractHTTPHeader),
		},
		injectors: map[interface{}]injector{
			opentracing.HTTPHeaders: injectorFn(injectHTTPHeaders),
		},
	}
}

Cognitive complexity: 5, Cyclomatic complexity: 1

Uses: opentracing.HTTPHeaders.

func (*logEncoder) EmitBool

func (e *logEncoder) EmitBool(key string, value bool)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitFloat32

func (e *logEncoder) EmitFloat32(key string, value float32)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitFloat64

func (e *logEncoder) EmitFloat64(key string, value float64)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitInt

func (e *logEncoder) EmitInt(key string, value int)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitInt32

func (e *logEncoder) EmitInt32(key string, value int32)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitInt64

func (e *logEncoder) EmitInt64(key string, value int64)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitLazyLogger

func (e *logEncoder) EmitLazyLogger(value opentracinglog.LazyLogger)	{}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitObject

func (e *logEncoder) EmitObject(key string, value interface{})	{ e.emit(key, value) }

Cognitive complexity: 1, Cyclomatic complexity: 1

func (*logEncoder) EmitString

func (e *logEncoder) EmitString(key, value string)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitUint32

func (e *logEncoder) EmitUint32(key string, value uint32)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*logEncoder) EmitUint64

func (e *logEncoder) EmitUint64(key string, value uint64)	{ e.emit(key, value) }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*zipkinTracer) Extract

func (z *zipkinTracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error) {
	if x, ok := z.extractors[format]; ok {
		return x.extract(carrier)
	}
	return nil, opentracing.ErrUnsupportedFormat
}

Cognitive complexity: 4, Cyclomatic complexity: 2

Uses: opentracing.ErrUnsupportedFormat.

func (*zipkinTracer) Inject

func (z *zipkinTracer) Inject(ctx opentracing.SpanContext, format interface{}, carrier interface{}) error {
	c, ok := ctx.(spanContext)
	if !ok {
		return opentracing.ErrInvalidSpanContext
	}
	if x, ok := z.injectors[format]; ok {
		return x.inject(c, carrier)
	}
	return opentracing.ErrUnsupportedFormat
}

Cognitive complexity: 6, Cyclomatic complexity: 3

Uses: opentracing.ErrInvalidSpanContext, opentracing.ErrUnsupportedFormat.

func (*zipkinTracer) StartSpan

func (z *zipkinTracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span {
	var o []zipkin.SpanOption
	if len(opts) > 0 {
		var os opentracing.StartSpanOptions
		for _, opt := range opts {
			opt.Apply(&os)
		}
		if len(os.Tags) > 0 {
			t := make(map[string]string)
			for k, v := range os.Tags {
				t[k] = fmt.Sprint(v)
			}
			o = append(o, zipkin.Tags(t))
		}
		for _, ref := range os.References {
			switch ref.Type {
			case opentracing.ChildOfRef:
				sp := ref.ReferencedContext.(spanContext)
				o = append(o, zipkin.Parent(
					sp.SpanContext,
				))
			}
		}
	}
	sp := z.zip.StartSpan(operationName, o...)
	return Span{tr: z, span: sp}
}

Cognitive complexity: 17, Cyclomatic complexity: 8

Uses: fmt.Sprint, opentracing.ChildOfRef, opentracing.StartSpanOptions, zipkin.Parent, zipkin.SpanOption, zipkin.Tags.

func (Span) BaggageItem

func (Span) BaggageItem(restrictedKey string) string	{ return "" }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Span) Context

func (s Span) Context() opentracing.SpanContext {
	return spanContext{s.span.Context()}
}

Cognitive complexity: 1, Cyclomatic complexity: 1

func (Span) Finish

func (s Span) Finish() {
	s.span.Finish()
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Span) FinishWithOptions

func (s Span) FinishWithOptions(opts opentracing.FinishOptions) {
	s.span.Finish()
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Span) Log

func (s Span) Log(data opentracing.LogData)	{}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Span) LogEvent

func (s Span) LogEvent(event string)	{}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Span) LogEventWithPayload

func (s Span) LogEventWithPayload(event string, payload interface{})	{}

Cognitive complexity: 1, Cyclomatic complexity: 1

func (Span) LogFields

func (s Span) LogFields(fields ...opentracinglog.Field) {
	now := time.Now()
	lg := &logEncoder{h: func(key string, value interface{}) {
		s.span.Annotate(now, fmt.Sprintf("%s %s", key, value))
	}}
	for _, field := range fields {
		field.Marshal(lg)
	}
}

Cognitive complexity: 6, Cyclomatic complexity: 2

Uses: fmt.Sprintf, time.Now.

func (Span) LogKV

func (s Span) LogKV(alternatingKeyValues ...interface{})	{}

Cognitive complexity: 1, Cyclomatic complexity: 1

func (Span) SetBaggageItem

func (s Span) SetBaggageItem(restrictedKey, value string) opentracing.Span	{ return s }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Span) SetOperationName

func (s Span) SetOperationName(operationName string) opentracing.Span {
	s.span.SetName(operationName)
	return s
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Span) SetTag

func (s Span) SetTag(key string, value interface{}) opentracing.Span {
	s.span.Tag(key, fmt.Sprint(value))
	return s
}

Cognitive complexity: 1, Cyclomatic complexity: 1

Uses: fmt.Sprint.

func (Span) Tracer

func (s Span) Tracer() opentracing.Tracer	{ return s.tr }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Tracer) Name

func (Tracer) Name() string {
	return Name
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (spanContext) ForeachBaggageItem

func (spanContext) ForeachBaggageItem(handler func(k, v string) bool)	{}

Cognitive complexity: 0, Cyclomatic complexity: 1

Private functions

func extractHTTPHeader

extractHTTPHeader (carrier interface{}) (spanContext, error)
References: b3.Context, b3.Flags, b3.ParentSpanID, b3.ParseHeaders, b3.ParseSingleHeader, b3.Sampled, b3.SpanID, b3.TraceID, opentracing.ErrInvalidCarrier, opentracing.HTTPHeadersCarrier, strings.ToLower.

func getSampler

getSampler (s config.Sampler) (zipkin.Sampler, error)
References: fmt.Errorf, zipkin.AlwaysSample, zipkin.NewBoundarySampler, zipkin.NewCountingSampler, zipkin.NewModuloSampler.

func injectHTTPHeaders

injectHTTPHeaders (ctx spanContext, carrier interface{}) error
References: b3.BuildSingleHeader, b3.Context, opentracing.ErrInvalidCarrier, opentracing.HTTPHeadersCarrier.

func emit

emit (key string, value interface{})

func extract

extract (carrier interface{}) (spanContext, error)

func inject

inject (ctx spanContext, carrier interface{}) error


Tests

Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 1. Benchmarks: 0.

Test functions

TestLoad

References: config.Config, config.Load.