Skip to content

Commit

Permalink
Implement updated ForeachBaggageItem from OpenTracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuri Shkuro committed Jun 30, 2016
1 parent 9e26371 commit ff8409d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import:
subpackages:
- lib/go/thrift
- package: github.com/opentracing/opentracing-go
version: 01498abd158dfdbe8e251856bc7d14cb0f046fa3
version: d5b9be1fcf7d467664d3b8f9cb4f3c8c5ac0a753
subpackages:
- ext
- package: golang.org/x/net
Expand Down
6 changes: 4 additions & 2 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ func (s *span) BaggageItem(key string) string {
return s.baggage[key]
}

func (s *span) ForeachBaggageItem(handler func(k, v string)) {
func (s *span) ForeachBaggageItem(handler func(k, v string) bool) {
s.RLock()
defer s.RUnlock()
for k, v := range s.baggage {
handler(k, v)
if !handler(k, v) {
break
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ func TestBaggageIterator(t *testing.T) {
sp1.SetBaggageItem("Some-other-key", "42")

b := make(map[string]string)
sp1.ForeachBaggageItem(func(k, v string) {
sp1.ForeachBaggageItem(func(k, v string) bool {
b[k] = v
return true
})
assert.Equal(t, map[string]string{"some-key": "12345", "some-other-key": "42"}, b)

b = make(map[string]string)
sp1.ForeachBaggageItem(func(k, v string) bool {
b[k] = v
return false // break out early
})
assert.Equal(t, 1, len(b), "only one baggage item should be extracted")
}

0 comments on commit ff8409d

Please sign in to comment.