You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	rename finish to end (#150)
* rename finish -> end * missed a few finish -> end spots * change end back to finish for the bridge span in the openTracing bridge * fixed grammar, ran make
This commit is contained in:
		
				
					committed by
					
						 rghetia
						rghetia
					
				
			
			
				
	
			
			
			
						parent
						
							e86b95c440
						
					
				
				
					commit
					0eb73325ce
				
			| @@ -46,15 +46,15 @@ type Tracer interface { | |||||||
| 	WithResources(res ...core.KeyValue) Tracer | 	WithResources(res ...core.KeyValue) Tracer | ||||||
| } | } | ||||||
|  |  | ||||||
| type FinishOptions struct { | type EndOptions struct { | ||||||
| 	FinishTime time.Time | 	EndTime time.Time | ||||||
| } | } | ||||||
|  |  | ||||||
| type FinishOption func(*FinishOptions) | type EndOption func(*EndOptions) | ||||||
|  |  | ||||||
| func WithFinishTime(finishTime time.Time) FinishOption { | func WithEndTime(endTime time.Time) EndOption { | ||||||
| 	return func(opts *FinishOptions) { | 	return func(opts *EndOptions) { | ||||||
| 		opts.FinishTime = finishTime | 		opts.EndTime = endTime | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -62,9 +62,9 @@ type Span interface { | |||||||
| 	// Tracer returns tracer used to create this span. Tracer cannot be nil. | 	// Tracer returns tracer used to create this span. Tracer cannot be nil. | ||||||
| 	Tracer() Tracer | 	Tracer() Tracer | ||||||
|  |  | ||||||
| 	// Finish completes the span. No updates are allowed to span after it | 	// End completes the span. No updates are allowed to span after it | ||||||
| 	// finishes. The only exception is setting status of the span. | 	// ends. The only exception is setting status of the span. | ||||||
| 	Finish(options ...FinishOption) | 	End(options ...EndOption) | ||||||
|  |  | ||||||
| 	// AddEvent adds an event to the span. | 	// AddEvent adds an event to the span. | ||||||
| 	AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) | 	AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) | ||||||
| @@ -82,12 +82,12 @@ type Span interface { | |||||||
| 	// It then adds the newly created Link to the span. | 	// It then adds the newly created Link to the span. | ||||||
| 	Link(sc core.SpanContext, attrs ...core.KeyValue) | 	Link(sc core.SpanContext, attrs ...core.KeyValue) | ||||||
|  |  | ||||||
| 	// SpancContext returns span context of the span. Return SpanContext is usable | 	// SpanContext returns span context of the span. Returned SpanContext is usable | ||||||
| 	// even after the span is finished. | 	// even after the span ends. | ||||||
| 	SpanContext() core.SpanContext | 	SpanContext() core.SpanContext | ||||||
|  |  | ||||||
| 	// SetStatus sets the status of the span. The status of the span can be updated | 	// 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) | 	SetStatus(codes.Code) | ||||||
|  |  | ||||||
| 	// SetName sets the name of the span. | 	// SetName sets the name of the span. | ||||||
|   | |||||||
| @@ -96,8 +96,8 @@ func (mockSpan) ModifyAttribute(mutator tag.Mutator) { | |||||||
| func (mockSpan) ModifyAttributes(mutators ...tag.Mutator) { | func (mockSpan) ModifyAttributes(mutators ...tag.Mutator) { | ||||||
| } | } | ||||||
|  |  | ||||||
| // Finish does nothing. | // End does nothing. | ||||||
| func (mockSpan) Finish(options ...trace.FinishOption) { | func (mockSpan) End(options ...trace.EndOption) { | ||||||
| } | } | ||||||
|  |  | ||||||
| // Tracer returns noop implementation of Tracer. | // Tracer returns noop implementation of Tracer. | ||||||
|   | |||||||
| @@ -63,8 +63,8 @@ func (NoopSpan) ModifyAttribute(mutator tag.Mutator) { | |||||||
| func (NoopSpan) ModifyAttributes(mutators ...tag.Mutator) { | func (NoopSpan) ModifyAttributes(mutators ...tag.Mutator) { | ||||||
| } | } | ||||||
|  |  | ||||||
| // Finish does nothing. | // End does nothing. | ||||||
| func (NoopSpan) Finish(options ...FinishOption) { | func (NoopSpan) End(options ...EndOption) { | ||||||
| } | } | ||||||
|  |  | ||||||
| // Tracer returns noop implementation of Tracer. | // Tracer returns noop implementation of Tracer. | ||||||
|   | |||||||
| @@ -66,7 +66,7 @@ func main() { | |||||||
| 			trace.WithAttributes(attrs...), | 			trace.WithAttributes(attrs...), | ||||||
| 			trace.ChildOf(spanCtx), | 			trace.ChildOf(spanCtx), | ||||||
| 		) | 		) | ||||||
| 		defer span.Finish() | 		defer span.End() | ||||||
|  |  | ||||||
| 		span.AddEvent(ctx, "handling this...") | 		span.AddEvent(ctx, "handling this...") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -88,14 +88,14 @@ type bridgeSpan struct { | |||||||
| var _ ot.Span = &bridgeSpan{} | var _ ot.Span = &bridgeSpan{} | ||||||
|  |  | ||||||
| func (s *bridgeSpan) Finish() { | func (s *bridgeSpan) Finish() { | ||||||
| 	s.otelSpan.Finish() | 	s.otelSpan.End() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *bridgeSpan) FinishWithOptions(opts ot.FinishOptions) { | func (s *bridgeSpan) FinishWithOptions(opts ot.FinishOptions) { | ||||||
| 	var otelOpts []oteltrace.FinishOption | 	var otelOpts []oteltrace.EndOption | ||||||
|  |  | ||||||
| 	if !opts.FinishTime.IsZero() { | 	if !opts.FinishTime.IsZero() { | ||||||
| 		otelOpts = append(otelOpts, oteltrace.WithFinishTime(opts.FinishTime)) | 		otelOpts = append(otelOpts, oteltrace.WithEndTime(opts.FinishTime)) | ||||||
| 	} | 	} | ||||||
| 	for _, record := range opts.LogRecords { | 	for _, record := range opts.LogRecords { | ||||||
| 		s.logRecord(record) | 		s.logRecord(record) | ||||||
| @@ -103,7 +103,7 @@ func (s *bridgeSpan) FinishWithOptions(opts ot.FinishOptions) { | |||||||
| 	for _, data := range opts.BulkLogData { | 	for _, data := range opts.BulkLogData { | ||||||
| 		s.logRecord(data.ToLogRecord()) | 		s.logRecord(data.ToLogRecord()) | ||||||
| 	} | 	} | ||||||
| 	s.otelSpan.Finish(otelOpts...) | 	s.otelSpan.End(otelOpts...) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *bridgeSpan) logRecord(record ot.LogRecord) { | func (s *bridgeSpan) logRecord(record ot.LogRecord) { | ||||||
|   | |||||||
| @@ -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 { | func (t *MockTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error { | ||||||
| 	ctx, span := t.Start(ctx, name) | 	ctx, span := t.Start(ctx, name) | ||||||
| 	defer span.Finish() | 	defer span.End() | ||||||
| 	return body(ctx) | 	return body(ctx) | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -109,7 +109,7 @@ func (t *MockTracer) Start(ctx context.Context, name string, opts ...oteltrace.S | |||||||
| 		recording:      spanOpts.RecordEvent, | 		recording:      spanOpts.RecordEvent, | ||||||
| 		Attributes:     oteltag.NewMap(upsertMultiMapUpdate(spanOpts.Attributes...)), | 		Attributes:     oteltag.NewMap(upsertMultiMapUpdate(spanOpts.Attributes...)), | ||||||
| 		StartTime:      startTime, | 		StartTime:      startTime, | ||||||
| 		FinishTime:     time.Time{}, | 		EndTime:        time.Time{}, | ||||||
| 		ParentSpanID:   t.getParentSpanID(ctx, &spanOpts), | 		ParentSpanID:   t.getParentSpanID(ctx, &spanOpts), | ||||||
| 		Events:         nil, | 		Events:         nil, | ||||||
| 	} | 	} | ||||||
| @@ -215,7 +215,7 @@ type MockSpan struct { | |||||||
|  |  | ||||||
| 	Attributes   oteltag.Map | 	Attributes   oteltag.Map | ||||||
| 	StartTime    time.Time | 	StartTime    time.Time | ||||||
| 	FinishTime   time.Time | 	EndTime      time.Time | ||||||
| 	ParentSpanID uint64 | 	ParentSpanID uint64 | ||||||
| 	Events       []MockEvent | 	Events       []MockEvent | ||||||
| } | } | ||||||
| @@ -267,21 +267,21 @@ func (s *MockSpan) applyUpdate(update oteltag.MapUpdate) { | |||||||
| 	s.Attributes = s.Attributes.Apply(update) | 	s.Attributes = s.Attributes.Apply(update) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *MockSpan) Finish(options ...oteltrace.FinishOption) { | func (s *MockSpan) End(options ...oteltrace.EndOption) { | ||||||
| 	if !s.FinishTime.IsZero() { | 	if !s.EndTime.IsZero() { | ||||||
| 		return // already finished | 		return // already finished | ||||||
| 	} | 	} | ||||||
| 	finishOpts := oteltrace.FinishOptions{} | 	endOpts := oteltrace.EndOptions{} | ||||||
|  |  | ||||||
| 	for _, opt := range options { | 	for _, opt := range options { | ||||||
| 		opt(&finishOpts) | 		opt(&endOpts) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	finishTime := finishOpts.FinishTime | 	endTime := endOpts.EndTime | ||||||
| 	if finishTime.IsZero() { | 	if endTime.IsZero() { | ||||||
| 		finishTime = time.Now() | 		endTime = time.Now() | ||||||
| 	} | 	} | ||||||
| 	s.FinishTime = finishTime | 	s.EndTime = endTime | ||||||
| 	s.mockTracer.FinishedSpans = append(s.mockTracer.FinishedSpans, s) | 	s.mockTracer.FinishedSpans = append(s.mockTracer.FinishedSpans, s) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -538,7 +538,7 @@ func min(a, b int) int { | |||||||
|  |  | ||||||
| func runOtelOTOtel(t *testing.T, ctx context.Context, name string, callback func(*testing.T, context.Context)) { | 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)) | 	ctx, span := oteltrace.Start(ctx, fmt.Sprintf("%s_Otel_OTOtel", name)) | ||||||
| 	defer span.Finish() | 	defer span.End() | ||||||
| 	callback(t, ctx) | 	callback(t, ctx) | ||||||
| 	func(ctx2 context.Context) { | 	func(ctx2 context.Context) { | ||||||
| 		span, ctx2 := ot.StartSpanFromContext(ctx2, fmt.Sprintf("%sOtel_OT_Otel", name)) | 		span, ctx2 := ot.StartSpanFromContext(ctx2, fmt.Sprintf("%sOtel_OT_Otel", name)) | ||||||
| @@ -546,7 +546,7 @@ func runOtelOTOtel(t *testing.T, ctx context.Context, name string, callback func | |||||||
| 		callback(t, ctx2) | 		callback(t, ctx2) | ||||||
| 		func(ctx3 context.Context) { | 		func(ctx3 context.Context) { | ||||||
| 			ctx3, span := oteltrace.Start(ctx3, fmt.Sprintf("%sOtelOT_Otel_", name)) | 			ctx3, span := oteltrace.Start(ctx3, fmt.Sprintf("%sOtelOT_Otel_", name)) | ||||||
| 			defer span.Finish() | 			defer span.End() | ||||||
| 			callback(t, ctx3) | 			callback(t, ctx3) | ||||||
| 		}(ctx2) | 		}(ctx2) | ||||||
| 	}(ctx) | 	}(ctx) | ||||||
| @@ -558,7 +558,7 @@ func runOTOtelOT(t *testing.T, ctx context.Context, name string, callback func(* | |||||||
| 	callback(t, ctx) | 	callback(t, ctx) | ||||||
| 	func(ctx2 context.Context) { | 	func(ctx2 context.Context) { | ||||||
| 		ctx2, span := oteltrace.Start(ctx2, fmt.Sprintf("%sOT_Otel_OT", name)) | 		ctx2, span := oteltrace.Start(ctx2, fmt.Sprintf("%sOT_Otel_OT", name)) | ||||||
| 		defer span.Finish() | 		defer span.End() | ||||||
| 		callback(t, ctx2) | 		callback(t, ctx2) | ||||||
| 		func(ctx3 context.Context) { | 		func(ctx3 context.Context) { | ||||||
| 			span, ctx3 := ot.StartSpanFromContext(ctx3, fmt.Sprintf("%sOTOtel_OT_", name)) | 			span, ctx3 := ot.StartSpanFromContext(ctx3, fmt.Sprintf("%sOTOtel_OT_", name)) | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ func _() { | |||||||
| 	var x [1]struct{} | 	var x [1]struct{} | ||||||
| 	_ = x[INVALID-0] | 	_ = x[INVALID-0] | ||||||
| 	_ = x[START_SPAN-1] | 	_ = x[START_SPAN-1] | ||||||
| 	_ = x[FINISH_SPAN-2] | 	_ = x[END_SPAN-2] | ||||||
| 	_ = x[ADD_EVENT-3] | 	_ = x[ADD_EVENT-3] | ||||||
| 	_ = x[NEW_SCOPE-4] | 	_ = x[NEW_SCOPE-4] | ||||||
| 	_ = x[NEW_MEASURE-5] | 	_ = x[NEW_MEASURE-5] | ||||||
| @@ -21,9 +21,9 @@ func _() { | |||||||
| 	_ = x[SET_NAME-10] | 	_ = x[SET_NAME-10] | ||||||
| } | } | ||||||
|  |  | ||||||
| const _EventType_name = "INVALIDSTART_SPANFINISH_SPANADD_EVENTNEW_SCOPENEW_MEASURENEW_METRICMODIFY_ATTRRECORD_STATSSET_STATUSSET_NAME" | const _EventType_name = "INVALIDSTART_SPANEND_SPANADD_EVENTNEW_SCOPENEW_MEASURENEW_METRICMODIFY_ATTRRECORD_STATSSET_STATUSSET_NAME" | ||||||
|  |  | ||||||
| var _EventType_index = [...]uint8{0, 7, 17, 28, 37, 46, 57, 67, 78, 90, 100, 108} | var _EventType_index = [...]uint8{0, 7, 17, 25, 34, 43, 54, 64, 75, 87, 97, 105} | ||||||
|  |  | ||||||
| func (i EventType) String() string { | func (i EventType) String() string { | ||||||
| 	if i < 0 || i >= EventType(len(_EventType_index)-1) { | 	if i < 0 || i >= EventType(len(_EventType_index)-1) { | ||||||
|   | |||||||
| @@ -36,7 +36,7 @@ type Event struct { | |||||||
| 	Attributes []core.KeyValue // SET_ATTRIBUTES | 	Attributes []core.KeyValue // SET_ATTRIBUTES | ||||||
| 	Mutator    tag.Mutator     // SET_ATTRIBUTE | 	Mutator    tag.Mutator     // SET_ATTRIBUTE | ||||||
| 	Mutators   []tag.Mutator   // SET_ATTRIBUTES | 	Mutators   []tag.Mutator   // SET_ATTRIBUTES | ||||||
| 	Recovered  interface{}     // FINISH_SPAN | 	Recovered  interface{}     // END_SPAN | ||||||
| 	Status     codes.Code      // SET_STATUS | 	Status     codes.Code      // SET_STATUS | ||||||
|  |  | ||||||
| 	// Values | 	// Values | ||||||
| @@ -55,7 +55,7 @@ type Observer interface { | |||||||
| const ( | const ( | ||||||
| 	INVALID EventType = iota | 	INVALID EventType = iota | ||||||
| 	START_SPAN | 	START_SPAN | ||||||
| 	FINISH_SPAN | 	END_SPAN | ||||||
| 	ADD_EVENT | 	ADD_EVENT | ||||||
| 	NEW_SCOPE | 	NEW_SCOPE | ||||||
| 	NEW_MEASURE | 	NEW_MEASURE | ||||||
|   | |||||||
| @@ -65,8 +65,8 @@ func AppendEvent(buf *strings.Builder, data reader.Event) { | |||||||
| 			buf.WriteString(" >") | 			buf.WriteString(" >") | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 	case exporter.FINISH_SPAN: | 	case exporter.END_SPAN: | ||||||
| 		buf.WriteString("finish ") | 		buf.WriteString("end ") | ||||||
| 		buf.WriteString(data.Name) | 		buf.WriteString(data.Name) | ||||||
|  |  | ||||||
| 		buf.WriteString(" (") | 		buf.WriteString(" (") | ||||||
|   | |||||||
| @@ -157,14 +157,14 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) { | |||||||
|  |  | ||||||
| 		ro.scopes.Store(event.Sequence, span) | 		ro.scopes.Store(event.Sequence, span) | ||||||
|  |  | ||||||
| 	case exporter.FINISH_SPAN: | 	case exporter.END_SPAN: | ||||||
| 		attrs, span := ro.readScope(event.Scope) | 		attrs, span := ro.readScope(event.Scope) | ||||||
| 		if span == nil { | 		if span == nil { | ||||||
| 			panic(fmt.Sprint("span not found", event.Scope)) | 			panic(fmt.Sprint("span not found", event.Scope)) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		read.Name = span.name | 		read.Name = span.name | ||||||
| 		read.Type = exporter.FINISH_SPAN | 		read.Type = exporter.END_SPAN | ||||||
|  |  | ||||||
| 		read.Attributes = attrs | 		read.Attributes = attrs | ||||||
| 		read.Duration = event.Time.Sub(span.start) | 		read.Duration = event.Time.Sub(span.start) | ||||||
| @@ -287,7 +287,7 @@ func (ro *readerObserver) orderedObserve(event exporter.Event) { | |||||||
| 		reader.Read(read) | 		reader.Read(read) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if event.Type == exporter.FINISH_SPAN { | 	if event.Type == exporter.END_SPAN { | ||||||
| 		ro.cleanupSpan(event.Scope.EventID) | 		ro.cleanupSpan(event.Scope.EventID) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -58,7 +58,7 @@ func (s *spanReader) Read(data reader.Event) { | |||||||
|  |  | ||||||
| 	span.Events = append(span.Events, data) | 	span.Events = append(span.Events, data) | ||||||
|  |  | ||||||
| 	if data.Type == exporter.FINISH_SPAN { | 	if data.Type == exporter.END_SPAN { | ||||||
| 		for _, r := range s.readers { | 		for _, r := range s.readers { | ||||||
| 			r.Read(span) | 			r.Read(span) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -31,7 +31,7 @@ type span struct { | |||||||
| 	initial exporter.ScopeID | 	initial exporter.ScopeID | ||||||
| } | } | ||||||
|  |  | ||||||
| // SpancContext returns span context of the span. Return SpanContext is usable | // SpanContext returns span context of the span. Returned SpanContext is usable | ||||||
| // even after the span is finished. | // even after the span is finished. | ||||||
| func (sp *span) SpanContext() core.SpanContext { | func (sp *span) SpanContext() core.SpanContext { | ||||||
| 	return sp.initial.SpanContext | 	return sp.initial.SpanContext | ||||||
| @@ -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() | 	recovered := recover() | ||||||
| 	opts := trace.FinishOptions{} | 	opts := trace.EndOptions{} | ||||||
| 	for _, opt := range options { | 	for _, opt := range options { | ||||||
| 		opt(&opts) | 		opt(&opts) | ||||||
| 	} | 	} | ||||||
| 	sp.tracer.exporter.Record(exporter.Event{ | 	sp.tracer.exporter.Record(exporter.Event{ | ||||||
| 		Time:      opts.FinishTime, | 		Time:      opts.EndTime, | ||||||
| 		Type:      exporter.FINISH_SPAN, | 		Type:      exporter.END_SPAN, | ||||||
| 		Scope:     sp.ScopeID(), | 		Scope:     sp.ScopeID(), | ||||||
| 		Recovered: recovered, | 		Recovered: recovered, | ||||||
| 	}) | 	}) | ||||||
|   | |||||||
| @@ -89,7 +89,7 @@ func TestCustomStartEndTime(t *testing.T) { | |||||||
| 		"testspan", | 		"testspan", | ||||||
| 		trace.WithStartTime(startTime), | 		trace.WithStartTime(startTime), | ||||||
| 	) | 	) | ||||||
| 	span.Finish(trace.WithFinishTime(endTime)) | 	span.End(trace.WithEndTime(endTime)) | ||||||
| 	want := []exporter.Event{ | 	want := []exporter.Event{ | ||||||
| 		{ | 		{ | ||||||
| 			Type:   exporter.START_SPAN, | 			Type:   exporter.START_SPAN, | ||||||
| @@ -97,11 +97,11 @@ func TestCustomStartEndTime(t *testing.T) { | |||||||
| 			String: "testspan", | 			String: "testspan", | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Type: exporter.FINISH_SPAN, | 			Type: exporter.END_SPAN, | ||||||
| 			Time: endTime, | 			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") | 	diffEvents(t, got, want, "Scope") | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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/trace.WithRegion for execution tracer support | ||||||
| 	// TODO: use runtime/pprof.Do for profile tags support | 	// TODO: use runtime/pprof.Do for profile tags support | ||||||
| 	ctx, span := t.Start(ctx, name) | 	ctx, span := t.Start(ctx, name) | ||||||
| 	defer span.Finish() | 	defer span.End() | ||||||
|  |  | ||||||
| 	if err := body(ctx); err != nil { | 	if err := body(ctx); err != nil { | ||||||
| 		span.SetAttribute(ErrorKey.Bool(true)) | 		span.SetAttribute(ErrorKey.Bool(true)) | ||||||
|   | |||||||
| @@ -49,14 +49,14 @@ func main() { | |||||||
|  |  | ||||||
| 	ctx, span := apitrace.GlobalTracer().Start(ctx, "/foo") | 	ctx, span := apitrace.GlobalTracer().Start(ctx, "/foo") | ||||||
| 	bar(ctx) | 	bar(ctx) | ||||||
| 	span.Finish() | 	span.End() | ||||||
|  |  | ||||||
| 	exporter.Flush() | 	exporter.Flush() | ||||||
| } | } | ||||||
|  |  | ||||||
| func bar(ctx context.Context) { | func bar(ctx context.Context) { | ||||||
| 	_, span := apitrace.GlobalTracer().Start(ctx, "/bar") | 	_, span := apitrace.GlobalTracer().Start(ctx, "/bar") | ||||||
| 	defer span.Finish() | 	defer span.End() | ||||||
|  |  | ||||||
| 	// Do bar... | 	// Do bar... | ||||||
| } | } | ||||||
|   | |||||||
| @@ -71,8 +71,8 @@ func (ms *MockSpan) ModifyAttribute(mutator tag.Mutator) { | |||||||
| func (ms *MockSpan) ModifyAttributes(mutators ...tag.Mutator) { | func (ms *MockSpan) ModifyAttributes(mutators ...tag.Mutator) { | ||||||
| } | } | ||||||
|  |  | ||||||
| // Finish does nothing. | // End does nothing. | ||||||
| func (ms *MockSpan) Finish(options ...apitrace.FinishOption) { | func (ms *MockSpan) End(options ...apitrace.EndOption) { | ||||||
| } | } | ||||||
|  |  | ||||||
| // SetName does nothing. | // SetName does nothing. | ||||||
|   | |||||||
| @@ -70,7 +70,7 @@ func (ct *clientTracer) close(name string) { | |||||||
| 	ct.mtx.Lock() | 	ct.mtx.Lock() | ||||||
| 	defer ct.mtx.Unlock() | 	defer ct.mtx.Unlock() | ||||||
| 	if s, ok := ct.levels[name]; ok { | 	if s, ok := ct.levels[name]; ok { | ||||||
| 		s.Finish() | 		s.End() | ||||||
| 		delete(ct.levels, name) | 		delete(ct.levels, name) | ||||||
| 	} else { | 	} else { | ||||||
| 		panic(fmt.Sprintf("failed to find span %s in levels.", name)) | 		panic(fmt.Sprintf("failed to find span %s in levels.", name)) | ||||||
|   | |||||||
| @@ -30,7 +30,7 @@ func BenchmarkStartEndSpan(b *testing.B) { | |||||||
| 		b.ResetTimer() | 		b.ResetTimer() | ||||||
| 		for i := 0; i < b.N; i++ { | 		for i := 0; i < b.N; i++ { | ||||||
| 			_, span := t.Start(ctx, "/foo") | 			_, span := t.Start(ctx, "/foo") | ||||||
| 			span.Finish() | 			span.End() | ||||||
| 		} | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| @@ -50,7 +50,7 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) { | |||||||
| 				key.New("key3").Uint64(123), | 				key.New("key3").Uint64(123), | ||||||
| 				key.New("key4").Float64(123.456), | 				key.New("key4").Float64(123.456), | ||||||
| 			) | 			) | ||||||
| 			span.Finish() | 			span.End() | ||||||
| 		} | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| @@ -74,7 +74,7 @@ func BenchmarkSpanWithAttributes_8(b *testing.B) { | |||||||
| 				key.New("key23").Uint64(123), | 				key.New("key23").Uint64(123), | ||||||
| 				key.New("key24").Float64(123.456), | 				key.New("key24").Float64(123.456), | ||||||
| 			) | 			) | ||||||
| 			span.Finish() | 			span.End() | ||||||
| 		} | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| @@ -101,7 +101,7 @@ func BenchmarkSpanWithAttributes_all(b *testing.B) { | |||||||
| 				key.New("key10").Int(123), | 				key.New("key10").Int(123), | ||||||
| 				key.New("key11").Uint(123), | 				key.New("key11").Uint(123), | ||||||
| 			) | 			) | ||||||
| 			span.Finish() | 			span.End() | ||||||
| 		} | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| @@ -138,7 +138,7 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) { | |||||||
| 				key.New("key210").Int(123), | 				key.New("key210").Int(123), | ||||||
| 				key.New("key211").Uint(123), | 				key.New("key211").Uint(123), | ||||||
| 			) | 			) | ||||||
| 			span.Finish() | 			span.End() | ||||||
| 		} | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ import ( | |||||||
| func ExampleStart() { | func ExampleStart() { | ||||||
| 	printEvens := func(ctx context.Context) { | 	printEvens := func(ctx context.Context) { | ||||||
| 		_, span := trace.GlobalTracer().Start(ctx, "my/package.Function") | 		_, span := trace.GlobalTracer().Start(ctx, "my/package.Function") | ||||||
| 		defer span.Finish() | 		defer span.End() | ||||||
|  |  | ||||||
| 		for i := 0; i < 10; i++ { | 		for i := 0; i < 10; i++ { | ||||||
| 			if i%2 == 0 { | 			if i%2 == 0 { | ||||||
|   | |||||||
| @@ -67,7 +67,7 @@ func TestSimpleSpanProcessorOnEnd(t *testing.T) { | |||||||
| 		TraceFlags: 0x1, | 		TraceFlags: 0x1, | ||||||
| 	} | 	} | ||||||
| 	_, span := apitrace.GlobalTracer().Start(context.Background(), "OnEnd", apitrace.ChildOf(sc)) | 	_, span := apitrace.GlobalTracer().Start(context.Background(), "OnEnd", apitrace.ChildOf(sc)) | ||||||
| 	span.Finish() | 	span.End() | ||||||
|  |  | ||||||
| 	wantTraceID := tid | 	wantTraceID := tid | ||||||
| 	gotTraceID := te.spans[0].SpanContext.TraceID | 	gotTraceID := te.spans[0].SpanContext.TraceID | ||||||
|   | |||||||
| @@ -106,7 +106,7 @@ func (s *span) ModifyAttribute(mutator apitag.Mutator) { | |||||||
| func (s *span) ModifyAttributes(mutators ...apitag.Mutator) { | func (s *span) ModifyAttributes(mutators ...apitag.Mutator) { | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *span) Finish(options ...apitrace.FinishOption) { | func (s *span) End(options ...apitrace.EndOption) { | ||||||
| 	if s == nil { | 	if s == nil { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| @@ -117,7 +117,7 @@ func (s *span) Finish(options ...apitrace.FinishOption) { | |||||||
| 	if !s.IsRecordingEvents() { | 	if !s.IsRecordingEvents() { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	opts := apitrace.FinishOptions{} | 	opts := apitrace.EndOptions{} | ||||||
| 	for _, opt := range options { | 	for _, opt := range options { | ||||||
| 		opt(&opts) | 		opt(&opts) | ||||||
| 	} | 	} | ||||||
| @@ -129,10 +129,10 @@ func (s *span) Finish(options ...apitrace.FinishOption) { | |||||||
| 		// of processors. Exporter will export based on sampling. | 		// of processors. Exporter will export based on sampling. | ||||||
| 		if mustExportOrProcess { | 		if mustExportOrProcess { | ||||||
| 			sd := s.makeSpanData() | 			sd := s.makeSpanData() | ||||||
| 			if opts.FinishTime.IsZero() { | 			if opts.EndTime.IsZero() { | ||||||
| 				sd.EndTime = internal.MonotonicEndTime(sd.StartTime) | 				sd.EndTime = internal.MonotonicEndTime(sd.StartTime) | ||||||
| 			} else { | 			} else { | ||||||
| 				sd.EndTime = opts.FinishTime | 				sd.EndTime = opts.EndTime | ||||||
| 			} | 			} | ||||||
| 			// Sampling check would be in the processor if the processor is used for exporting. | 			// Sampling check would be in the processor if the processor is used for exporting. | ||||||
| 			if s.spanContext.IsSampled() { | 			if s.spanContext.IsSampled() { | ||||||
|   | |||||||
| @@ -51,7 +51,7 @@ func TestRegisterSpanProcessort(t *testing.T) { | |||||||
| 	sdktrace.RegisterSpanProcessor(sp) | 	sdktrace.RegisterSpanProcessor(sp) | ||||||
| 	defer sdktrace.UnregisterSpanProcessor(sp) | 	defer sdktrace.UnregisterSpanProcessor(sp) | ||||||
| 	_, span := apitrace.GlobalTracer().Start(context.Background(), "OnStart") | 	_, span := apitrace.GlobalTracer().Start(context.Background(), "OnStart") | ||||||
| 	span.Finish() | 	span.End() | ||||||
| 	wantCount := 1 | 	wantCount := 1 | ||||||
| 	gotCount := len(sp.spansStarted) | 	gotCount := len(sp.spansStarted) | ||||||
| 	if gotCount != wantCount { | 	if gotCount != wantCount { | ||||||
| @@ -68,12 +68,12 @@ func TestUnregisterSpanProcessor(t *testing.T) { | |||||||
| 	sp := NewTestSpanProcessor() | 	sp := NewTestSpanProcessor() | ||||||
| 	sdktrace.RegisterSpanProcessor(sp) | 	sdktrace.RegisterSpanProcessor(sp) | ||||||
| 	_, span := apitrace.GlobalTracer().Start(context.Background(), "OnStart") | 	_, span := apitrace.GlobalTracer().Start(context.Background(), "OnStart") | ||||||
| 	span.Finish() | 	span.End() | ||||||
| 	sdktrace.UnregisterSpanProcessor(sp) | 	sdktrace.UnregisterSpanProcessor(sp) | ||||||
|  |  | ||||||
| 	// start another span after unregistering span processor. | 	// start another span after unregistering span processor. | ||||||
| 	_, span = apitrace.GlobalTracer().Start(context.Background(), "Start span after unregister") | 	_, span = apitrace.GlobalTracer().Start(context.Background(), "Start span after unregister") | ||||||
| 	span.Finish() | 	span.End() | ||||||
|  |  | ||||||
| 	wantCount := 1 | 	wantCount := 1 | ||||||
| 	gotCount := len(sp.spansStarted) | 	gotCount := len(sp.spansStarted) | ||||||
| @@ -94,7 +94,7 @@ func TestUnregisterSpanProcessorWhileSpanIsActive(t *testing.T) { | |||||||
| 	_, span := apitrace.GlobalTracer().Start(context.Background(), "OnStart") | 	_, span := apitrace.GlobalTracer().Start(context.Background(), "OnStart") | ||||||
| 	sdktrace.UnregisterSpanProcessor(sp) | 	sdktrace.UnregisterSpanProcessor(sp) | ||||||
|  |  | ||||||
| 	span.Finish() | 	span.End() | ||||||
|  |  | ||||||
| 	wantCount := 1 | 	wantCount := 1 | ||||||
| 	gotCount := len(sp.spansStarted) | 	gotCount := len(sp.spansStarted) | ||||||
|   | |||||||
| @@ -55,7 +55,7 @@ func (t *testExporter) ExportSpan(s *SpanData) { | |||||||
|  |  | ||||||
| func TestStartSpan(t *testing.T) { | func TestStartSpan(t *testing.T) { | ||||||
| 	_, span := apitrace.GlobalTracer().Start(context.Background(), "StartSpan") | 	_, span := apitrace.GlobalTracer().Start(context.Background(), "StartSpan") | ||||||
| 	defer span.Finish() | 	defer span.End() | ||||||
| 	if span == nil { | 	if span == nil { | ||||||
| 		t.Errorf("span not started") | 		t.Errorf("span not started") | ||||||
| 	} | 	} | ||||||
| @@ -118,13 +118,13 @@ func TestSetName(t *testing.T) { | |||||||
| 		if gotSampledAfter := span.SpanContext().IsSampled(); tt.sampledAfter != gotSampledAfter { | 		if gotSampledAfter := span.SpanContext().IsSampled(); tt.sampledAfter != gotSampledAfter { | ||||||
| 			t.Errorf("%d: invalid sampling decision after rename, expected %v, got %v", idx, tt.sampledAfter, gotSampledAfter) | 			t.Errorf("%d: invalid sampling decision after rename, expected %v, got %v", idx, tt.sampledAfter, gotSampledAfter) | ||||||
| 		} | 		} | ||||||
| 		span.Finish() | 		span.End() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestRecordingIsOff(t *testing.T) { | func TestRecordingIsOff(t *testing.T) { | ||||||
| 	_, span := apitrace.GlobalTracer().Start(context.Background(), "StartSpan") | 	_, span := apitrace.GlobalTracer().Start(context.Background(), "StartSpan") | ||||||
| 	defer span.Finish() | 	defer span.End() | ||||||
| 	if span.IsRecordingEvents() == true { | 	if span.IsRecordingEvents() == true { | ||||||
| 		t.Error("new span is recording events") | 		t.Error("new span is recording events") | ||||||
| 	} | 	} | ||||||
| @@ -562,7 +562,7 @@ func endSpan(span apitrace.Span) (*SpanData, error) { | |||||||
| 	} | 	} | ||||||
| 	var te testExporter | 	var te testExporter | ||||||
| 	RegisterExporter(&te) | 	RegisterExporter(&te) | ||||||
| 	span.Finish() | 	span.End() | ||||||
| 	UnregisterExporter(&te) | 	UnregisterExporter(&te) | ||||||
| 	if len(te.spans) != 1 { | 	if len(te.spans) != 1 { | ||||||
| 		return nil, fmt.Errorf("got exported spans %#v, want one span", te.spans) | 		return nil, fmt.Errorf("got exported spans %#v, want one span", te.spans) | ||||||
| @@ -601,8 +601,8 @@ func TestEndSpanTwice(t *testing.T) { | |||||||
| 	RegisterExporter(&spans) | 	RegisterExporter(&spans) | ||||||
| 	defer UnregisterExporter(&spans) | 	defer UnregisterExporter(&spans) | ||||||
| 	span := startSpan() | 	span := startSpan() | ||||||
| 	span.Finish() | 	span.End() | ||||||
| 	span.Finish() | 	span.End() | ||||||
| 	UnregisterExporter(&spans) | 	UnregisterExporter(&spans) | ||||||
| 	if len(spans) != 1 { | 	if len(spans) != 1 { | ||||||
| 		t.Fatalf("expected only a single span, got %#v", spans) | 		t.Fatalf("expected only a single span, got %#v", spans) | ||||||
| @@ -615,12 +615,12 @@ func TestStartSpanAfterEnd(t *testing.T) { | |||||||
| 	defer UnregisterExporter(&spans) | 	defer UnregisterExporter(&spans) | ||||||
| 	ctx, span0 := apitrace.GlobalTracer().Start(context.Background(), "parent", apitrace.ChildOf(remoteSpanContext())) | 	ctx, span0 := apitrace.GlobalTracer().Start(context.Background(), "parent", apitrace.ChildOf(remoteSpanContext())) | ||||||
| 	ctx1, span1 := apitrace.GlobalTracer().Start(ctx, "span-1") | 	ctx1, span1 := apitrace.GlobalTracer().Start(ctx, "span-1") | ||||||
| 	span1.Finish() | 	span1.End() | ||||||
| 	// Start a new span with the context containing span-1 | 	// Start a new span with the context containing span-1 | ||||||
| 	// even though span-1 is ended, we still add this as a new child of span-1 | 	// even though span-1 is ended, we still add this as a new child of span-1 | ||||||
| 	_, span2 := apitrace.GlobalTracer().Start(ctx1, "span-2") | 	_, span2 := apitrace.GlobalTracer().Start(ctx1, "span-2") | ||||||
| 	span2.Finish() | 	span2.End() | ||||||
| 	span0.Finish() | 	span0.End() | ||||||
| 	UnregisterExporter(&spans) | 	UnregisterExporter(&spans) | ||||||
| 	if got, want := len(spans), 3; got != want { | 	if got, want := len(spans), 3; got != want { | ||||||
| 		t.Fatalf("len(%#v) = %d; want %d", spans, got, want) | 		t.Fatalf("len(%#v) = %d; want %d", spans, got, want) | ||||||
| @@ -647,12 +647,12 @@ func TestChildSpanCount(t *testing.T) { | |||||||
| 	ctx, span0 := apitrace.GlobalTracer().Start(context.Background(), "parent") | 	ctx, span0 := apitrace.GlobalTracer().Start(context.Background(), "parent") | ||||||
| 	ctx1, span1 := apitrace.GlobalTracer().Start(ctx, "span-1") | 	ctx1, span1 := apitrace.GlobalTracer().Start(ctx, "span-1") | ||||||
| 	_, span2 := apitrace.GlobalTracer().Start(ctx1, "span-2") | 	_, span2 := apitrace.GlobalTracer().Start(ctx1, "span-2") | ||||||
| 	span2.Finish() | 	span2.End() | ||||||
| 	span1.Finish() | 	span1.End() | ||||||
|  |  | ||||||
| 	_, span3 := apitrace.GlobalTracer().Start(ctx, "span-3") | 	_, span3 := apitrace.GlobalTracer().Start(ctx, "span-3") | ||||||
| 	span3.Finish() | 	span3.End() | ||||||
| 	span0.Finish() | 	span0.End() | ||||||
| 	UnregisterExporter(&spans) | 	UnregisterExporter(&spans) | ||||||
| 	if got, want := len(spans), 4; got != want { | 	if got, want := len(spans), 4; got != want { | ||||||
| 		t.Fatalf("len(%#v) = %d; want %d", spans, got, want) | 		t.Fatalf("len(%#v) = %d; want %d", spans, got, want) | ||||||
| @@ -671,9 +671,9 @@ func TestChildSpanCount(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestNilSpanFinish(t *testing.T) { | func TestNilSpanEnd(t *testing.T) { | ||||||
| 	var span *span | 	var span *span | ||||||
| 	span.Finish() | 	span.End() | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestExecutionTracerTaskEnd(t *testing.T) { | func TestExecutionTracerTaskEnd(t *testing.T) { | ||||||
| @@ -712,7 +712,7 @@ func TestExecutionTracerTaskEnd(t *testing.T) { | |||||||
| 	spans = append(spans, s) // always sample | 	spans = append(spans, s) // always sample | ||||||
|  |  | ||||||
| 	for _, span := range spans { | 	for _, span := range spans { | ||||||
| 		span.Finish() | 		span.End() | ||||||
| 	} | 	} | ||||||
| 	if got, want := n, uint64(len(spans)); got != want { | 	if got, want := n, uint64(len(spans)); got != want { | ||||||
| 		t.Fatalf("Execution tracer task ended for %v spans; want %v", got, want) | 		t.Fatalf("Execution tracer task ended for %v spans; want %v", got, want) | ||||||
| @@ -729,7 +729,7 @@ func TestCustomStartEndTime(t *testing.T) { | |||||||
| 	) | 	) | ||||||
| 	var te testExporter | 	var te testExporter | ||||||
| 	RegisterExporter(&te) | 	RegisterExporter(&te) | ||||||
| 	span.Finish(apitrace.WithFinishTime(endTime)) | 	span.End(apitrace.WithEndTime(endTime)) | ||||||
| 	UnregisterExporter(&te) | 	UnregisterExporter(&te) | ||||||
| 	if len(te.spans) != 1 { | 	if len(te.spans) != 1 { | ||||||
| 		t.Fatalf("got exported spans %#v, want one span", te.spans) | 		t.Fatalf("got exported spans %#v, want one span", te.spans) | ||||||
|   | |||||||
| @@ -76,7 +76,7 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti | |||||||
|  |  | ||||||
| func (tr *tracer) WithSpan(ctx context.Context, name string, body func(ctx context.Context) error) error { | func (tr *tracer) WithSpan(ctx context.Context, name string, body func(ctx context.Context) error) error { | ||||||
| 	ctx, span := tr.Start(ctx, name) | 	ctx, span := tr.Start(ctx, name) | ||||||
| 	defer span.Finish() | 	defer span.End() | ||||||
|  |  | ||||||
| 	if err := body(ctx); err != nil { | 	if err := body(ctx); err != nil { | ||||||
| 		// TODO: set event with boolean attribute for error. | 		// TODO: set event with boolean attribute for error. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user