@@ -5,6 +5,7 @@ package integration
55
66import (
77 "context"
8+ "errors"
89 "fmt"
910 "testing"
1011
@@ -122,3 +123,36 @@ func TestWriteTraces(t *testing.T) {
122123 thirdChunkScope := thirdChunkResource .ScopeSpans ().At (0 )
123124 assert .Equal (t , "span5" , thirdChunkScope .Spans ().At (0 ).Name ())
124125}
126+
127+ func TestWriteTracesReturnsIntermediateChunkError (t * testing.T ) {
128+ td := ptrace .NewTraces ()
129+ resource := td .ResourceSpans ().AppendEmpty ()
130+ scope := resource .ScopeSpans ().AppendEmpty ()
131+ for i := 1 ; i <= 3 ; i ++ {
132+ span := scope .Spans ().AppendEmpty ()
133+ span .SetSpanID (pcommon .SpanID ([8 ]byte {0 , 0 , 0 , 0 , 0 , 0 , 0 , byte (i )}))
134+ span .SetName (fmt .Sprintf ("span%d" , i ))
135+ }
136+
137+ expectedErr := errors .New ("send failed" )
138+ mockExporter := & MockExporter {}
139+ mockExporter .On ("ConsumeTraces" , mock .Anything , mock .Anything ).Return (expectedErr ).Once ()
140+ tw := & traceWriter {
141+ logger : zaptest .NewLogger (t ),
142+ exporter : mockExporter ,
143+ }
144+
145+ origMaxChunkSize := MaxChunkSize
146+ MaxChunkSize = 2
147+ defer func () {
148+ MaxChunkSize = origMaxChunkSize
149+ }()
150+
151+ err := tw .WriteTraces (context .Background (), td )
152+
153+ require .ErrorIs (t , err , expectedErr )
154+ mockExporter .AssertNumberOfCalls (t , "ConsumeTraces" , 1 )
155+ mockExporter .AssertExpectations (t )
156+ require .Len (t , mockExporter .chunks , 1 )
157+ assert .Equal (t , 2 , mockExporter .chunks [0 ].SpanCount ())
158+ }
0 commit comments