Skip to content

Commit 0b53d97

Browse files
authored
fixed destination issue with old versions of cassandra-driver (<3.18) (#761)
1 parent 0201357 commit 0b53d97

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

elasticapm/instrumentation/packages/cassandra.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ def call(self, module, method, wrapped, instance, args, kwargs):
4444
context = {}
4545
if method == "Cluster.connect":
4646
span_action = "connect"
47-
host = instance.endpoints_resolved[0].address
48-
port = instance.endpoints_resolved[0].port
47+
if hasattr(instance, "contact_points_resolved"): # < cassandra-driver 3.18
48+
host = instance.contact_points_resolved[0]
49+
port = instance.port
50+
else:
51+
host = instance.endpoints_resolved[0].address
52+
port = instance.endpoints_resolved[0].port
4953
else:
50-
host = instance.hosts[0].endpoint.address
51-
port = instance.hosts[0].endpoint.port
54+
hosts = list(instance.hosts)
55+
if hasattr(hosts[0], "endpoint"):
56+
host = hosts[0].endpoint.address
57+
port = hosts[0].endpoint.port
58+
else:
59+
# < cassandra-driver 3.18
60+
host = hosts[0].address
61+
port = instance.cluster.port
5262
span_action = "query"
5363
query = args[0] if args else kwargs.get("query")
5464
if hasattr(query, "query_string"):

0 commit comments

Comments
 (0)