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
|
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{
|
span := &Span{
|
||||||
Name: name,
|
Name: name,
|
||||||
Trace: uuid.New().String(),
|
Trace: uuid.New().String(),
|
||||||
@ -48,12 +48,12 @@ func (t *trace) Start(ctx context.Context, name string) *Span {
|
|||||||
|
|
||||||
// return span if no context
|
// return span if no context
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
return span
|
return context.Background(), span
|
||||||
}
|
}
|
||||||
|
|
||||||
s, ok := FromContext(ctx)
|
s, ok := FromContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return span
|
return ctx, span
|
||||||
}
|
}
|
||||||
|
|
||||||
// set trace id
|
// set trace id
|
||||||
@ -62,7 +62,7 @@ func (t *trace) Start(ctx context.Context, name string) *Span {
|
|||||||
span.Parent = s.Id
|
span.Parent = s.Id
|
||||||
|
|
||||||
// return the sapn
|
// return the sapn
|
||||||
return span
|
return ctx, span
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *trace) Finish(s *Span) error {
|
func (t *trace) Finish(s *Span) error {
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
// Trace is an interface for distributed tracing
|
// Trace is an interface for distributed tracing
|
||||||
type Trace interface {
|
type Trace interface {
|
||||||
// Start a trace
|
// Start a trace
|
||||||
Start(ctx context.Context, name string) *Span
|
Start(ctx context.Context, name string) (context.Context, *Span)
|
||||||
// Finish the trace
|
// Finish the trace
|
||||||
Finish(*Span) error
|
Finish(*Span) error
|
||||||
// Read the traces
|
// Read the traces
|
||||||
|
Loading…
Reference in New Issue
Block a user