Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added null guards to 'Process' when processing an incoming span #1723

Merged
merged 1 commit into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...)
}