Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Create a Go execution tracer task for each span #715

Merged
merged 1 commit into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ type Span struct {
spanContext SpanContext
// spanStore is the spanStore this span belongs to, if any, otherwise it is nil.
*spanStore
exportOnce sync.Once
endOnce sync.Once

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

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

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

Expand All @@ -175,6 +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
return NewContext(ctx, span), span
}

Expand Down Expand Up @@ -258,7 +265,8 @@ func (s *Span) End() {
if !s.IsRecordingEvents() {
return
}
s.exportOnce.Do(func() {
s.endOnce.Do(func() {
s.executionTracerSpanEnd()
// TODO: optimize to avoid this call if sd won't be used.
sd := s.makeSpanData()
sd.EndTime = internal.MonotonicEndTime(sd.StartTime)
Expand Down
26 changes: 26 additions & 0 deletions trace/trace_go11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build go1.11

package trace

import (
"context"
t "runtime/trace"
)

func startExecutionTracerSpan(ctx context.Context, name string) (context.Context, func()) {
return t.NewContext(ctx, name)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer builds as of https://golang.org/cl/112198.

(CC: @hyangah @pjweinbgo)

}
25 changes: 25 additions & 0 deletions trace/trace_nongo11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !go1.11

package trace

import (
"context"
)

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