From 4db46d70ac4bceb7d0a43a6067121461450a3904 Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Thu, 17 Sep 2020 09:45:17 +0200 Subject: [PATCH 1/3] Translate OTEL instrumentation library to ES DB model Signed-off-by: Pavol Loffay --- .../esmodeltranslator/modeltranslator.go | 20 +++++++++++++++++-- .../esmodeltranslator/modeltranslator_test.go | 11 +++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go index 0216ad92e1c..b48dd04adf0 100644 --- a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go +++ b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go @@ -90,14 +90,13 @@ func (c *Translator) resourceSpans(rspans pdata.ResourceSpans, containers *[]Con ils := rspans.InstrumentationLibrarySpans() process := c.process(rspans.Resource()) for i := 0; i < ils.Len(); i++ { - // TODO convert instrumentation library info - //ils.At(i).InstrumentationLibrary() spans := ils.At(i).Spans() for j := 0; j < spans.Len(); j++ { dbSpan, err := c.spanWithoutProcess(spans.At(j)) if err != nil { return err } + c.addInstrumentationLibrary(dbSpan, ils.At(i).InstrumentationLibrary()) dbSpan.Process = *process *containers = append(*containers, ConvertedData{ Span: spans.At(j), @@ -110,6 +109,23 @@ func (c *Translator) resourceSpans(rspans pdata.ResourceSpans, containers *[]Con return nil } +func (c *Translator) addInstrumentationLibrary(span *dbmodel.Span, instLib pdata.InstrumentationLibrary) { + if instLib.Name() != "" { + span.Tags = append(span.Tags, dbmodel.KeyValue{ + Key: tracetranslator.TagInstrumentationName, + Type: dbmodel.StringType, + Value: instLib.Name(), + }) + } + if instLib.Version() != "" { + span.Tags = append(span.Tags, dbmodel.KeyValue{ + Key: tracetranslator.TagInstrumentationVersion, + Type: dbmodel.StringType, + Value: instLib.Version(), + }) + } +} + func (c *Translator) spanWithoutProcess(span pdata.Span) (*dbmodel.Span, error) { if span.IsNil() { return nil, nil diff --git a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator_test.go b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator_test.go index 9b8cd177c24..2b6b5b75358 100644 --- a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator_test.go +++ b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator_test.go @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/translator/conventions" + tracetranslator "go.opentelemetry.io/collector/translator/trace" "github.com/jaegertracing/jaeger/plugin/storage/es/spanstore/dbmodel" ) @@ -107,6 +108,10 @@ func TestConvertSpan(t *testing.T) { traces := traces("myservice") resource := traces.ResourceSpans().At(0).Resource() resource.Attributes().InsertDouble("num", 16.66) + instrumentationLibrary := traces.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).InstrumentationLibrary() + instrumentationLibrary.InitEmpty() + instrumentationLibrary.SetName("io.opentelemetry") + instrumentationLibrary.SetVersion("1.0") span := addSpan(traces, "root", traceID, spanID) span.SetKind(pdata.SpanKindCLIENT) span.Status().InitEmpty() @@ -149,7 +154,10 @@ func TestConvertSpan(t *testing.T) { {Key: "status.code", Type: dbmodel.StringType, Value: "Cancelled"}, {Key: "error", Type: dbmodel.BoolType, Value: "true"}, {Key: "status.message", Type: dbmodel.StringType, Value: "messagetext"}, - {Key: "foo", Type: dbmodel.BoolType, Value: "true"}}, + {Key: "foo", Type: dbmodel.BoolType, Value: "true"}, + {Key: tracetranslator.TagInstrumentationName, Type: dbmodel.StringType, Value: "io.opentelemetry"}, + {Key: tracetranslator.TagInstrumentationVersion, Type: dbmodel.StringType, Value: "1.0"}, + }, Tag: map[string]interface{}{"toTagMap": "val"}, Logs: []dbmodel.Log{{Fields: []dbmodel.KeyValue{ {Key: "event", Value: "eventName", Type: dbmodel.StringType}, @@ -170,6 +178,7 @@ func TestSpanEmptyRef(t *testing.T) { span := addSpan(traces, "root", traceID, spanID) span.SetStartTime(pdata.TimestampUnixNano(1000000)) span.SetEndTime(pdata.TimestampUnixNano(2000000)) + traces.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).InstrumentationLibrary().InitEmpty() c := &Translator{} spanDataContainers, err := c.ConvertSpans(traces) From 4bad59fa8455d1ce4106a4c76439d1394d630920 Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Thu, 17 Sep 2020 14:00:56 +0200 Subject: [PATCH 2/3] Print OTEL xdock logs if failed Signed-off-by: Pavol Loffay --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0cc900d5fa3..f63f1c9a697 100644 --- a/.travis.yml +++ b/.travis.yml @@ -85,7 +85,7 @@ after_success: - if [ "$COVERAGE" == true ]; then bash <(curl -s https://codecov.io/bash) ; else echo 'skipping coverage'; fi after_failure: - - if [ "$CROSSDOCK" == true ]; then make crossdock-logs ; else echo 'skipping crossdock'; fi + - if [ "$CROSSDOCK" == true || "$CROSSDOCK_OTEL" == true ]; then make crossdock-logs ; else echo 'skipping crossdock'; fi before_deploy: - if [ "$DEPLOY" == true ]; then bash ./scripts/travis/package-deploy.sh ; else echo 'skipping deploying binaries'; fi From f97c127bd3e6b3ec700729eb0cd9e3f0b605980d Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Thu, 17 Sep 2020 14:10:30 +0200 Subject: [PATCH 3/3] Add nil check Signed-off-by: Pavol Loffay --- .../elasticsearchexporter/esmodeltranslator/modeltranslator.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go index b48dd04adf0..ff03c34eba3 100644 --- a/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go +++ b/cmd/opentelemetry/app/exporter/elasticsearchexporter/esmodeltranslator/modeltranslator.go @@ -110,6 +110,9 @@ func (c *Translator) resourceSpans(rspans pdata.ResourceSpans, containers *[]Con } func (c *Translator) addInstrumentationLibrary(span *dbmodel.Span, instLib pdata.InstrumentationLibrary) { + if instLib.IsNil() { + return + } if instLib.Name() != "" { span.Tags = append(span.Tags, dbmodel.KeyValue{ Key: tracetranslator.TagInstrumentationName,