From e8c3032796baa3852628cdaad229839a2917682c Mon Sep 17 00:00:00 2001 From: 1046102779 Date: Fri, 11 Feb 2022 17:18:50 +0800 Subject: [PATCH 1/4] feature/exporter: add Drop Counts for oltptracer's event Signed-off-by: 1046102779 --- exporters/otlp/otlptrace/internal/tracetransform/span.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span.go b/exporters/otlp/otlptrace/internal/tracetransform/span.go index 2f0f5eacb77..c11a8ffa45d 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -191,10 +191,10 @@ func spanEvents(es []tracesdk.Event) []*tracepb.Span_Event { 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. + Name: e.Name, + TimeUnixNano: uint64(e.Time.UnixNano()), + Attributes: KeyValues(e.Attributes), + DroppedAttributesCount: uint32(e.DroppedAttributeCount), }, ) } From 912979da511dded90368c2215acc194103a27c27 Mon Sep 17 00:00:00 2001 From: 1046102779 Date: Fri, 11 Feb 2022 17:20:28 +0800 Subject: [PATCH 2/4] feature/exporter: add Drop Counts for oltptracer's event Signed-off-by: 1046102779 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b65fd81c2de..a750fab22ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Support `OTEL_EXPORTER_ZIPKIN_ENDPOINT` env to specify zipkin collector endpoint (#2490) - Log the configuration of TracerProviders, and Tracers for debugging. To enable use a logger with Verbosity (V level) >=1 - Added environment variables for: `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`, `OTEL_BSP_MAX_QUEUE_SIZE` and `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` (#2515) +- Add Drop Counts for oltptracer's event (#2601) ### Changed From bd6a5a7744456bb4af891abfb39bc29e974f7bf0 Mon Sep 17 00:00:00 2001 From: 1046102779 Date: Fri, 11 Feb 2022 17:23:59 +0800 Subject: [PATCH 3/4] feature/exporter: add Drop Counts for oltptracer's event and link Signed-off-by: 1046102779 --- CHANGELOG.md | 2 +- exporters/otlp/otlptrace/internal/tracetransform/span.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a750fab22ac..3d347462caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Support `OTEL_EXPORTER_ZIPKIN_ENDPOINT` env to specify zipkin collector endpoint (#2490) - Log the configuration of TracerProviders, and Tracers for debugging. To enable use a logger with Verbosity (V level) >=1 - Added environment variables for: `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`, `OTEL_BSP_MAX_QUEUE_SIZE` and `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` (#2515) -- Add Drop Counts for oltptracer's event (#2601) +- Add Drop Counts for oltptracer's event and link (#2601) ### Changed diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span.go b/exporters/otlp/otlptrace/internal/tracetransform/span.go index c11a8ffa45d..ab431dd84b7 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -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 From ab815ff5ccbc77b3c85bc750ce286023cef3f788 Mon Sep 17 00:00:00 2001 From: 1046102779 Date: Fri, 11 Feb 2022 18:58:47 +0800 Subject: [PATCH 4/4] feature/exporter: add Drop Counts for oltptracer's event and link Signed-off-by: 1046102779 --- .../otlptrace/internal/tracetransform/span.go | 21 ++++++---------- .../internal/tracetransform/span_test.go | 24 ++++++++++++------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span.go b/exporters/otlp/otlptrace/internal/tracetransform/span.go index ab431dd84b7..3c6a3ec4291 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -181,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), - DroppedAttributesCount: uint32(e.DroppedAttributeCount), - }, - ) } return events diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go index 351de0367ef..f83d748d63c 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go @@ -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) { @@ -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) { @@ -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) @@ -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]) @@ -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) {