@@ -332,21 +332,22 @@ def test_opentelemetry_publish(creds, span_exporter):
332
332
client .publish (TOPIC , b"message" )
333
333
spans = span_exporter .get_finished_spans ()
334
334
335
- # Span 1: Publisher Flow control span
336
- # Span 2: Publisher Batching span
337
- # Publish Create Span would still be active, and hence not exported.
338
- flow_control_span = spans [0 ]
339
- assert flow_control_span .name == "publisher flow control"
340
- assert flow_control_span .kind == trace .SpanKind .INTERNAL
341
- # Assert the Publisher Flow Control Span has a parent(the Publish Create
342
- # span is still active, and hence unexported. So, the value of parent cannot
343
- # be asserted)
344
- assert flow_control_span .parent is not None
345
-
346
- batching_span = spans [1 ]
347
- assert batching_span .name == "publisher batching"
348
- assert batching_span .kind == trace .SpanKind .INTERNAL
349
- assert batching_span .parent is not None
335
+ # Publisher Flow control and batching spans would be ended in the
336
+ # publish() function and are deterministically expected to be in the
337
+ # list of exported spans. The Publish Create span and Publish RPC span
338
+ # are run async and end at a non-deterministic time. Hence,
339
+ # asserting that we have atleast two spans(flow control and batching span)
340
+ assert len (spans ) >= 2
341
+
342
+ for span in spans :
343
+ if span .name == "publisher flow control" :
344
+ flow_control_span = span
345
+ assert flow_control_span .kind == trace .SpanKind .INTERNAL
346
+ assert flow_control_span is not None
347
+ if span .name == "publisher batching" :
348
+ batching_span = span
349
+ assert batching_span .kind == trace .SpanKind .INTERNAL
350
+ assert batching_span .parent is not None
350
351
351
352
352
353
def test_init_w_api_endpoint (creds ):
0 commit comments