github.com/erda-project/erda-infra@v1.0.10-0.20240327085753-f3a249292aeb/pkg/trace/inject/redis/option.go (about) 1 // Copyright (c) 2021 Terminus, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package redis 16 17 import ( 18 "go.opentelemetry.io/otel/attribute" 19 "go.opentelemetry.io/otel/trace" 20 ) 21 22 // Option is the interface that applies a configuration option. 23 type Option interface { 24 // Apply sets the Option value of a config. 25 Apply(*config) 26 } 27 28 var _ Option = OptionFunc(nil) 29 30 // OptionFunc implements the Option interface. 31 type OptionFunc func(*config) 32 33 // Apply . 34 func (f OptionFunc) Apply(c *config) { 35 f(c) 36 } 37 38 // WithTracerProvider specifies a tracer provider to use for creating a tracer. 39 // If none is specified, the global provider is used. 40 func WithTracerProvider(provider trace.TracerProvider) Option { 41 return OptionFunc(func(cfg *config) { 42 cfg.TracerProvider = provider 43 }) 44 } 45 46 // WithAttributes specifies attributes that will be set to each span. 47 func WithAttributes(attributes ...attribute.KeyValue) Option { 48 return OptionFunc(func(cfg *config) { 49 cfg.Attributes = attributes 50 }) 51 } 52 53 // WithSpanNameFormatter takes an interface that will be called on every 54 // operation and the returned string will become the span name. 55 func WithSpanNameFormatter(spanNameFormatter SpanNameFormatter) Option { 56 return OptionFunc(func(cfg *config) { 57 cfg.SpanNameFormatter = spanNameFormatter 58 }) 59 } 60 61 // WithSpanOptions specifies configuration for span to decide whether to enable some features. 62 func WithSpanOptions(opts SpanOptions) Option { 63 return OptionFunc(func(cfg *config) { 64 cfg.SpanOptions = opts 65 }) 66 }