Skip to content

Commit b3f32df

Browse files
feat: add psycopg2 support (Rd 11304) (#513)
* feat: add psycopg2 support (no payload) * fix: 3.11 tests and compatibility matrix values * chore: add script to simplify new instrumentation setup * refactor: span parser for multiple root span handling
1 parent de6dc3d commit b3f32df

File tree

49 files changed

+689
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+689
-440
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ target/
8181
profile_default/
8282
ipython_config.py
8383

84-
# pyenv
85-
.python-version
86-
8784
# pipenv
8885
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
8986
# However, in case of collaboration, if having platform-specific dependencies or dependencies

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.9.9

CONTRIBUTING.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ Getting your machine ready to develop against the package is a straightforward p
1515
1. Run the setup script: `python setup.py develop`.
1616
1. Run `pre-commit install` in your repository to install pre-commit hooks
1717

18-
**Note**: If you are using pycharm, ensure that you set it to use the virtualenv virtual environment manager. This is available in the menu under `PyCharm -> Preferences -> Project -> Interpreter`
18+
### MacOS Users
19+
20+
Psycopg2 cannot be installed without the `pg_config` executable available, for which you'll need to install `postgres`.
21+
22+
You can do this with `brew update && brew install postgresql`.
23+
24+
It might be necessary to throw in a `brew tap homebrew/core` along the way.
25+
26+
### PyCharm Users
27+
28+
If you are using pycharm, ensure that you set it to use the virtualenv virtual environment manager. This is available in the menu under `PyCharm -> Preferences -> Project -> Interpreter`
1929

2030
## Running the test suite
2131

@@ -57,11 +67,8 @@ TEST_ONLY_UNTESTED_NEW_VERSIONS=true python3 -m nox -e integration_tests_flask`
5767

5868
## Adding support for a new package
5969

60-
The `tested_versions` folder must be present and updated both under `src/lumigo_opentelemetry/instrumentations` and in the tested package's folder under `src/test`. For this to work, create a symlink from the package's `src/test` folder.
70+
The `tested_versions` folder must be present and updated both under `src/lumigo_opentelemetry/instrumentations` and in the tested package's folder under `src/test`. For this to work, you'll need a symlink from the package's `src/test` folder. It's recommended to use the script below to initialize your `tested_versions` folders:
6171

6272
```sh
63-
mkdir -p src/lumigo_opentelemetry/instrumentations/<PACKAGE_NAME>/tested_versions
64-
touch src/lumigo_opentelemetry/instrumentations/<PACKAGE_NAME>/tested_versions/<PACKAGE_NAME>
65-
cd src/test/integration/<PACKAGE_NAME>
66-
ln -s ../../../lumigo_opentelemetry/instrumentations/<PACKAGE_NAME>/tested_versions tested_versions
73+
./scripts/init_tested_versions.sh
6774
```

README.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -206,26 +206,27 @@ get_current_span().add_event('<error-message>', {'lumigo.type': '<error-type>'})
206206
| Instrumentation | Package | Supported Versions | | | | |
207207
| --- | --- | :---: | :---: | :---: | :---: | :---: |
208208
| | | 3.7 | 3.8 | 3.9 | 3.10 | 3.11 |
209-
| botocore | [boto3](https://pypi.org/project/boto3) | 1.17.22~1.28.40|1.17.22~1.28.40|1.17.22~1.28.40|1.17.22~1.28.40| |
209+
| botocore | [boto3](https://pypi.org/project/boto3) | 1.17.22~1.28.40|1.17.22~1.28.40|1.17.22~1.28.40|1.17.22~1.28.40|1.17.22~1.28.40|
210210
| django | [django](https://pypi.org/project/django) | |4.2.5|4.2.5|4.2.5|4.2.5|
211211
| fastapi | [fastapi](https://pypi.org/project/fastapi) | 0.56.1~0.100.0|0.56.1~0.100.0|0.56.1~0.100.0|0.56.1~0.100.0|0.56.1~0.100.0|
212212
| | | 0.100.0b2~0.103.1| 0.100.0b2~0.103.1| 0.100.0b2~0.103.1| 0.100.0b2~0.103.1| 0.100.0b2~0.103.1|
213213
| | [uvicorn](https://pypi.org/project/uvicorn) | 0.11.3~0.22.0|0.11.3~0.22.0|0.11.3~0.22.0|0.11.3~0.22.0|0.12.0~0.22.0|
214214
| flask | [flask](https://pypi.org/project/flask) | 2.0.0~2.2.5|2.0.0~2.2.5|2.0.0~2.2.5|2.0.0~2.2.5|2.0.0~2.2.5|
215215
| grpcio | [grpcio](https://pypi.org/project/grpcio) | 1.45.0~1.58.0rc1|1.45.0~1.58.0rc1|1.45.0~1.58.0rc1|1.45.0~1.58.0rc1|1.49.0~1.58.0rc1|
216-
| kafka_python | [kafka_python](https://pypi.org/project/kafka_python) | 2.0.0~2.0.2|2.0.0~2.0.2|2.0.0~2.0.2|2.0.0~2.0.2| |
217-
| pika | [pika](https://pypi.org/project/pika) | 1.0.0|1.0.0|1.0.0|1.0.0| |
218-
| | | 1.0.1~1.3.0| 1.0.1~1.3.0| 1.0.1~1.3.0| 1.0.1~1.3.0| |
219-
| | | 1.3.0rc5~1.3.2| 1.3.0rc5~1.3.2| 1.3.0rc5~1.3.2| 1.3.0rc5~1.3.2| |
216+
| kafka_python | [kafka_python](https://pypi.org/project/kafka_python) | 2.0.0~2.0.2|2.0.0~2.0.2|2.0.0~2.0.2|2.0.0~2.0.2|2.0.0~2.0.2|
217+
| pika | [pika](https://pypi.org/project/pika) | 1.0.0|1.0.0|1.0.0|1.0.0|1.0.0|
218+
| | | 1.0.1~1.3.0| 1.0.1~1.3.0| 1.0.1~1.3.0| 1.0.1~1.3.0| 1.0.1~1.3.0|
219+
| | | 1.3.0rc5~1.3.2| 1.3.0rc5~1.3.2| 1.3.0rc5~1.3.2| 1.3.0rc5~1.3.2| 1.3.0rc5~1.3.2|
220+
| psycopg2 | [psycopg2](https://pypi.org/project/psycopg2) | 2.9|2.9|2.9|2.9.5|2.9.5|
220221
| pymongo | [pymongo](https://pypi.org/project/pymongo) | 3.1.1~3.3.1|3.1.1~3.3.1|3.1.1~3.3.1|3.1.1~3.3.1|3.1.1~3.3.1|
221-
| | | 3.5.0~3.13.0| 3.5.0~3.13.0| 3.5.0~3.13.0| 3.5.0~3.13.0| 3.5.0~3.9.0|
222-
| | | 4.0.1~4.5.0| 4.0.1~4.5.0| 4.0.1~4.5.0| 4.0.1~4.5.0| 3.1|
223-
| | | 3.1| 3.1| 3.1| 3.1| 3.2|
224-
| | | 3.2| 3.2| 3.2| 3.2| |
225-
| | | 4.0| 4.0| 4.0| 4.0| |
226-
| pymysql | [pymysql](https://pypi.org/project/pymysql) | 0.9.0~0.10.1|0.9.0~0.10.1|0.9.0~0.10.1|0.9.0~0.10.1| |
227-
| | | 1.0.0~1.0.3| 1.0.0~1.0.3| 1.0.0~1.0.3| 1.0.0~1.0.3| |
228-
| | | 1.1.0~1.1.0rc2| 1.1.0~1.1.0rc2| 1.1.0~1.1.0rc2| 1.1.0~1.1.0rc2| |
222+
| | | 3.5.0~3.13.0| 3.5.0~3.13.0| 3.5.0~3.13.0| 3.5.0~3.13.0| 3.5.0~3.13.0|
223+
| | | 4.0.1~4.5.0| 4.0.1~4.5.0| 4.0.1~4.5.0| 4.0.1~4.5.0| 4.0.1~4.5.0|
224+
| | | 3.1| 3.1| 3.1| 3.1| 3.1|
225+
| | | 3.2| 3.2| 3.2| 3.2| 3.2|
226+
| | | 4.0| 4.0| 4.0| 4.0| 4.0|
227+
| pymysql | [pymysql](https://pypi.org/project/pymysql) | 0.9.0~0.10.1|0.9.0~0.10.1|0.9.0~0.10.1|0.9.0~0.10.1|0.9.0~0.10.1|
228+
| | | 1.0.0~1.0.3| 1.0.0~1.0.3| 1.0.0~1.0.3| 1.0.0~1.0.3| 1.0.0~1.0.3|
229+
| | | 1.1.0~1.1.0rc2| 1.1.0~1.1.0rc2| 1.1.0~1.1.0rc2| 1.1.0~1.1.0rc2| 1.1.0~1.1.0rc2|
229230
| redis | [redis](https://pypi.org/project/redis) | 4.1.1~4.2.0|4.1.1~4.2.0|4.1.1~4.2.0|4.1.1~4.2.0|4.1.1~4.2.0|
230231
| | | 4.2.1~4.6.0| 4.2.1~4.6.0| 4.2.1~4.6.0| 4.2.1~4.6.0| 4.2.1~4.6.0|
231232
| | | 5.0.0~5.0.0rc2| 5.0.0~5.0.0rc2| 5.0.0~5.0.0rc2| 5.0.0~5.0.0rc2| 5.0.0~5.0.0rc2|

noxfile.py

+49-2
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,12 @@ def component_tests(session):
397397
component_tests_attr_max_size(
398398
session=session,
399399
fastapi_version="0.78.0", # arbitrary version
400-
uvicorn_version="0.16.0", # arbitrary version
400+
uvicorn_version="0.16.0", # TODO don't update, see https://lumigo.atlassian.net/browse/RD-11466
401401
)
402402
component_tests_execution_tags(
403403
session=session,
404404
fastapi_version="0.78.0", # arbitrary version
405-
uvicorn_version="0.16.0", # arbitrary version
405+
uvicorn_version="0.16.0", # TODO don't update, see https://lumigo.atlassian.net/browse/RD-11466
406406
)
407407

408408

@@ -797,6 +797,52 @@ def integration_tests_pika(
797797
kill_process_and_clean_outputs(temp_file, "uvicorn", session)
798798

799799

800+
@nox.session()
801+
@nox.parametrize(
802+
"python,psycopg2_version",
803+
[
804+
(python, psycopg2_version)
805+
for python in python_versions()
806+
for psycopg2_version in dependency_versions_to_be_tested(
807+
python=python,
808+
directory="psycopg2",
809+
dependency_name="psycopg2",
810+
)
811+
],
812+
)
813+
def integration_tests_psycopg2(
814+
session,
815+
python,
816+
psycopg2_version,
817+
):
818+
with TestedVersions.save_tests_result(
819+
"psycopg2", python, "psycopg2", psycopg2_version
820+
):
821+
install_package("psycopg2", psycopg2_version, session)
822+
823+
session.install(".")
824+
825+
temp_file = create_it_tempfile("psycopg2")
826+
with session.chdir("src/test/integration/psycopg2"):
827+
session.install("-r", OTHER_REQUIREMENTS)
828+
829+
try:
830+
session.run(
831+
"pytest",
832+
"--tb",
833+
"native",
834+
"--log-cli-level=INFO",
835+
"--color=yes",
836+
"-v",
837+
"./tests/test_psycopg2.py",
838+
env={
839+
"LUMIGO_DEBUG_SPANDUMP": temp_file,
840+
},
841+
)
842+
finally:
843+
kill_process_and_clean_outputs(temp_file, "test_psycopg2", session)
844+
845+
800846
@nox.session()
801847
@nox.parametrize(
802848
"python,pymongo_version",
@@ -1001,6 +1047,7 @@ def integration_tests_redis(
10011047
temp_file = create_it_tempfile("redis")
10021048
with session.chdir("src/test/integration/redis"):
10031049
session.install("-r", OTHER_REQUIREMENTS)
1050+
10041051
try:
10051052
session.run(
10061053
"pytest",

scripts/checks.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ set -eo pipefail
55
pre-commit run -a
66

77
# run u.t
8-
pushd src/test/
9-
pytest ci
10-
pytest unit
8+
pushd src/test
9+
pytest ci
10+
pytest unit
1111
popd
1212

1313
# branch name validation
@@ -16,3 +16,6 @@ then
1616
# Check if branch contains RD ticket value.
1717
echo "$CIRCLE_BRANCH" | grep -E "[RDrd]-[0-9]+|master|version-testing-[0-9]{4}[0-9]{2}[0-9]{2}|dependabot/" || { echo "Please create a relevent ticket in Jira and connect it to this branch. Use jiranch." ; exit 1; }
1818
fi
19+
20+
# update the README's package compatibility matrix
21+
python3 -m scripts.update_supported_packages_documentation

scripts/init_tested_versions.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
PACKAGE_NAME="$1"
4+
SUPPORTED_VERSIONS=(3.7 3.8 3.9 3.10 3.11)
5+
6+
if [ -z "$PACKAGE_NAME" ]; then
7+
echo "Usage: $0 <PACKAGE_NAME>"
8+
exit 1
9+
fi
10+
11+
base_folder="src/lumigo_opentelemetry/instrumentations/${PACKAGE_NAME}/tested_versions"
12+
test_folder="src/test/integration/${PACKAGE_NAME}"
13+
14+
echo "Creating tested versions folders under ${base_folder}..."
15+
for python_version in "${SUPPORTED_VERSIONS[@]}"; do
16+
echo "Creating ${python_version} folder..."
17+
version_folder="${base_folder}/${python_version}"
18+
mkdir -p "$version_folder"
19+
touch "${version_folder}/${PACKAGE_NAME}"
20+
done
21+
22+
echo ""
23+
echo "Creating tested versions symlink in ${test_folder}..."
24+
mkdir -p "$test_folder"
25+
pushd "$test_folder"
26+
if [ -e tested_versions ]; then
27+
echo "Removing old tested_versions symlink..."
28+
rm tested_versions
29+
fi
30+
echo "linking from ${test_folder} to ${base_folder}..."
31+
ln -s ../../../../${base_folder} tested_versions
32+
popd
33+
34+
echo ""
35+
echo "Done"

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"opentelemetry-instrumentation-grpc==0.36b0",
3232
"opentelemetry-instrumentation-kafka-python==0.36b0",
3333
"opentelemetry-instrumentation-pika==0.36b0",
34+
"opentelemetry-instrumentation-psycopg2==0.36b0",
3435
"opentelemetry-instrumentation-pymongo==0.36b0",
3536
"opentelemetry-instrumentation-pymysql==0.36b0",
3637
"opentelemetry-instrumentation-requests==0.36b0",

0 commit comments

Comments
 (0)