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

[exporter/tanzuobservability]Instrumentation Library and Dropped Counts to Span Tags #8120

Merged
merged 9 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 33 additions & 8 deletions exporter/tanzuobservabilityexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ import (
)

const (
defaultApplicationName = "defaultApp"
defaultServiceName = "defaultService"
labelApplication = "application"
labelError = "error"
labelEventName = "name"
labelService = "service"
labelSpanKind = "span.kind"
labelSource = "source"
defaultApplicationName = "defaultApp"
defaultServiceName = "defaultService"
labelApplication = "application"
labelError = "error"
labelEventName = "name"
labelService = "service"
labelSpanKind = "span.kind"
labelSource = "source"
labelDroppedEventsCount = "otel.dropped_events_count"
labelDroppedLinksCount = "otel.dropped_links_count"
labelDroppedAttrsCount = "otel.dropped_attributes_count"
labelOtelSpanName = "otel.span.name"
labelOtelSpanVersion = "otel.span.version"
)

// spanSender Interface for sending tracing spans to Tanzu Observability
Expand Down Expand Up @@ -103,6 +108,18 @@ func (e *tracesExporter) pushTraceData(ctx context.Context, td pdata.Traces) err
for j := 0; j < rspans.InstrumentationLibrarySpans().Len(); j++ {
ispans := rspans.InstrumentationLibrarySpans().At(j)
transform := newTraceTransformer(resource)

var libraryName string
var libraryVersion string

if len(ispans.InstrumentationLibrary().Name()) > 0 {
deosu marked this conversation as resolved.
Show resolved Hide resolved
libraryName = ispans.InstrumentationLibrary().Name()
}

if len(ispans.InstrumentationLibrary().Version()) > 0 {
libraryVersion = ispans.InstrumentationLibrary().Version()
}

for k := 0; k < ispans.Spans().Len(); k++ {
select {
case <-ctx.Done():
Expand All @@ -114,6 +131,14 @@ func (e *tracesExporter) pushTraceData(ctx context.Context, td pdata.Traces) err
continue
}

if len(libraryName) > 0 {
deosu marked this conversation as resolved.
Show resolved Hide resolved
transformedSpan.Tags[labelOtelSpanName] = libraryName
}

if len(libraryVersion) > 0 {
deosu marked this conversation as resolved.
Show resolved Hide resolved
transformedSpan.Tags[labelOtelSpanVersion] = libraryVersion
}

if err := e.recordSpan(transformedSpan); err != nil {
errs = multierr.Append(errs, err)
continue
Expand Down
29 changes: 29 additions & 0 deletions exporter/tanzuobservabilityexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,35 @@ func validateTraces(t *testing.T, expected []*span, traces pdata.Traces) {
}
}

func TestExportTraceDataWithInstrumentationDetails(t *testing.T) {
minSpan := createSpan(
"root",
pdata.NewTraceID([16]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}),
pdata.NewSpanID([8]byte{9, 9, 9, 9, 9, 9, 9, 9}),
pdata.SpanID{},
)
traces := constructTraces([]pdata.Span{minSpan})

traces.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).InstrumentationLibrary().
deosu marked this conversation as resolved.
Show resolved Hide resolved
SetName("instrumentation_name")
traces.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).InstrumentationLibrary().
SetVersion("v0.0.1")

expected := []*span{{
Name: "root",
TraceID: uuid.MustParse("01010101-0101-0101-0101-010101010101"),
SpanID: uuid.MustParse("00000000-0000-0000-0909-090909090909"),
Tags: map[string]string{
labelApplication: "defaultApp",
labelService: "defaultService",
labelOtelSpanName: "instrumentation_name",
labelOtelSpanVersion: "v0.0.1",
},
}}

validateTraces(t, expected, traces)
}

func TestExportTraceDataRespectsContext(t *testing.T) {
traces := constructTraces([]pdata.Span{createSpan(
"root",
Expand Down
13 changes: 13 additions & 0 deletions exporter/tanzuobservabilityexporter/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package tanzuobservabilityexporter // import "github.com/open-telemetry/opentele

import (
"errors"
"strconv"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -73,6 +74,18 @@ func (t *traceTransformer) Span(orig pdata.Span) (span, error) {

tags[labelSpanKind] = spanKind(orig)

if droppedEventsCount := orig.DroppedEventsCount(); droppedEventsCount > 0 {
tags[labelDroppedEventsCount] = strconv.Itoa(int(droppedEventsCount))
deosu marked this conversation as resolved.
Show resolved Hide resolved
}

if droppedLinksCount := orig.DroppedLinksCount(); droppedLinksCount > 0 {
tags[labelDroppedLinksCount] = strconv.Itoa(int(droppedLinksCount))
}

if droppedAttrsCount := orig.DroppedAttributesCount(); droppedAttrsCount > 0 {
tags[labelDroppedAttrsCount] = strconv.Itoa(int(droppedAttrsCount))
}

errorTags := errorTagsFromStatus(orig.Status())
for k, v := range errorTags {
tags[k] = v
Expand Down
69 changes: 69 additions & 0 deletions exporter/tanzuobservabilityexporter/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,75 @@ func TestSpanForSourceTag(t *testing.T) {
assert.Equal(t, "source_from_span_attribute", actual.Tags["_source"])
}

func TestSpanForDroppedEventsCount(t *testing.T) {
inNanos := int64(50000000)
deosu marked this conversation as resolved.
Show resolved Hide resolved

//TestCase: 1 droppedEvents tag not set
resAttrs := pdata.NewAttributeMap()
transform := transformerFromAttributes(resAttrs)
span := pdata.NewSpan()
span.SetSpanID(pdata.NewSpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}))
span.SetTraceID(pdata.NewTraceID([16]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}))
span.SetStartTimestamp(pdata.Timestamp(inNanos))

actual, err := transform.Span(span)
require.NoError(t, err, "transforming span to wavefront format")
assert.NotContains(t, actual.Tags, "otel.dropped_events_count")

//TestCase2: droppedEvents set
span.SetDroppedEventsCount(123)

actual, err = transform.Span(span)
require.NoError(t, err, "transforming span to wavefront format")
assert.Equal(t, "123", actual.Tags["otel.dropped_events_count"])
}

func TestSpanForDroppedLinksCounts(t *testing.T) {
inNanos := int64(50000000)

//TestCase: 1 DroppedLinks tag not set
resAttrs := pdata.NewAttributeMap()
transform := transformerFromAttributes(resAttrs)
span := pdata.NewSpan()
span.SetSpanID(pdata.NewSpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}))
span.SetTraceID(pdata.NewTraceID([16]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}))
span.SetStartTimestamp(pdata.Timestamp(inNanos))

actual, err := transform.Span(span)
require.NoError(t, err, "transforming span to wavefront format")
assert.NotContains(t, actual.Tags, "otel.dropped_links_count")

//TestCase2: DroppedLinks set
span.SetDroppedLinksCount(123)

actual, err = transform.Span(span)
require.NoError(t, err, "transforming span to wavefront format")
assert.Equal(t, "123", actual.Tags["otel.dropped_links_count"])
}

func TestSpanForDroppedAttributesCounts(t *testing.T) {
inNanos := int64(50000000)

//TestCase: 1 DroppedAttributes tag not set
resAttrs := pdata.NewAttributeMap()
transform := transformerFromAttributes(resAttrs)
span := pdata.NewSpan()
span.SetSpanID(pdata.NewSpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}))
span.SetTraceID(pdata.NewTraceID([16]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}))
span.SetStartTimestamp(pdata.Timestamp(inNanos))

actual, err := transform.Span(span)
require.NoError(t, err, "transforming span to wavefront format")
assert.NotContains(t, actual.Tags, "otel.dropped_attributes_count")

//TestCase2: DroppedAttributes set
span.SetDroppedAttributesCount(123)

actual, err = transform.Span(span)
require.NoError(t, err, "transforming span to wavefront format")
assert.Equal(t, "123", actual.Tags["otel.dropped_attributes_count"])
}

func TestGetSourceAndResourceTags(t *testing.T) {
resAttrs := pdata.NewAttributeMap()
resAttrs.InsertString(labelSource, "test_source")
Expand Down