Skip to content

Commit

Permalink
Added null guards to 'Process' when processing an incoming span (#1723)
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling authored and yurishkuro committed Aug 10, 2019
1 parent e5f9953 commit 3d3483f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/collector/app/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,13 @@ func (m *SpanProcessorMetrics) GetCountsForFormat(spanFormat SpanFormat, transpo
// reportServiceNameForSpan determines the name of the service that emitted
// the span and reports a counter stat.
func (m metricsBySvc) ReportServiceNameForSpan(span *model.Span) {
serviceName := span.Process.ServiceName
if serviceName == "" {
return
var serviceName string
if nil == span.Process || len(span.Process.ServiceName) == 0 {
serviceName = "__unknown"
} else {
serviceName = span.Process.ServiceName
}

m.countSpansByServiceName(serviceName, span.Flags.IsDebug())
if span.ParentSpanID() == 0 {

Expand Down
6 changes: 6 additions & 0 deletions cmd/collector/app/span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func (sp *spanProcessor) Stop() {
}

func (sp *spanProcessor) saveSpan(span *model.Span) {
if nil == span.Process {
sp.logger.Error("process is empty for the span")
sp.metrics.SavedErrBySvc.ReportServiceNameForSpan(span)
return
}

startTime := time.Now()
if err := sp.spanWriter.WriteSpan(span); err != nil {
sp.logger.Error("Failed to save span", zap.Error(err))
Expand Down
16 changes: 16 additions & 0 deletions cmd/collector/app/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,19 @@ func TestSpanProcessorBusy(t *testing.T) {
assert.Error(t, err, "expcting busy error")
assert.Nil(t, res)
}

func TestSpanProcessorWithNilProcess(t *testing.T) {
mb := metricstest.NewFactory(time.Hour)
serviceMetrics := mb.Namespace(metrics.NSOptions{Name: "service", Tags: nil})

w := &fakeSpanWriter{}
p := NewSpanProcessor(w, Options.ServiceMetrics(serviceMetrics)).(*spanProcessor)
defer p.Stop()

p.saveSpan(&model.Span{})

expected := []metricstest.ExpectedMetric{{
Name: "service.spans.saved-by-svc|debug=false|result=err|svc=__unknown", Value: 1,
}}
mb.AssertCounterMetrics(t, expected...)
}

0 comments on commit 3d3483f

Please sign in to comment.