...

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

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

     1  package opencensus
     2  
     3  import (
     4  	"context"
     5  
     6  	"go.opencensus.io/trace"
     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  	// Attributes holds the default attributes which will be set on span
    16  	// creation by our Endpoint middleware.
    17  	Attributes []trace.Attribute
    18  
    19  	// GetName is an optional function that can set the span name based on the existing name
    20  	// for the endpoint and information in the context.
    21  	//
    22  	// If the function is nil, or the returned name is empty, the existing name for the endpoint is used.
    23  	GetName func(ctx context.Context, name string) string
    24  
    25  	// GetAttributes is an optional function that can extract trace attributes 
    26  	// from the context and add them to the span.
    27  	GetAttributes func(ctx context.Context) []trace.Attribute
    28  }
    29  
    30  // EndpointOption allows for functional options to our OpenCensus endpoint
    31  // tracing middleware.
    32  type EndpointOption func(*EndpointOptions)
    33  
    34  // WithEndpointConfig sets all configuration options at once by use of the
    35  // EndpointOptions struct.
    36  func WithEndpointConfig(options EndpointOptions) EndpointOption {
    37  	return func(o *EndpointOptions) {
    38  		*o = options
    39  	}
    40  }
    41  
    42  // WithEndpointAttributes sets the default attributes for the spans created by
    43  // the Endpoint tracer.
    44  func WithEndpointAttributes(attrs ...trace.Attribute) EndpointOption {
    45  	return func(o *EndpointOptions) {
    46  		o.Attributes = attrs
    47  	}
    48  }
    49  
    50  // WithIgnoreBusinessError if set to true will not treat a business error
    51  // identified through the endpoint.Failer interface as a span error.
    52  func WithIgnoreBusinessError(val bool) EndpointOption {
    53  	return func(o *EndpointOptions) {
    54  		o.IgnoreBusinessError = val
    55  	}
    56  }
    57  
    58  // WithSpanName extracts additional attributes from the request context.
    59  func WithSpanName(fn func(ctx context.Context, name string) string) EndpointOption {
    60  	return func(o *EndpointOptions) {
    61  		o.GetName = fn
    62  	}
    63  }
    64  
    65  // WithSpanAttributes extracts additional attributes from the request context.
    66  func WithSpanAttributes(fn func(ctx context.Context) []trace.Attribute) EndpointOption {
    67  	return func(o *EndpointOptions) {
    68  		o.GetAttributes = fn
    69  	}
    70  }
    71  

View as plain text