Codebase list golang-github-go-kit-kit / d2f2902b-79c4-43cd-8c09-341e33fc6017/v0.8.0 tracing / zipkin / options.go
d2f2902b-79c4-43cd-8c09-341e33fc6017/v0.8.0

Tree @d2f2902b-79c4-43cd-8c09-341e33fc6017/v0.8.0 (Download .tar.gz)

options.go @d2f2902b-79c4-43cd-8c09-341e33fc6017/v0.8.0raw · history · blame

package zipkin

import "github.com/go-kit/kit/log"

// TracerOption allows for functional options to our Zipkin tracing middleware.
type TracerOption func(o *tracerOptions)

// Name sets the name for an instrumented transport endpoint. If name is omitted
// at tracing middleware creation, the method of the transport or transport rpc
// name is used.
func Name(name string) TracerOption {
	return func(o *tracerOptions) {
		o.name = name
	}
}

// Tags adds default tags to our Zipkin transport spans.
func Tags(tags map[string]string) TracerOption {
	return func(o *tracerOptions) {
		for k, v := range tags {
			o.tags[k] = v
		}
	}
}

// Logger adds a Go kit logger to our Zipkin Middleware to log SpanContext
// extract / inject errors if they occur. Default is Noop.
func Logger(logger log.Logger) TracerOption {
	return func(o *tracerOptions) {
		if logger != nil {
			o.logger = logger
		}
	}
}

// AllowPropagation instructs the tracer to allow or deny propagation of the
// span context between this instrumented client or service and its peers. If
// the instrumented client connects to services outside its own platform or if
// the instrumented service receives requests from untrusted clients it is
// strongly advised to disallow propagation. Propagation between services inside
// your own platform benefit from propagation. Default for both TraceClient and
// TraceServer is to allow propagation.
func AllowPropagation(propagate bool) TracerOption {
	return func(o *tracerOptions) {
		o.propagate = propagate
	}
}

type tracerOptions struct {
	tags      map[string]string
	name      string
	logger    log.Logger
	propagate bool
}