add trace context

This commit is contained in:
Asim Aslam 2020-01-24 21:44:48 +00:00
parent 2d28ff72d7
commit a997a86e49
2 changed files with 5 additions and 5 deletions

View File

@ -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 {

View File

@ -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