add trace context
This commit is contained in:
parent
2d28ff72d7
commit
a997a86e49
@ -37,7 +37,7 @@ func (t *trace) Read(opts ...ReadOption) ([]*Span, error) {
|
||||
return spans, nil
|
||||
}
|
||||
|
||||
func (t *trace) Start(ctx context.Context, name string) *Span {
|
||||
func (t *trace) Start(ctx context.Context, name string) (context.Context, *Span) {
|
||||
span := &Span{
|
||||
Name: name,
|
||||
Trace: uuid.New().String(),
|
||||
@ -48,12 +48,12 @@ func (t *trace) Start(ctx context.Context, name string) *Span {
|
||||
|
||||
// return span if no context
|
||||
if ctx == nil {
|
||||
return span
|
||||
return context.Background(), span
|
||||
}
|
||||
|
||||
s, ok := FromContext(ctx)
|
||||
if !ok {
|
||||
return span
|
||||
return ctx, span
|
||||
}
|
||||
|
||||
// set trace id
|
||||
@ -62,7 +62,7 @@ func (t *trace) Start(ctx context.Context, name string) *Span {
|
||||
span.Parent = s.Id
|
||||
|
||||
// return the sapn
|
||||
return span
|
||||
return ctx, span
|
||||
}
|
||||
|
||||
func (t *trace) Finish(s *Span) error {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
// Trace is an interface for distributed tracing
|
||||
type Trace interface {
|
||||
// Start a trace
|
||||
Start(ctx context.Context, name string) *Span
|
||||
Start(ctx context.Context, name string) (context.Context, *Span)
|
||||
// Finish the trace
|
||||
Finish(*Span) error
|
||||
// Read the traces
|
||||
|
Loading…
Reference in New Issue
Block a user