Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename finish to end #150

Merged
merged 4 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 12 additions & 12 deletions api/trace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ type Tracer interface {
WithResources(res ...core.KeyValue) Tracer
}

type FinishOptions struct {
FinishTime time.Time
type EndOptions struct {
EndTime time.Time
}

type FinishOption func(*FinishOptions)
type EndOption func(*EndOptions)

func WithFinishTime(finishTime time.Time) FinishOption {
return func(opts *FinishOptions) {
opts.FinishTime = finishTime
func WithEndTime(endTime time.Time) EndOption {
return func(opts *EndOptions) {
opts.EndTime = endTime
}
}

type Span interface {
// Tracer returns tracer used to create this span. Tracer cannot be nil.
Tracer() Tracer

// Finish completes the span. No updates are allowed to span after it
// finishes. The only exception is setting status of the span.
Finish(options ...FinishOption)
// End completes the span. No updates are allowed to span after it
// ends. The only exception is setting status of the span.
End(options ...EndOption)

// AddEvent adds an event to the span.
AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue)
Expand All @@ -82,12 +82,12 @@ type Span interface {
// It then adds the newly created Link to the span.
Link(sc core.SpanContext, attrs ...core.KeyValue)

// SpancContext returns span context of the span. Return SpanContext is usable
// even after the span is finished.
// SpanContext returns span context of the span. Return SpanContext is usable
akvanhar marked this conversation as resolved.
Show resolved Hide resolved
// even after the span ends.
SpanContext() core.SpanContext

// SetStatus sets the status of the span. The status of the span can be updated
// even after span is finished.
// even after span ends.
SetStatus(codes.Code)

// SetName sets the name of the span.
Expand Down
4 changes: 2 additions & 2 deletions api/trace/current_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (mockSpan) ModifyAttribute(mutator tag.Mutator) {
func (mockSpan) ModifyAttributes(mutators ...tag.Mutator) {
}

// Finish does nothing.
func (mockSpan) Finish(options ...trace.FinishOption) {
// End does nothing.
func (mockSpan) End(options ...trace.EndOption) {
}

// Tracer returns noop implementation of Tracer.
Expand Down
4 changes: 2 additions & 2 deletions api/trace/noop_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func (NoopSpan) ModifyAttribute(mutator tag.Mutator) {
func (NoopSpan) ModifyAttributes(mutators ...tag.Mutator) {
}

// Finish does nothing.
func (NoopSpan) Finish(options ...FinishOption) {
// End does nothing.
func (NoopSpan) End(options ...EndOption) {
}

// Tracer returns noop implementation of Tracer.
Expand Down
2 changes: 1 addition & 1 deletion example/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func main() {
trace.WithAttributes(attrs...),
trace.ChildOf(spanCtx),
)
defer span.Finish()
defer span.End()

span.AddEvent(ctx, "handling this...")

Expand Down
8 changes: 4 additions & 4 deletions experimental/bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ type bridgeSpan struct {
var _ ot.Span = &bridgeSpan{}

func (s *bridgeSpan) Finish() {
s.otelSpan.Finish()
s.otelSpan.End()
}

func (s *bridgeSpan) FinishWithOptions(opts ot.FinishOptions) {
var otelOpts []oteltrace.FinishOption
var otelOpts []oteltrace.EndOption

if !opts.FinishTime.IsZero() {
otelOpts = append(otelOpts, oteltrace.WithFinishTime(opts.FinishTime))
otelOpts = append(otelOpts, oteltrace.WithEndTime(opts.FinishTime))
}
for _, record := range opts.LogRecords {
s.logRecord(record)
}
for _, data := range opts.BulkLogData {
s.logRecord(data.ToLogRecord())
}
s.otelSpan.Finish(otelOpts...)
s.otelSpan.End(otelOpts...)
}

func (s *bridgeSpan) logRecord(record ot.LogRecord) {
Expand Down
22 changes: 11 additions & 11 deletions experimental/bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (t *MockTracer) WithService(name string) oteltrace.Tracer {

func (t *MockTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error {
ctx, span := t.Start(ctx, name)
defer span.Finish()
defer span.End()
return body(ctx)
}

Expand All @@ -109,7 +109,7 @@ func (t *MockTracer) Start(ctx context.Context, name string, opts ...oteltrace.S
recording: spanOpts.RecordEvent,
Attributes: oteltag.NewMap(upsertMultiMapUpdate(spanOpts.Attributes...)),
StartTime: startTime,
FinishTime: time.Time{},
EndTime: time.Time{},
ParentSpanID: t.getParentSpanID(ctx, &spanOpts),
Events: nil,
}
Expand Down Expand Up @@ -215,7 +215,7 @@ type MockSpan struct {

Attributes oteltag.Map
StartTime time.Time
FinishTime time.Time
EndTime time.Time
ParentSpanID uint64
Events []MockEvent
}
Expand Down Expand Up @@ -267,21 +267,21 @@ func (s *MockSpan) applyUpdate(update oteltag.MapUpdate) {
s.Attributes = s.Attributes.Apply(update)
}

func (s *MockSpan) Finish(options ...oteltrace.FinishOption) {
if !s.FinishTime.IsZero() {
func (s *MockSpan) End(options ...oteltrace.EndOption) {
if !s.EndTime.IsZero() {
return // already finished
}
finishOpts := oteltrace.FinishOptions{}
endOpts := oteltrace.EndOptions{}

for _, opt := range options {
opt(&finishOpts)
opt(&endOpts)
}

finishTime := finishOpts.FinishTime
if finishTime.IsZero() {
finishTime = time.Now()
endTime := endOpts.EndTime
if endTime.IsZero() {
endTime = time.Now()
}
s.FinishTime = finishTime
s.EndTime = endTime
s.mockTracer.FinishedSpans = append(s.mockTracer.FinishedSpans, s)
}

Expand Down
6 changes: 3 additions & 3 deletions experimental/bridge/opentracing/mix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,15 +538,15 @@ func min(a, b int) int {

func runOtelOTOtel(t *testing.T, ctx context.Context, name string, callback func(*testing.T, context.Context)) {
ctx, span := oteltrace.Start(ctx, fmt.Sprintf("%s_Otel_OTOtel", name))
defer span.Finish()
defer span.End()
callback(t, ctx)
func(ctx2 context.Context) {
span, ctx2 := ot.StartSpanFromContext(ctx2, fmt.Sprintf("%sOtel_OT_Otel", name))
defer span.Finish()
callback(t, ctx2)
func(ctx3 context.Context) {
ctx3, span := oteltrace.Start(ctx3, fmt.Sprintf("%sOtelOT_Otel_", name))
defer span.Finish()
defer span.End()
callback(t, ctx3)
}(ctx2)
}(ctx)
Expand All @@ -558,7 +558,7 @@ func runOTOtelOT(t *testing.T, ctx context.Context, name string, callback func(*
callback(t, ctx)
func(ctx2 context.Context) {
ctx2, span := oteltrace.Start(ctx2, fmt.Sprintf("%sOT_Otel_OT", name))
defer span.Finish()
defer span.End()
callback(t, ctx2)
func(ctx3 context.Context) {
span, ctx3 := ot.StartSpanFromContext(ctx3, fmt.Sprintf("%sOTOtel_OT_", name))
Expand Down
4 changes: 2 additions & 2 deletions experimental/streaming/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Event struct {
Attributes []core.KeyValue // SET_ATTRIBUTES
Mutator tag.Mutator // SET_ATTRIBUTE
Mutators []tag.Mutator // SET_ATTRIBUTES
Recovered interface{} // FINISH_SPAN
Recovered interface{} // END_SPAN
Status codes.Code // SET_STATUS

// Values
Expand All @@ -55,7 +55,7 @@ type Observer interface {
const (
INVALID EventType = iota
START_SPAN
FINISH_SPAN
END_SPAN
akvanhar marked this conversation as resolved.
Show resolved Hide resolved
ADD_EVENT
NEW_SCOPE
NEW_MEASURE
Expand Down
4 changes: 2 additions & 2 deletions experimental/streaming/exporter/reader/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
buf.WriteString(" >")
}

case exporter.FINISH_SPAN:
buf.WriteString("finish ")
case exporter.END_SPAN:
buf.WriteString("end ")
buf.WriteString(data.Name)

buf.WriteString(" (")
Expand Down
6 changes: 3 additions & 3 deletions experimental/streaming/exporter/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) {

ro.scopes.Store(event.Sequence, span)

case exporter.FINISH_SPAN:
case exporter.END_SPAN:
attrs, span := ro.readScope(event.Scope)
if span == nil {
panic(fmt.Sprint("span not found", event.Scope))
}

read.Name = span.name
read.Type = exporter.FINISH_SPAN
read.Type = exporter.END_SPAN

read.Attributes = attrs
read.Duration = event.Time.Sub(span.start)
Expand Down Expand Up @@ -287,7 +287,7 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) {
reader.Read(read)
}

if event.Type == exporter.FINISH_SPAN {
if event.Type == exporter.END_SPAN {
ro.cleanupSpan(event.Scope.EventID)
}
}
Expand Down
2 changes: 1 addition & 1 deletion experimental/streaming/exporter/spandata/spandata.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *spanReader) Read(data reader.Event) {

span.Events = append(span.Events, data)

if data.Type == exporter.FINISH_SPAN {
if data.Type == exporter.END_SPAN {
for _, r := range s.readers {
r.Read(span)
}
Expand Down
10 changes: 5 additions & 5 deletions experimental/streaming/sdk/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type span struct {
initial exporter.ScopeID
}

// SpancContext returns span context of the span. Return SpanContext is usable
// SpanContext returns span context of the span. Return SpanContext is usable
akvanhar marked this conversation as resolved.
Show resolved Hide resolved
// even after the span is finished.
func (sp *span) SpanContext() core.SpanContext {
return sp.initial.SpanContext
Expand Down Expand Up @@ -87,15 +87,15 @@ func (sp *span) ModifyAttributes(mutators ...tag.Mutator) {
})
}

func (sp *span) Finish(options ...trace.FinishOption) {
func (sp *span) End(options ...trace.EndOption) {
recovered := recover()
opts := trace.FinishOptions{}
opts := trace.EndOptions{}
for _, opt := range options {
opt(&opts)
}
sp.tracer.exporter.Record(exporter.Event{
Time: opts.FinishTime,
Type: exporter.FINISH_SPAN,
Time: opts.EndTime,
Type: exporter.END_SPAN,
Scope: sp.ScopeID(),
Recovered: recovered,
})
Expand Down
6 changes: 3 additions & 3 deletions experimental/streaming/sdk/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ func TestCustomStartEndTime(t *testing.T) {
"testspan",
trace.WithStartTime(startTime),
)
span.Finish(trace.WithFinishTime(endTime))
span.End(trace.WithEndTime(endTime))
want := []exporter.Event{
{
Type: exporter.START_SPAN,
Time: startTime,
String: "testspan",
},
{
Type: exporter.FINISH_SPAN,
Type: exporter.END_SPAN,
Time: endTime,
},
}
got := append(obs.Events(exporter.START_SPAN), obs.Events(exporter.FINISH_SPAN)...)
got := append(obs.Events(exporter.START_SPAN), obs.Events(exporter.END_SPAN)...)
diffEvents(t, got, want, "Scope")
}

Expand Down
2 changes: 1 addition & 1 deletion experimental/streaming/sdk/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (t *tracer) WithSpan(ctx context.Context, name string, body func(context.Co
// TODO: use runtime/trace.WithRegion for execution tracer support
// TODO: use runtime/pprof.Do for profile tags support
ctx, span := t.Start(ctx, name)
defer span.Finish()
defer span.End()

if err := body(ctx); err != nil {
span.SetAttribute(ErrorKey.Bool(true))
Expand Down
4 changes: 2 additions & 2 deletions exporter/trace/jaeger/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ func main() {

ctx, span := apitrace.GlobalTracer().Start(ctx, "/foo")
bar(ctx)
span.Finish()
span.End()

exporter.Flush()
}

func bar(ctx context.Context) {
_, span := apitrace.GlobalTracer().Start(ctx, "/bar")
defer span.Finish()
defer span.End()

// Do bar...
}
4 changes: 2 additions & 2 deletions internal/trace/mock_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (ms *MockSpan) ModifyAttribute(mutator tag.Mutator) {
func (ms *MockSpan) ModifyAttributes(mutators ...tag.Mutator) {
}

// Finish does nothing.
func (ms *MockSpan) Finish(options ...apitrace.FinishOption) {
// End does nothing.
func (ms *MockSpan) End(options ...apitrace.EndOption) {
}

// SetName does nothing.
Expand Down
2 changes: 1 addition & 1 deletion plugin/httptrace/clienttrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (ct *clientTracer) close(name string) {
ct.mtx.Lock()
defer ct.mtx.Unlock()
if s, ok := ct.levels[name]; ok {
s.Finish()
s.End()
delete(ct.levels, name)
} else {
panic(fmt.Sprintf("failed to find span %s in levels.", name))
Expand Down
10 changes: 5 additions & 5 deletions sdk/trace/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func BenchmarkStartEndSpan(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, span := t.Start(ctx, "/foo")
span.Finish()
span.End()
}
})
}
Expand All @@ -50,7 +50,7 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) {
key.New("key3").Uint64(123),
key.New("key4").Float64(123.456),
)
span.Finish()
span.End()
}
})
}
Expand All @@ -74,7 +74,7 @@ func BenchmarkSpanWithAttributes_8(b *testing.B) {
key.New("key23").Uint64(123),
key.New("key24").Float64(123.456),
)
span.Finish()
span.End()
}
})
}
Expand All @@ -101,7 +101,7 @@ func BenchmarkSpanWithAttributes_all(b *testing.B) {
key.New("key10").Int(123),
key.New("key11").Uint(123),
)
span.Finish()
span.End()
}
})
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) {
key.New("key210").Int(123),
key.New("key211").Uint(123),
)
span.Finish()
span.End()
}
})
}
Expand Down
Loading