@@ -46,6 +46,7 @@ func TestReceiveTraceDataOp(t *testing.T) {
46
46
params := []testParams {
47
47
{items : 13 , err : WrapDownstreamError (errFake )},
48
48
{items : 42 , err : nil },
49
+ {items : 7 , err : errors .New ("non-downstream error" )}, // Regular error to test numFailedErrors path
49
50
}
50
51
for i , param := range params {
51
52
rec , err := newReceiver (ObsReportSettings {
@@ -62,19 +63,29 @@ func TestReceiveTraceDataOp(t *testing.T) {
62
63
spans := tt .SpanRecorder .Ended ()
63
64
require .Len (t , spans , len (params ))
64
65
65
- var acceptedSpans , refusedSpans int
66
+ var acceptedSpans , refusedSpans , failedSpans int
66
67
for i , span := range spans {
67
68
assert .Equal (t , "receiver/" + receiverID .String ()+ "/TraceDataReceived" , span .Name ())
68
69
switch {
69
70
case params [i ].err == nil :
70
71
acceptedSpans += params [i ].items
71
72
require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .AcceptedSpansKey , Value : attribute .Int64Value (int64 (params [i ].items ))})
72
73
require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .RefusedSpansKey , Value : attribute .Int64Value (0 )})
74
+ require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .FailedSpansKey , Value : attribute .Int64Value (0 )})
73
75
assert .Equal (t , codes .Unset , span .Status ().Code )
74
76
case errors .Is (params [i ].err , errFake ):
75
77
refusedSpans += params [i ].items
76
78
require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .AcceptedSpansKey , Value : attribute .Int64Value (0 )})
77
79
require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .RefusedSpansKey , Value : attribute .Int64Value (int64 (params [i ].items ))})
80
+ require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .FailedSpansKey , Value : attribute .Int64Value (0 )})
81
+ assert .Equal (t , codes .Error , span .Status ().Code )
82
+ assert .Equal (t , params [i ].err .Error (), span .Status ().Description )
83
+ case params [i ].err != nil && ! errors .Is (params [i ].err , ErrDownstreamError ):
84
+ // Non-downstream error case - this covers the uncovered numFailedErrors path
85
+ failedSpans += params [i ].items
86
+ require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .AcceptedSpansKey , Value : attribute .Int64Value (0 )})
87
+ require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .RefusedSpansKey , Value : attribute .Int64Value (0 )})
88
+ require .Contains (t , span .Attributes (), attribute.KeyValue {Key : internal .FailedSpansKey , Value : attribute .Int64Value (int64 (params [i ].items ))})
78
89
assert .Equal (t , codes .Error , span .Status ().Code )
79
90
assert .Equal (t , params [i ].err .Error (), span .Status ().Description )
80
91
default :
@@ -100,6 +111,15 @@ func TestReceiveTraceDataOp(t *testing.T) {
100
111
Value : int64 (refusedSpans ),
101
112
},
102
113
}, metricdatatest .IgnoreTimestamp (), metricdatatest .IgnoreExemplars ())
114
+ metadatatest .AssertEqualReceiverFailedSpans (t , tt ,
115
+ []metricdata.DataPoint [int64 ]{
116
+ {
117
+ Attributes : attribute .NewSet (
118
+ attribute .String (internal .ReceiverKey , receiverID .String ()),
119
+ attribute .String (internal .TransportKey , transport )),
120
+ Value : int64 (failedSpans ),
121
+ },
122
+ }, metricdatatest .IgnoreTimestamp (), metricdatatest .IgnoreExemplars ())
103
123
104
124
// Assert otelcol_receiver_requests metric with outcome attribute
105
125
var expectedRequests []metricdata.DataPoint [int64 ]
0 commit comments