2020-09-10 00:06:29 +03:00
|
|
|
package tracer
|
2020-01-18 13:20:46 +03:00
|
|
|
|
2020-12-09 12:10:25 +03:00
|
|
|
import "github.com/unistack-org/micro/v3/logger"
|
|
|
|
|
2020-11-03 02:02:32 +03:00
|
|
|
var (
|
|
|
|
// DefaultSize of the buffer
|
|
|
|
DefaultSize = 64
|
|
|
|
)
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Options struct
|
2020-01-29 18:45:11 +03:00
|
|
|
type Options struct {
|
2020-12-09 12:10:25 +03:00
|
|
|
// Logger is the logger for messages
|
|
|
|
Logger logger.Logger
|
2020-01-29 18:45:11 +03:00
|
|
|
// Size is the size of ring buffer
|
|
|
|
Size int
|
|
|
|
}
|
2020-01-18 13:20:46 +03:00
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Option func
|
2020-01-18 13:20:46 +03:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
2020-11-03 02:02:32 +03:00
|
|
|
// ReadOptions struct
|
2020-01-18 13:20:46 +03:00
|
|
|
type ReadOptions struct {
|
|
|
|
// Trace id
|
|
|
|
Trace string
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// ReadOption func
|
2020-01-18 13:20:46 +03:00
|
|
|
type ReadOption func(o *ReadOptions)
|
2020-01-25 00:24:51 +03:00
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// ReadTrace read the given trace
|
2020-01-25 00:24:51 +03:00
|
|
|
func ReadTrace(t string) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Trace = t
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 18:45:11 +03:00
|
|
|
|
2020-12-09 12:10:25 +03:00
|
|
|
// Logger sets the logger
|
|
|
|
func Logger(l logger.Logger) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Logger = l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 02:02:32 +03:00
|
|
|
// NewOptions returns default options
|
|
|
|
func NewOptions(opts ...Option) Options {
|
|
|
|
options := Options{
|
2020-12-09 12:10:25 +03:00
|
|
|
Logger: logger.DefaultLogger,
|
|
|
|
Size: DefaultSize,
|
2020-01-29 18:45:11 +03:00
|
|
|
}
|
2020-11-03 02:02:32 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return options
|
2020-01-29 18:45:11 +03:00
|
|
|
}
|