You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +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] | ||||
|  | ||||
| ### Changed | ||||
|  | ||||
| - Add event and link drop counts to the exported data from the `oltptrace` exporter. (#2601) | ||||
|  | ||||
| ## [1.4.1] - 2022-02-16 | ||||
|  | ||||
| ### Fixed | ||||
|   | ||||
| @@ -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 | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user