mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-04 09:43:23 +02:00
Update concurrency support in test Handlers
This commit is contained in:
parent
8c5b1663a2
commit
e73d119d6c
@ -39,19 +39,22 @@ import (
|
||||
|
||||
var testResource = resource.New(kv.String("R", "V"))
|
||||
|
||||
type handler struct{ err error }
|
||||
|
||||
func (h *handler) Handle(err error) {
|
||||
h.err = err
|
||||
type handler struct {
|
||||
sync.Mutex
|
||||
err error
|
||||
}
|
||||
|
||||
func (h *handler) Reset() {
|
||||
h.err = nil
|
||||
func (h *handler) Handle(err error) {
|
||||
h.Lock()
|
||||
h.err = err
|
||||
h.Unlock()
|
||||
}
|
||||
|
||||
func (h *handler) Flush() error {
|
||||
h.Lock()
|
||||
err := h.err
|
||||
h.Reset()
|
||||
h.err = nil
|
||||
h.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
@ -40,19 +41,28 @@ import (
|
||||
var Must = metric.Must
|
||||
var testResource = resource.New(kv.String("R", "V"))
|
||||
|
||||
type handler struct{ err error }
|
||||
type handler struct {
|
||||
sync.Mutex
|
||||
err error
|
||||
}
|
||||
|
||||
func (h *handler) Handle(err error) {
|
||||
h.Lock()
|
||||
h.err = err
|
||||
h.Unlock()
|
||||
}
|
||||
|
||||
func (h *handler) Reset() {
|
||||
h.Lock()
|
||||
h.err = nil
|
||||
h.Unlock()
|
||||
}
|
||||
|
||||
func (h *handler) Flush() error {
|
||||
h.Lock()
|
||||
err := h.err
|
||||
h.Reset()
|
||||
h.err = nil
|
||||
h.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ package trace
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
@ -201,12 +202,14 @@ func (s *span) addEventWithTimestamp(timestamp time.Time, name string, attrs ...
|
||||
})
|
||||
}
|
||||
|
||||
var errUninitializedSpan = errors.New("failed to set name on uninitialized span")
|
||||
|
||||
func (s *span) SetName(name string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if s.data == nil {
|
||||
global.Handle(fmt.Errorf("failed to set name on uninitialized span: %#v", s))
|
||||
global.Handle(errUninitializedSpan)
|
||||
return
|
||||
}
|
||||
s.data.Name = name
|
||||
|
Loading…
Reference in New Issue
Block a user