github.com/mailgun/holster/v4@v4.20.0/tracing/option.go (about)

     1  package tracing
     2  
     3  import (
     4  	"go.opentelemetry.io/otel/sdk/resource"
     5  	sdktrace "go.opentelemetry.io/otel/sdk/trace"
     6  )
     7  
     8  type TracingOption interface {
     9  	apply(state *initState)
    10  }
    11  
    12  type TracerProviderTracingOption struct {
    13  	opts []sdktrace.TracerProviderOption
    14  }
    15  
    16  // WithTracerProviderOption passes TracerProviderOption arguments to
    17  // InitTracing.
    18  func WithTracerProviderOption(opts ...sdktrace.TracerProviderOption) *TracerProviderTracingOption {
    19  	return &TracerProviderTracingOption{
    20  		opts: opts,
    21  	}
    22  }
    23  
    24  func (o *TracerProviderTracingOption) apply(state *initState) {
    25  	state.opts = append(state.opts, o.opts...)
    26  }
    27  
    28  type ResourceOption struct {
    29  	res *resource.Resource
    30  }
    31  
    32  // WithResource is convenience function for common use case of passing a
    33  // Resource object as TracerProviderOption.
    34  func WithResource(res *resource.Resource) *ResourceOption {
    35  	return &ResourceOption{
    36  		res: res,
    37  	}
    38  }
    39  
    40  func (o *ResourceOption) apply(state *initState) {
    41  	state.opts = append(state.opts, sdktrace.WithResource(o.res))
    42  }
    43  
    44  type LevelTracingOption struct {
    45  	level Level
    46  }
    47  
    48  // WithLevel passes a log level to InitTracing.
    49  func WithLevel(level Level) *LevelTracingOption {
    50  	return &LevelTracingOption{
    51  		level: level,
    52  	}
    53  }
    54  
    55  func (o *LevelTracingOption) apply(state *initState) {
    56  	state.level = o.level
    57  }