You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-09-16 09:26:25 +02:00
feature/exporter: add Drop Counts for oltptracer's event and link (#2601)
* feature/exporter: add Drop Counts for oltptracer's event Signed-off-by: 1046102779 <seachen@tencent.com> * feature/exporter: add Drop Counts for oltptracer's event Signed-off-by: 1046102779 <seachen@tencent.com> * feature/exporter: add Drop Counts for oltptracer's event and link Signed-off-by: 1046102779 <seachen@tencent.com> * feature/exporter: add Drop Counts for oltptracer's event and link Signed-off-by: 1046102779 <seachen@tencent.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Add event and link drop counts to the exported data from the `oltptrace` exporter. (#2601)
|
||||||
|
|
||||||
## [1.4.1] - 2022-02-16
|
## [1.4.1] - 2022-02-16
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@@ -162,9 +162,10 @@ func links(links []tracesdk.Link) []*tracepb.Span_Link {
|
|||||||
sid := otLink.SpanContext.SpanID()
|
sid := otLink.SpanContext.SpanID()
|
||||||
|
|
||||||
sl = append(sl, &tracepb.Span_Link{
|
sl = append(sl, &tracepb.Span_Link{
|
||||||
TraceId: tid[:],
|
TraceId: tid[:],
|
||||||
SpanId: sid[:],
|
SpanId: sid[:],
|
||||||
Attributes: KeyValues(otLink.Attributes),
|
Attributes: KeyValues(otLink.Attributes),
|
||||||
|
DroppedAttributesCount: uint32(otLink.DroppedAttributeCount),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return sl
|
return sl
|
||||||
@@ -180,23 +181,16 @@ func spanEvents(es []tracesdk.Event) []*tracepb.Span_Event {
|
|||||||
if evCount > maxEventsPerSpan {
|
if evCount > maxEventsPerSpan {
|
||||||
evCount = maxEventsPerSpan
|
evCount = maxEventsPerSpan
|
||||||
}
|
}
|
||||||
events := make([]*tracepb.Span_Event, 0, evCount)
|
events := make([]*tracepb.Span_Event, evCount)
|
||||||
nEvents := 0
|
|
||||||
|
|
||||||
// Transform message events
|
// Transform message events
|
||||||
for _, e := range es {
|
for i := 0; i < evCount; i++ {
|
||||||
if nEvents >= maxEventsPerSpan {
|
events[i] = &tracepb.Span_Event{
|
||||||
break
|
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
|
return events
|
||||||
|
@@ -87,9 +87,10 @@ func TestSpanEvent(t *testing.T) {
|
|||||||
Time: eventTime,
|
Time: eventTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "test 2",
|
Name: "test 2",
|
||||||
Attributes: attrs,
|
Attributes: attrs,
|
||||||
Time: eventTime,
|
Time: eventTime,
|
||||||
|
DroppedAttributeCount: 2,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if !assert.Len(t, got, 2) {
|
if !assert.Len(t, got, 2) {
|
||||||
@@ -98,7 +99,7 @@ func TestSpanEvent(t *testing.T) {
|
|||||||
eventTimestamp := uint64(1589932800 * 1e9)
|
eventTimestamp := uint64(1589932800 * 1e9)
|
||||||
assert.Equal(t, &tracepb.Span_Event{Name: "test 1", Attributes: nil, TimeUnixNano: eventTimestamp}, got[0])
|
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.
|
// 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) {
|
func TestExcessiveSpanEvents(t *testing.T) {
|
||||||
@@ -124,10 +125,13 @@ func TestEmptyLinks(t *testing.T) {
|
|||||||
func TestLinks(t *testing.T) {
|
func TestLinks(t *testing.T) {
|
||||||
attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)}
|
attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)}
|
||||||
l := []tracesdk.Link{
|
l := []tracesdk.Link{
|
||||||
{},
|
|
||||||
{
|
{
|
||||||
SpanContext: trace.SpanContext{},
|
DroppedAttributeCount: 3,
|
||||||
Attributes: attrs,
|
},
|
||||||
|
{
|
||||||
|
SpanContext: trace.SpanContext{},
|
||||||
|
Attributes: attrs,
|
||||||
|
DroppedAttributeCount: 3,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
got := links(l)
|
got := links(l)
|
||||||
@@ -139,8 +143,9 @@ func TestLinks(t *testing.T) {
|
|||||||
|
|
||||||
// Empty should be empty.
|
// Empty should be empty.
|
||||||
expected := &tracepb.Span_Link{
|
expected := &tracepb.Span_Link{
|
||||||
TraceId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 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},
|
SpanId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
|
||||||
|
DroppedAttributesCount: 3,
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, got[0])
|
assert.Equal(t, expected, got[0])
|
||||||
|
|
||||||
@@ -151,6 +156,7 @@ func TestLinks(t *testing.T) {
|
|||||||
// Changes to our links should not change the produced links.
|
// Changes to our links should not change the produced links.
|
||||||
l[1].SpanContext = l[1].SpanContext.WithTraceID(trace.TraceID{})
|
l[1].SpanContext = l[1].SpanContext.WithTraceID(trace.TraceID{})
|
||||||
assert.Equal(t, expected, got[1])
|
assert.Equal(t, expected, got[1])
|
||||||
|
assert.Equal(t, l[1].DroppedAttributeCount, int(got[1].DroppedAttributesCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStatus(t *testing.T) {
|
func TestStatus(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user