v3 (#404)
## Pull Request template Please, go through these steps before clicking submit on this PR. 1. Give a descriptive title to your PR. 2. Provide a description of your changes. 3. Make sure you have some relevant tests. 4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable). **PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING** Reviewed-on: #404 Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru> Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
This commit is contained in:
@@ -46,6 +46,10 @@ func (s memoryStringer) String() string {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (t *Tracer) Enabled() bool {
|
||||
return t.opts.Enabled
|
||||
}
|
||||
|
||||
func (t *Tracer) Flush(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
@@ -18,6 +18,10 @@ func (t *noopTracer) Spans() []Span {
|
||||
return t.spans
|
||||
}
|
||||
|
||||
func (t *noopTracer) Enabled() bool {
|
||||
return t.opts.Enabled
|
||||
}
|
||||
|
||||
func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
|
||||
options := NewSpanOptions(opts...)
|
||||
span := &noopSpan{
|
||||
|
@@ -142,6 +142,8 @@ type Options struct {
|
||||
Name string
|
||||
// ContextAttrFuncs contains funcs that provides tracing
|
||||
ContextAttrFuncs []ContextAttrFunc
|
||||
// Enabled specify trace status
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
// Option func signature
|
||||
@@ -181,6 +183,7 @@ func NewOptions(opts ...Option) Options {
|
||||
Logger: logger.DefaultLogger,
|
||||
Context: context.Background(),
|
||||
ContextAttrFuncs: DefaultContextAttrFuncs,
|
||||
Enabled: true,
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
@@ -194,3 +197,10 @@ func Name(n string) Option {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
||||
// Disabled disable tracer
|
||||
func Disabled(b bool) Option {
|
||||
return func(o *Options) {
|
||||
o.Enabled = !b
|
||||
}
|
||||
}
|
||||
|
@@ -51,6 +51,8 @@ type Tracer interface {
|
||||
// Extract(ctx context.Context)
|
||||
// Flush flushes spans
|
||||
Flush(ctx context.Context) error
|
||||
// Enabled returns tracer status
|
||||
Enabled() bool
|
||||
}
|
||||
|
||||
type Span interface {
|
||||
|
@@ -67,6 +67,12 @@ func (b *SeekerBuffer) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset clears all the data out of the buffer and sets the read position to 0.
|
||||
func (b *SeekerBuffer) Reset() {
|
||||
b.data = nil
|
||||
b.pos = 0
|
||||
}
|
||||
|
||||
// Len returns the length of data remaining to be read.
|
||||
func (b *SeekerBuffer) Len() int {
|
||||
return len(b.data[b.pos:])
|
||||
|
Reference in New Issue
Block a user