Skip to content

Commit

Permalink
breaking(reporter): removes B3 header option for HTTP reporting. (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs committed Sep 15, 2020
1 parent f2e3397 commit b98d756
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
22 changes: 6 additions & 16 deletions reporter/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type httpReporter struct {
reqCallback RequestCallbackFn
reqTimeout time.Duration
serializer reporter.SpanSerializer
doNotSample bool
}

// Send implements reporter
Expand Down Expand Up @@ -153,9 +152,12 @@ func (r *httpReporter) sendBatch() error {
r.logger.Printf("failed when creating the request: %s\n", err.Error())
return err
}
if r.doNotSample {
req.Header.Set("b3", "0")
}

// By default we send b3:0 header to mitigate trace reporting amplification in
// service mesh environments where the sidecar proxies might trace the call
// we do here towards the Zipkin collector.
req.Header.Set("b3", "0")

req.Header.Set("Content-Type", r.serializer.ContentType())
if r.reqCallback != nil {
r.reqCallback(req)
Expand Down Expand Up @@ -241,17 +243,6 @@ func Serializer(serializer reporter.SpanSerializer) ReporterOption {
}
}

// AllowSamplingReporterCalls if set to true will remove the b3:0 header on
// outgoing calls to the Zipkin collector.
// By default we send b3:0 header to mitigate trace reporting amplification in
// service mesh environments where the sidecar proxies might trace the call
// we do here towards the Zipkin collector.
func AllowSamplingReporterCalls(allow bool) ReporterOption {
return func(r *httpReporter) {
r.doNotSample = !allow
}
}

// NewReporter returns a new HTTP Reporter.
// url should be the endpoint to send the spans to, e.g.
// http://localhost:9411/api/v2/spans
Expand All @@ -271,7 +262,6 @@ func NewReporter(url string, opts ...ReporterOption) reporter.Reporter {
batchMtx: &sync.Mutex{},
serializer: reporter.JSONSerializer{},
reqTimeout: defaultTimeout,
doNotSample: true,
}

for _, opt := range opts {
Expand Down
15 changes: 0 additions & 15 deletions reporter/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,6 @@ func TestB3SamplingHeader(t *testing.T) {
rep := zipkinhttp.NewReporter(
ts.URL,
zipkinhttp.Serializer(serializer),
zipkinhttp.AllowSamplingReporterCalls(true),
)
for _, span := range spans {
rep.Send(*span)
}
rep.Close()

if len(haveHeaders["B3"]) > 0 {
t.Errorf("Expected B3 header to not exist, got %v", haveHeaders["B3"])
}

rep = zipkinhttp.NewReporter(
ts.URL,
zipkinhttp.Serializer(serializer),
)
for _, span := range spans {
rep.Send(*span)
Expand All @@ -240,7 +226,6 @@ func TestB3SamplingHeader(t *testing.T) {
if want, have := []string{"0"}, haveHeaders["B3"]; !reflect.DeepEqual(want, have) {
t.Errorf("B3 header: want: %v, have %v", want, have)
}

}

type headerClient struct {
Expand Down

0 comments on commit b98d756

Please sign in to comment.