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 
			
		
		
		
	use EmptySpanContext function instead of global variable (#86)
This commit is contained in:
		| @@ -38,11 +38,10 @@ type SpanContext struct { | ||||
| 	TraceOptions byte | ||||
| } | ||||
|  | ||||
| var ( | ||||
| 	// INVALID_SPAN_CONTEXT is meant for internal use to return invalid span context during error | ||||
| 	// conditions. | ||||
| 	INVALID_SPAN_CONTEXT = SpanContext{} | ||||
| ) | ||||
| // EmptySpanContext is meant for internal use to return invalid span context during error conditions. | ||||
| func EmptySpanContext() SpanContext { | ||||
| 	return SpanContext{} | ||||
| } | ||||
|  | ||||
| func (sc SpanContext) IsValid() bool { | ||||
| 	return sc.HasTraceID() && sc.HasSpanID() | ||||
|   | ||||
| @@ -31,7 +31,7 @@ var _ Span = (*noopSpan)(nil) | ||||
|  | ||||
| // SpancContext returns an invalid span context. | ||||
| func (noopSpan) SpanContext() core.SpanContext { | ||||
| 	return core.INVALID_SPAN_CONTEXT | ||||
| 	return core.EmptySpanContext() | ||||
| } | ||||
|  | ||||
| // IsRecordingEvents always returns false for noopSpan. | ||||
|   | ||||
| @@ -60,7 +60,7 @@ var _ apitrace.Span = &span{} | ||||
|  | ||||
| func (s *span) SpanContext() core.SpanContext { | ||||
| 	if s == nil { | ||||
| 		return core.INVALID_SPAN_CONTEXT | ||||
| 		return core.EmptySpanContext() | ||||
| 	} | ||||
| 	return s.spanContext | ||||
| } | ||||
| @@ -225,7 +225,7 @@ func startSpanInternal(name string, parent core.SpanContext, remoteParent bool, | ||||
|  | ||||
| 	cfg := config.Load().(*Config) | ||||
|  | ||||
| 	if parent == core.INVALID_SPAN_CONTEXT { | ||||
| 	if parent == core.EmptySpanContext() { | ||||
| 		span.spanContext.TraceID = cfg.IDGenerator.NewTraceID() | ||||
| 		noParent = true | ||||
| 	} | ||||
|   | ||||
| @@ -46,7 +46,7 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti | ||||
| 	// 2. Remote is not trusted. In this case create a root span and then add the remote as link | ||||
| 	//      span := tracer.Start(ctx, "some name") | ||||
| 	//      span.Link(remote_span_context, ChildOfRelationship) | ||||
| 	if opts.Reference.SpanContext != core.INVALID_SPAN_CONTEXT && | ||||
| 	if opts.Reference.SpanContext != core.EmptySpanContext() && | ||||
| 		opts.Reference.RelationshipType == apitrace.ChildOfRelationship { | ||||
| 		parent = opts.Reference.SpanContext | ||||
| 		remoteParent = true | ||||
|   | ||||
		Reference in New Issue
	
	Block a user