tracer: add Flush method #224

Merged
vtolstov merged 1 commits from tracerimp into master 2023-07-04 00:24:11 +03:00
3 changed files with 8 additions and 4 deletions

View File

@ -39,8 +39,6 @@ func FromOutgoingContext(ctx context.Context) (Metadata, bool) {
// FromContext returns metadata from the given context // FromContext returns metadata from the given context
// returned metadata shoud not be modified or race condition happens // returned metadata shoud not be modified or race condition happens
//
// Deprecated: use FromIncomingContext or FromOutgoingContext
func FromContext(ctx context.Context) (Metadata, bool) { func FromContext(ctx context.Context) (Metadata, bool) {
if ctx == nil { if ctx == nil {
return nil, false return nil, false
@ -53,8 +51,6 @@ func FromContext(ctx context.Context) (Metadata, bool) {
} }
// NewContext creates a new context with the given metadata // NewContext creates a new context with the given metadata
//
// Deprecated: use NewIncomingContext or NewOutgoingContext
func NewContext(ctx context.Context, md Metadata) context.Context { func NewContext(ctx context.Context, md Metadata) context.Context {
if ctx == nil { if ctx == nil {
ctx = context.Background() ctx = context.Background()

View File

@ -4,6 +4,8 @@ import (
"context" "context"
) )
var _ Tracer = (*noopTracer)(nil)
type noopTracer struct { type noopTracer struct {
opts Options opts Options
} }
@ -21,6 +23,10 @@ func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption)
return NewSpanContext(ctx, span), span return NewSpanContext(ctx, span), span
} }
func (t *noopTracer) Flush(ctx context.Context) error {
return nil
}
func (t *noopTracer) Init(opts ...Option) error { func (t *noopTracer) Init(opts ...Option) error {
for _, o := range opts { for _, o := range opts {
o(&t.opts) o(&t.opts)

View File

@ -16,6 +16,8 @@ type Tracer interface {
Init(...Option) error Init(...Option) error
// Start a trace // Start a trace
Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)
// Flush flushes spans
Flush(ctx context.Context) error
} }
type Span interface { type Span interface {