Skip to content

Commit a606839

Browse files
thinkerourghetia
authored andcommitted
use function instead of global var (open-telemetry#36)
* use function instead of global var * fix lack return
1 parent 252c6b5 commit a606839

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

api/tag/api.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ type Map interface {
3535

3636
type Option func(*registeredKey)
3737

38-
var (
39-
EmptyMap = NewMap(core.KeyValue{}, nil, core.Mutator{}, nil)
40-
)
41-
4238
func New(name string, opts ...Option) core.Key { // TODO rename NewKey?
4339
return register(name, opts)
4440
}
@@ -49,6 +45,11 @@ func NewMeasure(name string, opts ...Option) core.Measure {
4945
}
5046
}
5147

48+
func NewEmptyMap() Map {
49+
var t tagMap
50+
return t.Apply(core.KeyValue{}, nil, core.Mutator{}, nil)
51+
}
52+
5253
func NewMap(a1 core.KeyValue, attributes []core.KeyValue, m1 core.Mutator, mutators []core.Mutator) Map {
5354
var t tagMap
5455
return t.Apply(a1, attributes, m1, mutators)

exporter/reader/reader.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func (ro *readerObserver) Observe(event observer.Event) {
126126
read := Event{
127127
Time: event.Time,
128128
Sequence: event.Sequence,
129-
Attributes: tag.EmptyMap,
130-
Tags: tag.EmptyMap,
129+
Attributes: tag.NewEmptyMap(),
130+
Tags: tag.NewEmptyMap(),
131131
}
132132

133133
if event.Context != nil {
@@ -201,7 +201,7 @@ func (ro *readerObserver) Observe(event observer.Event) {
201201
sid = event.Scope
202202
}
203203
if sid.EventID == 0 {
204-
m = tag.EmptyMap
204+
m = tag.NewEmptyMap()
205205
} else {
206206
parentI, has := ro.scopes.Load(sid.EventID)
207207
if !has {
@@ -316,7 +316,7 @@ func (ro *readerObserver) addMeasurement(e *Event, m core.Measurement) {
316316

317317
func (ro *readerObserver) readScope(id core.ScopeID) (tag.Map, *readerSpan) {
318318
if id.EventID == 0 {
319-
return tag.EmptyMap, nil
319+
return tag.NewEmptyMap(), nil
320320
}
321321
ev, has := ro.scopes.Load(id.EventID)
322322
if !has {
@@ -327,7 +327,7 @@ func (ro *readerObserver) readScope(id core.ScopeID) (tag.Map, *readerSpan) {
327327
} else if sp, ok := ev.(*readerSpan); ok {
328328
return sp.attributes, sp
329329
}
330-
return tag.EmptyMap, nil
330+
return tag.NewEmptyMap(), nil
331331
}
332332

333333
func (ro *readerObserver) cleanupSpan(id core.EventID) {

0 commit comments

Comments
 (0)