You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-09-16 09:26:25 +02:00
Do not store TracerProvider or Tracer fields in SDK recordingSpan (#2575)
* Do not store TracerProvider fields in span Instead of keeping a reference to the span's Tracer, and therefore also it's TracerProvider, and the associated resource and spanLimits just keep the reference to the Tracer. Refer to the TracerProvider fields when needed instead. * Make span refer to the inst lib via the Tracer Instead of holding a field in the span, refer to the field in the parent Tracer.
This commit is contained in:
@@ -74,10 +74,13 @@ type TracerProvider struct {
|
||||
mu sync.Mutex
|
||||
namedTracer map[instrumentation.Library]*tracer
|
||||
spanProcessors atomic.Value
|
||||
sampler Sampler
|
||||
idGenerator IDGenerator
|
||||
spanLimits SpanLimits
|
||||
resource *resource.Resource
|
||||
|
||||
// These fields are not protected by the lock mu. They are assumed to be
|
||||
// immutable after creation of the TracerProvider.
|
||||
sampler Sampler
|
||||
idGenerator IDGenerator
|
||||
spanLimits SpanLimits
|
||||
resource *resource.Resource
|
||||
}
|
||||
|
||||
var _ trace.TracerProvider = &TracerProvider{}
|
||||
|
@@ -126,14 +126,6 @@ type recordingSpan struct {
|
||||
// childSpanCount holds the number of child spans created for this span.
|
||||
childSpanCount int
|
||||
|
||||
// resource contains attributes representing an entity that produced this
|
||||
// span.
|
||||
resource *resource.Resource
|
||||
|
||||
// instrumentationLibrary defines the instrumentation library used to
|
||||
// provide instrumentation.
|
||||
instrumentationLibrary instrumentation.Library
|
||||
|
||||
// spanContext holds the SpanContext of this span.
|
||||
spanContext trace.SpanContext
|
||||
|
||||
@@ -152,9 +144,6 @@ type recordingSpan struct {
|
||||
|
||||
// tracer is the SDK tracer that created this span.
|
||||
tracer *tracer
|
||||
|
||||
// spanLimits holds the limits to this span.
|
||||
spanLimits SpanLimits
|
||||
}
|
||||
|
||||
var _ ReadWriteSpan = (*recordingSpan)(nil)
|
||||
@@ -336,9 +325,9 @@ func (s *recordingSpan) addEvent(name string, o ...trace.EventOption) {
|
||||
// Discard over limited attributes
|
||||
attributes := c.Attributes()
|
||||
var discarded int
|
||||
if len(attributes) > s.spanLimits.AttributePerEventCountLimit {
|
||||
discarded = len(attributes) - s.spanLimits.AttributePerEventCountLimit
|
||||
attributes = attributes[:s.spanLimits.AttributePerEventCountLimit]
|
||||
if len(attributes) > s.tracer.provider.spanLimits.AttributePerEventCountLimit {
|
||||
discarded = len(attributes) - s.tracer.provider.spanLimits.AttributePerEventCountLimit
|
||||
attributes = attributes[:s.tracer.provider.spanLimits.AttributePerEventCountLimit]
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
@@ -440,7 +429,7 @@ func (s *recordingSpan) Status() Status {
|
||||
func (s *recordingSpan) InstrumentationLibrary() instrumentation.Library {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.instrumentationLibrary
|
||||
return s.tracer.instrumentationLibrary
|
||||
}
|
||||
|
||||
// Resource returns the Resource associated with the Tracer that created this
|
||||
@@ -448,7 +437,7 @@ func (s *recordingSpan) InstrumentationLibrary() instrumentation.Library {
|
||||
func (s *recordingSpan) Resource() *resource.Resource {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.resource
|
||||
return s.tracer.provider.resource
|
||||
}
|
||||
|
||||
func (s *recordingSpan) addLink(link trace.Link) {
|
||||
@@ -461,9 +450,9 @@ func (s *recordingSpan) addLink(link trace.Link) {
|
||||
var droppedAttributeCount int
|
||||
|
||||
// Discard over limited attributes
|
||||
if len(link.Attributes) > s.spanLimits.AttributePerLinkCountLimit {
|
||||
droppedAttributeCount = len(link.Attributes) - s.spanLimits.AttributePerLinkCountLimit
|
||||
link.Attributes = link.Attributes[:s.spanLimits.AttributePerLinkCountLimit]
|
||||
if len(link.Attributes) > s.tracer.provider.spanLimits.AttributePerLinkCountLimit {
|
||||
droppedAttributeCount = len(link.Attributes) - s.tracer.provider.spanLimits.AttributePerLinkCountLimit
|
||||
link.Attributes = link.Attributes[:s.tracer.provider.spanLimits.AttributePerLinkCountLimit]
|
||||
}
|
||||
|
||||
s.links.add(Link{link.SpanContext, link.Attributes, droppedAttributeCount})
|
||||
@@ -514,10 +503,10 @@ func (s *recordingSpan) snapshot() ReadOnlySpan {
|
||||
defer s.mu.Unlock()
|
||||
|
||||
sd.endTime = s.endTime
|
||||
sd.instrumentationLibrary = s.instrumentationLibrary
|
||||
sd.instrumentationLibrary = s.tracer.instrumentationLibrary
|
||||
sd.name = s.name
|
||||
sd.parent = s.parent
|
||||
sd.resource = s.resource
|
||||
sd.resource = s.tracer.provider.resource
|
||||
sd.spanContext = s.spanContext
|
||||
sd.spanKind = s.spanKind
|
||||
sd.startTime = s.startTime
|
||||
|
@@ -122,18 +122,15 @@ func (tr *tracer) newRecordingSpan(psc, sc trace.SpanContext, name string, sr Sa
|
||||
}
|
||||
|
||||
s := &recordingSpan{
|
||||
parent: psc,
|
||||
spanContext: sc,
|
||||
spanKind: trace.ValidateSpanKind(config.SpanKind()),
|
||||
name: name,
|
||||
startTime: startTime,
|
||||
attributes: newAttributesMap(tr.provider.spanLimits.AttributeCountLimit),
|
||||
events: newEvictedQueue(tr.provider.spanLimits.EventCountLimit),
|
||||
links: newEvictedQueue(tr.provider.spanLimits.LinkCountLimit),
|
||||
tracer: tr,
|
||||
spanLimits: tr.provider.spanLimits,
|
||||
resource: tr.provider.resource,
|
||||
instrumentationLibrary: tr.instrumentationLibrary,
|
||||
parent: psc,
|
||||
spanContext: sc,
|
||||
spanKind: trace.ValidateSpanKind(config.SpanKind()),
|
||||
name: name,
|
||||
startTime: startTime,
|
||||
attributes: newAttributesMap(tr.provider.spanLimits.AttributeCountLimit),
|
||||
events: newEvictedQueue(tr.provider.spanLimits.EventCountLimit),
|
||||
links: newEvictedQueue(tr.provider.spanLimits.LinkCountLimit),
|
||||
tracer: tr,
|
||||
}
|
||||
|
||||
for _, l := range config.Links() {
|
||||
|
Reference in New Issue
Block a user