mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 12:51:55 +00:00
honey: add read locking to event.Fields call for NonSendingReader (#61886)
The documentation for fields already says that the returned map is not safe for concurrent modification. However, I realized the variable assignment for the map should to be protected by a lock itself too. commit-id:9c5542b1
This commit is contained in:
parent
9fab1b4e1d
commit
44bf2c4883
@ -16,7 +16,7 @@ func NonSendingEvent() Event {
|
||||
// Honeycomb, but instead aggregates it in memory. This is useful for testing and
|
||||
// logging purposes.
|
||||
type nonSendingEvent struct {
|
||||
fieldsWritingMu sync.Mutex
|
||||
fieldsWritingMu sync.RWMutex
|
||||
fields map[string]any
|
||||
}
|
||||
|
||||
@ -57,6 +57,9 @@ func (e *nonSendingEvent) AddAttributes(values []attribute.KeyValue) {
|
||||
// Fields returns all the added fields of the event. The returned map is not safe to
|
||||
// be modified concurrently with calls to AddField or AddAttributes.
|
||||
func (e *nonSendingEvent) Fields() map[string]any {
|
||||
e.fieldsWritingMu.RLock()
|
||||
defer e.fieldsWritingMu.RUnlock()
|
||||
|
||||
return e.fields
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user