@@ -81,8 +81,6 @@ def test_trace_kafka_python_send(self) -> None:
81
81
assert kafka_span .data ["kafka" ]["access" ] == "send"
82
82
83
83
def test_trace_kafka_python_consume (self ) -> None :
84
- agent .options .allow_exit_as_root = False
85
-
86
84
# Produce some events
87
85
self .producer .send (testenv ["kafka_topic" ], b"raw_bytes1" )
88
86
self .producer .send (testenv ["kafka_topic" ], b"raw_bytes2" )
@@ -125,9 +123,48 @@ def test_trace_kafka_python_consume(self) -> None:
125
123
assert kafka_span .data ["kafka" ]["service" ] == testenv ["kafka_topic" ]
126
124
assert kafka_span .data ["kafka" ]["access" ] == "consume"
127
125
128
- def test_trace_kafka_python_error (self ) -> None :
129
- agent .options .allow_exit_as_root = False
126
+ def test_trace_kafka_python_poll (self ) -> None :
127
+ # Produce some events
128
+ self .producer .send (testenv ["kafka_topic" ], b"raw_bytes1" )
129
+ self .producer .send (testenv ["kafka_topic" ], b"raw_bytes2" )
130
+ self .producer .flush ()
131
+
132
+ # Consume the events
133
+ consumer = KafkaConsumer (
134
+ testenv ["kafka_topic" ],
135
+ bootstrap_servers = testenv ["kafka_bootstrap_servers" ],
136
+ auto_offset_reset = "earliest" , # consume earliest available messages
137
+ enable_auto_commit = False , # do not auto-commit offsets
138
+ consumer_timeout_ms = 1000 ,
139
+ )
140
+
141
+ with tracer .start_as_current_span ("test" ):
142
+ msg = consumer .poll () # noqa: F841
143
+
144
+ consumer .close ()
130
145
146
+ spans = self .recorder .queued_spans ()
147
+ assert len (spans ) == 2
148
+
149
+ kafka_span = spans [0 ]
150
+ test_span = spans [1 ]
151
+
152
+ # Same traceId
153
+ assert test_span .t == kafka_span .t
154
+
155
+ # Parent relationships
156
+ assert kafka_span .p == test_span .s
157
+
158
+ # Error logging
159
+ assert not test_span .ec
160
+ assert not kafka_span .ec
161
+
162
+ assert kafka_span .n == "kafka"
163
+ assert kafka_span .k == SpanKind .SERVER
164
+ assert kafka_span .data ["kafka" ]["service" ] == testenv ["kafka_topic" ]
165
+ assert kafka_span .data ["kafka" ]["access" ] == "poll"
166
+
167
+ def test_trace_kafka_python_error (self ) -> None :
131
168
# Consume the events
132
169
consumer = KafkaConsumer (
133
170
"inexistent_kafka_topic" ,
0 commit comments