From ce93decfc3717f9f919d51a2e1ff5b3f89b000ae Mon Sep 17 00:00:00 2001 From: Moritz Johner Date: Sat, 4 Jul 2020 17:02:05 +0200 Subject: [PATCH] fix null pointer in jaeger-spark-dependencies fixes jaegertracing/jaeger-operator#1113 Signed-off-by: Moritz Johner --- .../esmodeltranslator/modeltranslator.go | 2 +- .../esmodeltranslator/modeltranslator_test.go | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go index 8cb46d181ca3..5978c50d215f 100644 --- a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go +++ b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go @@ -134,7 +134,7 @@ func toTime(nano pdata.TimestampUnixNano) time.Time { func references(links pdata.SpanLinkSlice, parentSpanID pdata.SpanID, traceID dbmodel.TraceID) ([]dbmodel.Reference, error) { parentSpanIDSet := len(parentSpanID.Bytes()) != 0 if !parentSpanIDSet && links.Len() == 0 { - return nil, nil + return []dbmodel.Reference{}, nil } refsCount := links.Len() diff --git a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator_test.go b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator_test.go index 3b9c00271902..508ed0d585ec 100644 --- a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator_test.go +++ b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator_test.go @@ -159,6 +159,33 @@ func TestConvertSpan(t *testing.T) { }, spans[0]) } +func TestSpanEmptyRef(t *testing.T) { + traces := traces("myservice") + span := addSpan(traces, "root", traceID, spanID) + span.SetStartTime(pdata.TimestampUnixNano(1000000)) + span.SetEndTime(pdata.TimestampUnixNano(2000000)) + + c := &Translator{} + spans, err := c.ConvertSpans(traces) + require.NoError(t, err) + assert.Equal(t, 1, len(spans)) + assert.Equal(t, &dbmodel.Span{ + TraceID: "30313233343536373839616263646566", + SpanID: "3031323334353637", + StartTime: 1000, + Duration: 1000, + OperationName: "root", + StartTimeMillis: 1, + Tags: nil, + Logs: nil, + References: []dbmodel.Reference{}, // should not be nil + Process: dbmodel.Process{ + ServiceName: "myservice", + Tags: nil, + }, + }, spans[0]) +} + func TestEmpty(t *testing.T) { c := &Translator{} spans, err := c.ConvertSpans(pdata.NewTraces())