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

Translate OTEL instrumentation library to ES DB model #2484

Merged
merged 3 commits into from
Sep 17, 2020
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -110,6 +109,26 @@ func (c *Translator) resourceSpans(rspans pdata.ResourceSpans, containers *[]Con
return nil
}

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,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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},
Expand All @@ -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)
Expand Down