Skip to content

Commit 387b0a6

Browse files
committed
fix: TypeError in agent announcement process
- Add type check in fsm.py to ensure payload is a dictionary before passing to set_from - Add defensive check in host.py to verify required keys exist in announce response - Prevents "'bool' object is not subscriptable" error in confluent_kafka tests Signed-off-by: Paulo Vital <[email protected]>
1 parent 1a05aba commit 387b0a6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/instana/agent/host.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,15 @@ def set_from(
138138
@return: None
139139
"""
140140
self.options.set_from(res_data)
141-
self.announce_data = AnnounceData(
142-
pid=res_data["pid"],
143-
agentUuid=res_data["agentUuid"],
144-
)
141+
142+
# Ensure required keys are present
143+
if "pid" in res_data and "agentUuid" in res_data:
144+
self.announce_data = AnnounceData(
145+
pid=res_data["pid"],
146+
agentUuid=res_data["agentUuid"],
147+
)
148+
else:
149+
logger.debug(f"Missing required keys in announce response: {res_data}")
145150

146151
def get_from_structure(self) -> Dict[str, str]:
147152
"""

src/instana/fsm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def announce_sensor(self, e: Any) -> bool:
148148

149149
payload = self.agent.announce(d)
150150

151-
if not payload:
151+
if not payload or not isinstance(payload, dict):
152152
logger.debug("Cannot announce sensor. Scheduling retry.")
153153
self.schedule_retry(
154154
self.announce_sensor, e, f"{self.THREAD_NAME}: announce"

0 commit comments

Comments
 (0)