Skip to content

Commit

Permalink
fix: lock attributes when marshalling/unmarshalling (#3374)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira authored Nov 17, 2023
1 parent 7ab73c3 commit 45b28f1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/traces/span_entitiess.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,19 @@ func (a *Attributes) unlock() {
}

func (a Attributes) MarshalJSON() ([]byte, error) {
a.lock()
defer a.unlock()

return json.Marshal(a.values)
}

func (a *Attributes) UnmarshalJSON(in []byte) error {
a.mutex = &sync.Mutex{}
if a.mutex == nil {
a.mutex = &sync.Mutex{}
}
a.lock()
defer a.unlock()

a.values = make(map[string]string, 0)

return json.Unmarshal(in, &a.values)
Expand Down

0 comments on commit 45b28f1

Please sign in to comment.