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

feature/exporter: add Drop Counts for oltptracer's event and link #2601

Merged
merged 6 commits into from Feb 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Changed

- Add event and link drop counts to the exported data from the `oltptrace` exporter. (#2601)

## [1.4.1] - 2022-02-16

### Fixed
Expand Down
28 changes: 11 additions & 17 deletions exporters/otlp/otlptrace/internal/tracetransform/span.go
Expand Up @@ -162,9 +162,10 @@ func links(links []tracesdk.Link) []*tracepb.Span_Link {
sid := otLink.SpanContext.SpanID()

sl = append(sl, &tracepb.Span_Link{
TraceId: tid[:],
SpanId: sid[:],
Attributes: KeyValues(otLink.Attributes),
TraceId: tid[:],
SpanId: sid[:],
Attributes: KeyValues(otLink.Attributes),
DroppedAttributesCount: uint32(otLink.DroppedAttributeCount),
})
}
return sl
Expand All @@ -180,23 +181,16 @@ func spanEvents(es []tracesdk.Event) []*tracepb.Span_Event {
if evCount > maxEventsPerSpan {
evCount = maxEventsPerSpan
}
events := make([]*tracepb.Span_Event, 0, evCount)
nEvents := 0
events := make([]*tracepb.Span_Event, evCount)

// Transform message events
for _, e := range es {
if nEvents >= maxEventsPerSpan {
break
for i := 0; i < evCount; i++ {
events[i] = &tracepb.Span_Event{
Name: es[i].Name,
TimeUnixNano: uint64(es[i].Time.UnixNano()),
Attributes: KeyValues(es[i].Attributes),
DroppedAttributesCount: uint32(es[i].DroppedAttributeCount),
}
nEvents++
events = append(events,
&tracepb.Span_Event{
Name: e.Name,
TimeUnixNano: uint64(e.Time.UnixNano()),
Attributes: KeyValues(e.Attributes),
// TODO (rghetia) : Add Drop Counts when supported.
},
)
}

return events
Expand Down
24 changes: 15 additions & 9 deletions exporters/otlp/otlptrace/internal/tracetransform/span_test.go
Expand Up @@ -87,9 +87,10 @@ func TestSpanEvent(t *testing.T) {
Time: eventTime,
},
{
Name: "test 2",
Attributes: attrs,
Time: eventTime,
Name: "test 2",
Attributes: attrs,
Time: eventTime,
DroppedAttributeCount: 2,
},
})
if !assert.Len(t, got, 2) {
Expand All @@ -98,7 +99,7 @@ func TestSpanEvent(t *testing.T) {
eventTimestamp := uint64(1589932800 * 1e9)
assert.Equal(t, &tracepb.Span_Event{Name: "test 1", Attributes: nil, TimeUnixNano: eventTimestamp}, got[0])
// Do not test Attributes directly, just that the return value goes to the correct field.
assert.Equal(t, &tracepb.Span_Event{Name: "test 2", Attributes: KeyValues(attrs), TimeUnixNano: eventTimestamp}, got[1])
assert.Equal(t, &tracepb.Span_Event{Name: "test 2", Attributes: KeyValues(attrs), TimeUnixNano: eventTimestamp, DroppedAttributesCount: 2}, got[1])
}

func TestExcessiveSpanEvents(t *testing.T) {
Expand All @@ -124,10 +125,13 @@ func TestEmptyLinks(t *testing.T) {
func TestLinks(t *testing.T) {
attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)}
l := []tracesdk.Link{
{},
{
SpanContext: trace.SpanContext{},
Attributes: attrs,
DroppedAttributeCount: 3,
},
{
SpanContext: trace.SpanContext{},
Attributes: attrs,
DroppedAttributeCount: 3,
},
}
got := links(l)
Expand All @@ -139,8 +143,9 @@ func TestLinks(t *testing.T) {

// Empty should be empty.
expected := &tracepb.Span_Link{
TraceId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
SpanId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
TraceId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
SpanId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
DroppedAttributesCount: 3,
}
assert.Equal(t, expected, got[0])

Expand All @@ -151,6 +156,7 @@ func TestLinks(t *testing.T) {
// Changes to our links should not change the produced links.
l[1].SpanContext = l[1].SpanContext.WithTraceID(trace.TraceID{})
assert.Equal(t, expected, got[1])
assert.Equal(t, l[1].DroppedAttributeCount, int(got[1].DroppedAttributesCount))
}

func TestStatus(t *testing.T) {
Expand Down