Skip to content

Commit

Permalink
[newrelicexporter] Fix panic on missing span status (#775)
Browse files Browse the repository at this point in the history
The span status is optional and a missing status means no error, updates
the newrelicexporter to handle this and adds tests to prevent
regression.

Resolves #348
  • Loading branch information
MrAlias committed Aug 20, 2020
1 parent 23dfc78 commit 72ea63d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 1 addition & 5 deletions exporter/newrelicexporter/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (t *transformer) SpanAttributes(span *tracepb.Span) map[string]interface{}

length := 2

isErr := t.isError(span.Status.Code)
isErr := span.Status != nil && span.Status.Code != 0
if isErr {
length++
}
Expand Down Expand Up @@ -151,10 +151,6 @@ func (t *transformer) Timestamp(ts *timestamp.Timestamp) time.Time {
return time.Unix(ts.Seconds, int64(ts.Nanos))
}

func (t *transformer) isError(code int32) bool {
return code != 0
}

func (t *transformer) Metric(metric *metricspb.Metric) ([]telemetry.Metric, error) {
if metric == nil || metric.MetricDescriptor == nil {
return nil, errors.New("empty metric")
Expand Down
15 changes: 15 additions & 0 deletions exporter/newrelicexporter/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ func TestTransformSpan(t *testing.T) {
in *tracepb.Span
want telemetry.Span
}{
{
in: &tracepb.Span{
// No status means no error.
},
want: telemetry.Span{
ID: "0000000000000000",
TraceID: "00000000000000000000000000000000",
ServiceName: "test-service",
Attributes: map[string]interface{}{
"collector.name": name,
"collector.version": version,
"resource": "R1",
},
},
},
{
in: &tracepb.Span{
Status: &tracepb.Status{},
Expand Down

0 comments on commit 72ea63d

Please sign in to comment.