@@ -330,7 +330,6 @@ func TestExporter_PushTraceRecord(t *testing.T) {
330330 exporter := newTestTracesExporter (t , server .URL , func (cfg * Config ) { * cfg = * testConfig })
331331 mustSendTraces (t , exporter , `{"message": "test1"}` )
332332
333- time .Sleep (200 * time .Millisecond )
334333 assert .Equal (t , int64 (1 ), attempts .Load ())
335334 })
336335 }
@@ -346,9 +345,9 @@ func TestExporter_PushTraceRecord(t *testing.T) {
346345 })
347346
348347 exporter := newTestTracesExporter (t , server .URL )
349- mustSendTraces (t , exporter , `{"message": "test1"}` )
348+ err := sendTraces (t , exporter , `{"message": "test1"}` )
349+ assert .ErrorContains (t , err , "flush failed: [400 Bad Request] oops" )
350350
351- time .Sleep (200 * time .Millisecond )
352351 assert .Equal (t , int64 (1 ), attempts .Load ())
353352 })
354353
@@ -382,7 +381,6 @@ func TestExporter_PushTraceRecord(t *testing.T) {
382381 exporter := newTestTracesExporter (t , server .URL )
383382 mustSendTraces (t , exporter , `{"message": "test1"}` )
384383
385- time .Sleep (200 * time .Millisecond )
386384 assert .Equal (t , int64 (1 ), attempts .Load ())
387385 })
388386
@@ -420,9 +418,7 @@ func TestExporter_PushTraceRecord(t *testing.T) {
420418 cfg .Retry .InitialInterval = 1 * time .Millisecond
421419 cfg .Retry .MaxInterval = 10 * time .Millisecond
422420 })
423- mustSendTraces (t , exporter , `{"message": "test1", "idx": 0}` )
424- mustSendTraces (t , exporter , `{"message": "test2", "idx": 1}` )
425- mustSendTraces (t , exporter , `{"message": "test3", "idx": 2}` )
421+ mustSendTraces (t , exporter , `{"message": "test1", "idx": 0}` , `{"message": "test2", "idx": 1}` , `{"message": "test3", "idx": 2}` )
426422
427423 wg .Wait () // <- this blocks forever if the trace is not retried
428424
@@ -462,8 +458,22 @@ func withTestTracesExporterConfig(fns ...func(*Config)) func(string) *Config {
462458 }
463459}
464460
465- func mustSendTraces (t * testing.T , exporter * elasticsearchTracesExporter , contents string ) {
466- err := pushDocuments (context .TODO (), exporter .index , []byte (contents ), exporter .bulkIndexer )
461+ func sendTraces (t * testing.T , exporter * elasticsearchTracesExporter , contents ... string ) error {
462+ req := request {
463+ bulkIndexer : exporter .bulkIndexer ,
464+ Items : nil ,
465+ }
466+ for _ , body := range contents {
467+ req .Add (bulkIndexerItem {
468+ Index : exporter .index ,
469+ Body : []byte (body ),
470+ })
471+ }
472+ return req .Export (context .TODO ())
473+ }
474+
475+ func mustSendTraces (t * testing.T , exporter * elasticsearchTracesExporter , contents ... string ) {
476+ err := sendTraces (t , exporter , contents ... )
467477 require .NoError (t , err )
468478}
469479
@@ -474,6 +484,13 @@ func mustSendTracesWithAttributes(t *testing.T, exporter *elasticsearchTracesExp
474484 span := resSpans .ScopeSpans ().At (0 ).Spans ().At (0 )
475485 scope := resSpans .ScopeSpans ().At (0 ).Scope ()
476486
477- err := exporter .pushTraceRecord (context .TODO (), resSpans .Resource (), span , scope )
487+ req := request {
488+ bulkIndexer : exporter .bulkIndexer ,
489+ Items : nil ,
490+ }
491+ item , err := exporter .traceRecordToItem (context .TODO (), resSpans .Resource (), span , scope )
492+ require .NoError (t , err )
493+ req .Add (item )
494+ err = req .Export (context .TODO ())
478495 require .NoError (t , err )
479496}
0 commit comments