Skip to content

Commit d5aebef

Browse files
andreamattcursoragentemdneto
authored
cassandra: use _instruments_any instead of _instruments for driver deps (#4182)
* cassandra: use _instruments_any instead of _instruments for driver deps The cassandra instrumentation listed both cassandra-driver and scylla-driver in _instruments, which requires ALL listed packages to be installed. Since users install one OR the other (they are alternative drivers for the same API), this should use _instruments_any so that having either driver installed is sufficient. This follows the same pattern already used by psycopg2 and kafka-python instrumentations, introduced in #3610. Co-authored-by: Cursor <cursoragent@cursor.com> * fix ci Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> * fix uv.lock Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> --------- Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: emdneto <9735060+emdneto@users.noreply.github.com>
1 parent 93bea2d commit d5aebef

File tree

11 files changed

+523
-241
lines changed

11 files changed

+523
-241
lines changed

.github/workflows/core_contrib_test_0.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,8 +3023,8 @@ jobs:
30233023
- name: Run tests
30243024
run: tox -e py39-test-instrumentation-asyncio -- -ra
30253025

3026-
py39-test-instrumentation-cassandra:
3027-
name: instrumentation-cassandra
3026+
py39-test-instrumentation-cassandra-driver:
3027+
name: instrumentation-cassandra-driver
30283028
runs-on: ubuntu-latest
30293029
timeout-minutes: 30
30303030
steps:
@@ -3051,7 +3051,37 @@ jobs:
30513051
run: pip install tox-uv
30523052

30533053
- name: Run tests
3054-
run: tox -e py39-test-instrumentation-cassandra -- -ra
3054+
run: tox -e py39-test-instrumentation-cassandra-driver -- -ra
3055+
3056+
py39-test-instrumentation-cassandra-scylla:
3057+
name: instrumentation-cassandra-scylla
3058+
runs-on: ubuntu-latest
3059+
timeout-minutes: 30
3060+
steps:
3061+
- name: Checkout contrib repo @ SHA - ${{ env.CONTRIB_REPO_SHA }}
3062+
uses: actions/checkout@v4
3063+
with:
3064+
repository: open-telemetry/opentelemetry-python-contrib
3065+
ref: ${{ env.CONTRIB_REPO_SHA }}
3066+
3067+
- name: Checkout core repo @ SHA - ${{ env.CORE_REPO_SHA }}
3068+
uses: actions/checkout@v4
3069+
with:
3070+
repository: open-telemetry/opentelemetry-python
3071+
ref: ${{ env.CORE_REPO_SHA }}
3072+
path: opentelemetry-python
3073+
3074+
- name: Set up Python 3.9
3075+
uses: actions/setup-python@v5
3076+
with:
3077+
python-version: "3.9"
3078+
architecture: "x64"
3079+
3080+
- name: Install tox
3081+
run: pip install tox-uv
3082+
3083+
- name: Run tests
3084+
run: tox -e py39-test-instrumentation-cassandra-scylla -- -ra
30553085

30563086
py39-test-processor-baggage:
30573087
name: processor-baggage

.github/workflows/test_2.yml

Lines changed: 113 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,8 +1381,8 @@ jobs:
13811381
- name: Run tests
13821382
run: tox -e py313-test-instrumentation-asyncio -- -ra
13831383

1384-
py39-test-instrumentation-cassandra_ubuntu-latest:
1385-
name: instrumentation-cassandra 3.9 Ubuntu
1384+
py39-test-instrumentation-cassandra-driver_ubuntu-latest:
1385+
name: instrumentation-cassandra-driver 3.9 Ubuntu
13861386
runs-on: ubuntu-latest
13871387
timeout-minutes: 30
13881388
steps:
@@ -1398,10 +1398,48 @@ jobs:
13981398
run: pip install tox-uv
13991399

14001400
- name: Run tests
1401-
run: tox -e py39-test-instrumentation-cassandra -- -ra
1401+
run: tox -e py39-test-instrumentation-cassandra-driver -- -ra
14021402

1403-
py310-test-instrumentation-cassandra_ubuntu-latest:
1404-
name: instrumentation-cassandra 3.10 Ubuntu
1403+
py39-test-instrumentation-cassandra-scylla_ubuntu-latest:
1404+
name: instrumentation-cassandra-scylla 3.9 Ubuntu
1405+
runs-on: ubuntu-latest
1406+
timeout-minutes: 30
1407+
steps:
1408+
- name: Checkout repo @ SHA - ${{ github.sha }}
1409+
uses: actions/checkout@v4
1410+
1411+
- name: Set up Python 3.9
1412+
uses: actions/setup-python@v5
1413+
with:
1414+
python-version: "3.9"
1415+
1416+
- name: Install tox
1417+
run: pip install tox-uv
1418+
1419+
- name: Run tests
1420+
run: tox -e py39-test-instrumentation-cassandra-scylla -- -ra
1421+
1422+
py310-test-instrumentation-cassandra-driver_ubuntu-latest:
1423+
name: instrumentation-cassandra-driver 3.10 Ubuntu
1424+
runs-on: ubuntu-latest
1425+
timeout-minutes: 30
1426+
steps:
1427+
- name: Checkout repo @ SHA - ${{ github.sha }}
1428+
uses: actions/checkout@v4
1429+
1430+
- name: Set up Python 3.10
1431+
uses: actions/setup-python@v5
1432+
with:
1433+
python-version: "3.10"
1434+
1435+
- name: Install tox
1436+
run: pip install tox-uv
1437+
1438+
- name: Run tests
1439+
run: tox -e py310-test-instrumentation-cassandra-driver -- -ra
1440+
1441+
py310-test-instrumentation-cassandra-scylla_ubuntu-latest:
1442+
name: instrumentation-cassandra-scylla 3.10 Ubuntu
14051443
runs-on: ubuntu-latest
14061444
timeout-minutes: 30
14071445
steps:
@@ -1417,10 +1455,29 @@ jobs:
14171455
run: pip install tox-uv
14181456

14191457
- name: Run tests
1420-
run: tox -e py310-test-instrumentation-cassandra -- -ra
1458+
run: tox -e py310-test-instrumentation-cassandra-scylla -- -ra
1459+
1460+
py311-test-instrumentation-cassandra-driver_ubuntu-latest:
1461+
name: instrumentation-cassandra-driver 3.11 Ubuntu
1462+
runs-on: ubuntu-latest
1463+
timeout-minutes: 30
1464+
steps:
1465+
- name: Checkout repo @ SHA - ${{ github.sha }}
1466+
uses: actions/checkout@v4
1467+
1468+
- name: Set up Python 3.11
1469+
uses: actions/setup-python@v5
1470+
with:
1471+
python-version: "3.11"
1472+
1473+
- name: Install tox
1474+
run: pip install tox-uv
1475+
1476+
- name: Run tests
1477+
run: tox -e py311-test-instrumentation-cassandra-driver -- -ra
14211478

1422-
py311-test-instrumentation-cassandra_ubuntu-latest:
1423-
name: instrumentation-cassandra 3.11 Ubuntu
1479+
py311-test-instrumentation-cassandra-scylla_ubuntu-latest:
1480+
name: instrumentation-cassandra-scylla 3.11 Ubuntu
14241481
runs-on: ubuntu-latest
14251482
timeout-minutes: 30
14261483
steps:
@@ -1436,10 +1493,29 @@ jobs:
14361493
run: pip install tox-uv
14371494

14381495
- name: Run tests
1439-
run: tox -e py311-test-instrumentation-cassandra -- -ra
1496+
run: tox -e py311-test-instrumentation-cassandra-scylla -- -ra
1497+
1498+
py312-test-instrumentation-cassandra-driver_ubuntu-latest:
1499+
name: instrumentation-cassandra-driver 3.12 Ubuntu
1500+
runs-on: ubuntu-latest
1501+
timeout-minutes: 30
1502+
steps:
1503+
- name: Checkout repo @ SHA - ${{ github.sha }}
1504+
uses: actions/checkout@v4
1505+
1506+
- name: Set up Python 3.12
1507+
uses: actions/setup-python@v5
1508+
with:
1509+
python-version: "3.12"
1510+
1511+
- name: Install tox
1512+
run: pip install tox-uv
1513+
1514+
- name: Run tests
1515+
run: tox -e py312-test-instrumentation-cassandra-driver -- -ra
14401516

1441-
py312-test-instrumentation-cassandra_ubuntu-latest:
1442-
name: instrumentation-cassandra 3.12 Ubuntu
1517+
py312-test-instrumentation-cassandra-scylla_ubuntu-latest:
1518+
name: instrumentation-cassandra-scylla 3.12 Ubuntu
14431519
runs-on: ubuntu-latest
14441520
timeout-minutes: 30
14451521
steps:
@@ -1455,10 +1531,29 @@ jobs:
14551531
run: pip install tox-uv
14561532

14571533
- name: Run tests
1458-
run: tox -e py312-test-instrumentation-cassandra -- -ra
1534+
run: tox -e py312-test-instrumentation-cassandra-scylla -- -ra
1535+
1536+
py313-test-instrumentation-cassandra-driver_ubuntu-latest:
1537+
name: instrumentation-cassandra-driver 3.13 Ubuntu
1538+
runs-on: ubuntu-latest
1539+
timeout-minutes: 30
1540+
steps:
1541+
- name: Checkout repo @ SHA - ${{ github.sha }}
1542+
uses: actions/checkout@v4
1543+
1544+
- name: Set up Python 3.13
1545+
uses: actions/setup-python@v5
1546+
with:
1547+
python-version: "3.13"
1548+
1549+
- name: Install tox
1550+
run: pip install tox-uv
1551+
1552+
- name: Run tests
1553+
run: tox -e py313-test-instrumentation-cassandra-driver -- -ra
14591554

1460-
py313-test-instrumentation-cassandra_ubuntu-latest:
1461-
name: instrumentation-cassandra 3.13 Ubuntu
1555+
py313-test-instrumentation-cassandra-scylla_ubuntu-latest:
1556+
name: instrumentation-cassandra-scylla 3.13 Ubuntu
14621557
runs-on: ubuntu-latest
14631558
timeout-minutes: 30
14641559
steps:
@@ -1474,10 +1569,10 @@ jobs:
14741569
run: pip install tox-uv
14751570

14761571
- name: Run tests
1477-
run: tox -e py313-test-instrumentation-cassandra -- -ra
1572+
run: tox -e py313-test-instrumentation-cassandra-scylla -- -ra
14781573

1479-
pypy3-test-instrumentation-cassandra_ubuntu-latest:
1480-
name: instrumentation-cassandra pypy-3.9 Ubuntu
1574+
pypy3-test-instrumentation-cassandra-scylla_ubuntu-latest:
1575+
name: instrumentation-cassandra-scylla pypy-3.9 Ubuntu
14811576
runs-on: ubuntu-latest
14821577
timeout-minutes: 30
14831578
steps:
@@ -1493,7 +1588,7 @@ jobs:
14931588
run: pip install tox-uv
14941589

14951590
- name: Run tests
1496-
run: tox -e pypy3-test-instrumentation-cassandra -- -ra
1591+
run: tox -e pypy3-test-instrumentation-cassandra-scylla -- -ra
14971592

14981593
py39-test-processor-baggage_ubuntu-latest:
14991594
name: processor-baggage 3.9 Ubuntu

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5858

5959
### Fixed
6060

61+
- `opentelemetry-instrumentation-cassandra`: Use `_instruments_any` instead of `_instruments` for driver dependencies so that having either `cassandra-driver` or `scylla-driver` installed is sufficient
62+
([#4182](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4182))
6163
- `opentelemetry-instrumentation-asyncpg`: Hydrate span attributes before creation so samplers can filter on database details
6264
([#3841](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3841))
6365
- `opentelemetry-instrumentation-django`: Fix exemplars generation for `http.server.(request.)duration`

instrumentation/opentelemetry-instrumentation-cassandra/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ dependencies = [
3232
]
3333

3434
[project.optional-dependencies]
35-
instruments = [
35+
instruments = []
36+
instruments-any = [
3637
"cassandra-driver ~= 3.25",
3738
"scylla-driver ~= 3.25",
3839
]

instrumentation/opentelemetry-instrumentation-cassandra/src/opentelemetry/instrumentation/cassandra/__init__.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@
3737
---
3838
"""
3939

40+
from importlib.metadata import PackageNotFoundError, distribution
4041
from typing import Collection
4142

4243
import cassandra.cluster
4344
from wrapt import wrap_function_wrapper
4445

4546
from opentelemetry import trace
46-
from opentelemetry.instrumentation.cassandra.package import _instruments
47+
from opentelemetry.instrumentation.cassandra.package import (
48+
_instruments_any,
49+
_instruments_cassandra_driver,
50+
_instruments_scylla_driver,
51+
)
4752
from opentelemetry.instrumentation.cassandra.version import __version__
4853
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
4954
from opentelemetry.instrumentation.utils import unwrap
@@ -96,7 +101,22 @@ def _traced_execute_async(func, instance, args, kwargs):
96101

97102
class CassandraInstrumentor(BaseInstrumentor):
98103
def instrumentation_dependencies(self) -> Collection[str]:
99-
return _instruments
104+
# Determine which package of cassandra is installed.
105+
# Right now there are two packages, cassandra-driver and scylla-driver.
106+
# The latter is a fork with additional support for ScyllaDB.
107+
try:
108+
distribution("cassandra-driver")
109+
return (_instruments_cassandra_driver,)
110+
except PackageNotFoundError:
111+
pass
112+
113+
try:
114+
distribution("scylla-driver")
115+
return (_instruments_scylla_driver,)
116+
except PackageNotFoundError:
117+
pass
118+
119+
return _instruments_any
100120

101121
def _instrument(self, **kwargs):
102122
_instrument(

instrumentation/opentelemetry-instrumentation-cassandra/src/opentelemetry/instrumentation/cassandra/package.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
# limitations under the License.
1414

1515

16-
_instruments = ("cassandra-driver ~= 3.25", "scylla-driver ~= 3.25")
16+
_instruments_cassandra_driver = "cassandra-driver ~= 3.25"
17+
_instruments_scylla_driver = "scylla-driver ~= 3.25"
18+
19+
_instruments = ()
20+
_instruments_any = (_instruments_cassandra_driver, _instruments_scylla_driver)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
asgiref==3.8.1
2+
pyasyncore==1.0.4 # for python 3.13 (should removed when cassandra-driver replaces asyncore with recommended asyncio)
3+
click==8.1.7
4+
Deprecated==1.2.14
5+
geomet==0.2.1.post1
6+
iniconfig==2.0.0
7+
packaging==24.0
8+
pluggy==1.5.0
9+
py-cpuinfo==9.0.0
10+
pytest==7.4.4
11+
python-snappy==0.7.3
12+
PyYAML==6.0.1
13+
scylla-driver==3.26.6
14+
six==1.16.0
15+
tomli==2.0.1
16+
typing_extensions==4.12.2
17+
wrapt==1.16.0
18+
zipp==3.19.2
19+
-e opentelemetry-instrumentation
20+
-e instrumentation/opentelemetry-instrumentation-cassandra

instrumentation/opentelemetry-instrumentation-cassandra/test-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pluggy==1.5.0
1010
py-cpuinfo==9.0.0
1111
pytest==7.4.4
1212
PyYAML==6.0.1
13-
scylla-driver==3.26.6
1413
six==1.16.0
1514
tomli==2.0.1
1615
typing_extensions==4.12.2

0 commit comments

Comments
 (0)