Skip to content
Closed
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
8 changes: 4 additions & 4 deletions internal/global/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type meterProvider struct {
delegate metric.MeterProvider

// lock protects `delegate` and `meters`.
lock sync.Mutex
lock sync.RWMutex

// meters maintains a unique entry for every named Meter
// that has been registered through the global instance.
Expand All @@ -65,7 +65,7 @@ type meterProvider struct {
type meterImpl struct {
delegate unsafe.Pointer // (*metric.MeterImpl)

lock sync.Mutex
lock sync.RWMutex
syncInsts []*syncImpl
asyncInsts []*asyncImpl
}
Expand Down Expand Up @@ -144,8 +144,8 @@ func (p *meterProvider) setDelegate(provider metric.MeterProvider) {
}

func (p *meterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
p.lock.Lock()
defer p.lock.Unlock()
p.lock.RLock()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method can modify p.meters, so should this not be a read lock?

defer p.lock.RUnlock()

if p.delegate != nil {
return p.delegate.Meter(instrumentationName, opts...)
Expand Down
58 changes: 29 additions & 29 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var emptySpanContext = trace.SpanContext{}
// individual component of a trace.
type span struct {
// mu protects the contents of this span.
mu sync.Mutex
mu sync.RWMutex

// parent holds the parent span of this span as a trace.SpanContext.
parent trace.SpanContext
Expand Down Expand Up @@ -148,8 +148,8 @@ func (s *span) IsRecording() bool {
if s == nil {
return false
}
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.endTime.IsZero()
}

Expand Down Expand Up @@ -308,83 +308,83 @@ func (s *span) SetName(name string) {
}

func (s *span) Name() string {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.name
}

func (s *span) Parent() trace.SpanContext {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.parent
}

func (s *span) SpanKind() trace.SpanKind {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.spanKind
}

func (s *span) StartTime() time.Time {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.startTime
}

func (s *span) EndTime() time.Time {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.endTime
}

func (s *span) Attributes() []label.KeyValue {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
if s.attributes.evictList.Len() == 0 {
return []label.KeyValue{}
}
return s.attributes.toKeyValue()
}

func (s *span) Links() []trace.Link {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
if len(s.links.queue) == 0 {
return []trace.Link{}
}
return s.interfaceArrayToLinksArray()
}

func (s *span) Events() []trace.Event {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
if len(s.messageEvents.queue) == 0 {
return []trace.Event{}
}
return s.interfaceArrayToMessageEventArray()
}

func (s *span) StatusCode() codes.Code {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.statusCode
}

func (s *span) StatusMessage() string {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.statusMessage
}

func (s *span) InstrumentationLibrary() instrumentation.Library {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.instrumentationLibrary
}

func (s *span) Resource() *resource.Resource {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.resource
}

Expand All @@ -401,8 +401,8 @@ func (s *span) addLink(link trace.Link) {
// export.SpanSnapshot and returns a pointer to it.
func (s *span) Snapshot() *export.SpanSnapshot {
var sd export.SpanSnapshot
s.mu.Lock()
defer s.mu.Unlock()
s.mu.RLock()
defer s.mu.RUnlock()

sd.ChildSpanCount = s.childSpanCount
sd.EndTime = s.endTime
Expand Down