...

Source file src/github.com/go-kit/kit/tracing/opentracing/endpoint_options.go

Documentation: github.com/go-kit/kit/tracing/opentracing

     1  package opentracing
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/opentracing/opentracing-go"
     7  )
     8  
     9  // EndpointOptions holds the options for tracing an endpoint
    10  type EndpointOptions struct {
    11  	// IgnoreBusinessError if set to true will not treat a business error
    12  	// identified through the endpoint.Failer interface as a span error.
    13  	IgnoreBusinessError bool
    14  
    15  	// GetOperationName is an optional function that can set the span operation name based on the existing one
    16  	// for the endpoint and information in the context.
    17  	//
    18  	// If the function is nil, or the returned name is empty, the existing name for the endpoint is used.
    19  	GetOperationName func(ctx context.Context, name string) string
    20  
    21  	// Tags holds the default tags which will be set on span
    22  	// creation by our Endpoint middleware.
    23  	Tags opentracing.Tags
    24  
    25  	// GetTags is an optional function that can extract tags
    26  	// from the context and add them to the span.
    27  	GetTags func(ctx context.Context) opentracing.Tags
    28  }
    29  
    30  // EndpointOption allows for functional options to endpoint tracing middleware.
    31  type EndpointOption func(*EndpointOptions)
    32  
    33  // WithOptions sets all configuration options at once by use of the EndpointOptions struct.
    34  func WithOptions(options EndpointOptions) EndpointOption {
    35  	return func(o *EndpointOptions) {
    36  		*o = options
    37  	}
    38  }
    39  
    40  // WithIgnoreBusinessError if set to true will not treat a business error
    41  // identified through the endpoint.Failer interface as a span error.
    42  func WithIgnoreBusinessError(ignoreBusinessError bool) EndpointOption {
    43  	return func(o *EndpointOptions) {
    44  		o.IgnoreBusinessError = ignoreBusinessError
    45  	}
    46  }
    47  
    48  // WithOperationNameFunc allows to set function that can set the span operation name based on the existing one
    49  // for the endpoint and information in the context.
    50  func WithOperationNameFunc(getOperationName func(ctx context.Context, name string) string) EndpointOption {
    51  	return func(o *EndpointOptions) {
    52  		o.GetOperationName = getOperationName
    53  	}
    54  }
    55  
    56  // WithTags adds default tags for the spans created by the Endpoint tracer.
    57  func WithTags(tags opentracing.Tags) EndpointOption {
    58  	return func(o *EndpointOptions) {
    59  		if o.Tags == nil {
    60  			o.Tags = make(opentracing.Tags)
    61  		}
    62  
    63  		for key, value := range tags {
    64  			o.Tags[key] = value
    65  		}
    66  	}
    67  }
    68  
    69  // WithTagsFunc set the func to extracts additional tags from the context.
    70  func WithTagsFunc(getTags func(ctx context.Context) opentracing.Tags) EndpointOption {
    71  	return func(o *EndpointOptions) {
    72  		o.GetTags = getTags
    73  	}
    74  }
    75  

View as plain text