Skip to content

Commit

Permalink
Verify that baggage is passed through to the child span (jaegertracin…
Browse files Browse the repository at this point in the history
  • Loading branch information
yurishkuro authored Sep 26, 2016
1 parent 0e75388 commit b45a5ba
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions span_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package jaeger

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert"
)

func TestBaggageIterator(t *testing.T) {
Expand All @@ -12,20 +14,28 @@ func TestBaggageIterator(t *testing.T) {
sp1 := tracer.StartSpan("s1").(*span)
sp1.SetBaggageItem("Some_Key", "12345")
sp1.SetBaggageItem("Some-other-key", "42")
expectedBaggage := map[string]string{"some-key": "12345", "some-other-key": "42"}
assertBaggage(t, sp1, expectedBaggage)

b := make(map[string]string)
sp1.Context().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 := extractBaggage(sp1, false) // break out early
assert.Equal(t, 1, len(b), "only one baggage item should be extracted")

b = make(map[string]string)
sp1.Context().ForeachBaggageItem(func(k, v string) bool {
sp2 := tracer.StartSpan("s2", opentracing.ChildOf(sp1.Context()))
assertBaggage(t, sp2, expectedBaggage) // child inherits the same baggage
}

func assertBaggage(t *testing.T, sp opentracing.Span, expected map[string]string) {
b := extractBaggage(sp, true)
assert.Equal(t, expected, b)
}

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

func TestSpanProperties(t *testing.T) {
Expand Down

0 comments on commit b45a5ba

Please sign in to comment.