Skip to content

Commit

Permalink
Don't end execution tracer task if none exists
Browse files Browse the repository at this point in the history
For spans created with NewSpanXXX, we cannot
create execution tracer tasks. Don't try to end
if none is created.

Fixes census-instrumentation#717.
  • Loading branch information
rakyll committed Apr 20, 2018
1 parent 268594c commit 1f85450
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Span struct {
*spanStore
endOnce sync.Once

executionTracerSpanEnd func() // ends the execution tracer span
executionTracerTaskEnd func() // ends the execution tracer span
}

// IsRecordingEvents returns true if events are being recorded for this span.
Expand Down Expand Up @@ -165,8 +165,8 @@ func StartSpan(ctx context.Context, name string, o ...StartOption) (context.Cont
}
span := startSpanInternal(name, parent != SpanContext{}, parent, false, opts)

ctx, end := startExecutionTracerSpan(ctx, name)
span.executionTracerSpanEnd = end
ctx, end := startExecutionTracerTask(ctx, name)
span.executionTracerTaskEnd = end
return NewContext(ctx, span), span
}

Expand All @@ -180,8 +180,8 @@ func StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanCont
op(&opts)
}
span := startSpanInternal(name, parent != SpanContext{}, parent, true, opts)
ctx, end := startExecutionTracerSpan(ctx, name)
span.executionTracerSpanEnd = end
ctx, end := startExecutionTracerTask(ctx, name)
span.executionTracerTaskEnd = end
return NewContext(ctx, span), span
}

Expand Down Expand Up @@ -266,7 +266,9 @@ func (s *Span) End() {
return
}
s.endOnce.Do(func() {
s.executionTracerSpanEnd()
if s.executionTracerTaskEnd != nil {
s.executionTracerTaskEnd()
}
// TODO: optimize to avoid this call if sd won't be used.
sd := s.makeSpanData()
sd.EndTime = internal.MonotonicEndTime(sd.StartTime)
Expand Down
2 changes: 1 addition & 1 deletion trace/trace_go11.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import (
t "runtime/trace"
)

func startExecutionTracerSpan(ctx context.Context, name string) (context.Context, func()) {
func startExecutionTracerTask(ctx context.Context, name string) (context.Context, func()) {
return t.NewContext(ctx, name)
}
2 changes: 1 addition & 1 deletion trace/trace_nongo11.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ import (
"context"
)

func startExecutionTracerSpan(ctx context.Context, name string) (context.Context, func()) {
func startExecutionTracerTask(ctx context.Context, name string) (context.Context, func()) {
return ctx, func() {}
}

0 comments on commit 1f85450

Please sign in to comment.