github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/health/options.go (about) 1 package health 2 3 import ( 4 "fmt" 5 6 "go.opentelemetry.io/otel/trace" 7 ) 8 9 // Option is the health-container options type 10 type Option func(*Health) error 11 12 // WithChecks adds checks to newly instantiated health-container 13 func WithChecks(checks ...Config) Option { 14 return func(h *Health) error { 15 for _, c := range checks { 16 if err := h.Register(c); err != nil { 17 return fmt.Errorf("could not register check %q: %w", c.Name, err) 18 } 19 } 20 21 return nil 22 } 23 } 24 25 // WithTracerProvider sets trace provider for the checks and instrumentation name that will be used 26 // for tracer from trace provider. 27 func WithTracerProvider(tp trace.TracerProvider, instrumentationName string) Option { 28 return func(h *Health) error { 29 h.tp = tp 30 h.instrumentationName = instrumentationName 31 32 return nil 33 } 34 } 35 36 // WithComponent sets the component description of the component to which this check refer 37 func WithComponent(component Component) Option { 38 return func(h *Health) error { 39 h.component = component 40 41 return nil 42 } 43 } 44 45 // WithMaxConcurrent sets max number of concurrently running checks. 46 // Set to 1 if want to run all checks sequentially. 47 func WithMaxConcurrent(n int) Option { 48 return func(h *Health) error { 49 h.maxConcurrent = n 50 return nil 51 } 52 } 53 54 // WithSystemInfo enables the option to return system information about the go process. 55 func WithSystemInfo() Option { 56 return func(h *Health) error { 57 h.systemInfoEnabled = true 58 return nil 59 } 60 }