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
16 changes: 4 additions & 12 deletions exporter/tanzuobservabilityexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,8 @@ func (e *tracesExporter) pushTraceData(ctx context.Context, td pdata.Traces) err
ispans := rspans.InstrumentationLibrarySpans().At(j)
transform := newTraceTransformer(resource)

var libraryName string
var libraryVersion string

if len(ispans.InstrumentationLibrary().Name()) > 0 {
libraryName = ispans.InstrumentationLibrary().Name()
}

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

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

if len(libraryName) > 0 {
if libraryName != "" {
transformedSpan.Tags[labelOtelSpanName] = libraryName
}

if len(libraryVersion) > 0 {
if libraryVersion != "" {
transformedSpan.Tags[labelOtelSpanVersion] = libraryVersion
}

Expand Down
8 changes: 4 additions & 4 deletions exporter/tanzuobservabilityexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ func TestExportTraceDataWithInstrumentationDetails(t *testing.T) {
)
traces := constructTraces([]pdata.Span{minSpan})

traces.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).InstrumentationLibrary().
SetName("instrumentation_name")
traces.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).InstrumentationLibrary().
SetVersion("v0.0.1")
instrumentationLibrary := traces.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).
InstrumentationLibrary()
instrumentationLibrary.SetName("instrumentation_name")
instrumentationLibrary.SetVersion("v0.0.1")

expected := []*span{{
Name: "root",
Expand Down
6 changes: 3 additions & 3 deletions exporter/tanzuobservabilityexporter/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ 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))
tags[labelDroppedEventsCount] = strconv.FormatUint(uint64(droppedEventsCount), 10)
}

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

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

errorTags := errorTagsFromStatus(orig.Status())
Expand Down
50 changes: 5 additions & 45 deletions exporter/tanzuobservabilityexporter/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestSpanForSourceTag(t *testing.T) {
assert.Equal(t, "source_from_span_attribute", actual.Tags["_source"])
}

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

//TestCase: 1 droppedEvents tag not set
Expand All @@ -308,58 +308,18 @@ func TestSpanForDroppedEventsCount(t *testing.T) {
actual, err := transform.Span(span)
require.NoError(t, err, "transforming span to wavefront format")
assert.NotContains(t, actual.Tags, "otel.dropped_events_count")
assert.NotContains(t, actual.Tags, "otel.dropped_links_count")
assert.NotContains(t, actual.Tags, "otel.dropped_attributes_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)
deosu marked this conversation as resolved.
Show resolved Hide resolved

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)
deosu marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down