Skip to content

Commit

Permalink
Merge pull request #384 from jj22ee/fix-ci-tests
Browse files Browse the repository at this point in the history
Start MySQL from GH actions, upgrade ubuntu, and remove python versions for tests
  • Loading branch information
jj22ee authored Mar 30, 2023
2 parents 82cdf8d + 4138b2e commit da9e422
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 79 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/UnitTesting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ on:

jobs:
test:
# "setup-python" action doesn't provide python 3.4 binaries for ubuntu-latest.
# Sticking to Ubuntu 18.04 as recommended here:
# https://github.com/actions/setup-python/issues/185#issuecomment-768232756
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
env:
py27: 2.7
py34: 3.4
py35: 3.5
py36: 3.6
py37: 3.7
py38: 3.8
py39: 3.9
py310: '3.10'
py311: '3.11'
DB_DATABASE: test_db
DB_USER: root
DB_PASSWORD: root
strategy:
fail-fast: false
matrix:
python-version: [py27, py34, py35, py36, py37, py38, py39, py310, py311]
python-version: [py37, py38, py39, py310, py311]
testenv: [core, ext]
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Start MySQL
if: ${{ matrix.testenv == 'ext' }}
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }};' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
- name: Setup Python
uses: actions/setup-python@v4
with:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ AWS X-Ray supports using OpenTelemetry Python and the AWS Distro for OpenTelemet

If you want additional features when tracing your Python applications, please [open an issue on the OpenTelemetry Python Instrumentation repository](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/new?labels=feature-request&template=feature_request.md&title=X-Ray%20Compatible%20Feature%20Request).

### :mega: Python Versions End-of-Support Notice

AWS X-Ray SDK for Python versions `>2.11.0` has dropped support for Python 2.7, 3.4, 3.5, and 3.6.

# AWS X-Ray SDK for Python

![Screenshot of the AWS X-Ray console](/images/example_servicemap.png?raw=true)

## Installing

The AWS X-Ray SDK for Python is compatible with Python 2.7, 3.4, 3.5, 3.6, 3.7, 3.8, and 3.9.
The AWS X-Ray SDK for Python is compatible with Python 3.7, 3.8, 3.9, 3.10, and 3.11.

Install the SDK using the following command (the SDK's non-testing dependencies will be installed).

Expand Down
51 changes: 25 additions & 26 deletions tests/ext/pymysql/test_pymysql.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import pymysql

import pytest
import testing.mysqld

from aws_xray_sdk.core import patch
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core.context import Context
from aws_xray_sdk.ext.pymysql import unpatch

MYSQL_USER = "root"
MYSQL_PASSWORD = "root"
MYSQL_HOST = "localhost"
MYSQL_PORT = 3306
MYSQL_DB_NAME = "test_db"

@pytest.fixture(scope='module', autouse=True)
def patch_module():
Expand All @@ -32,46 +36,41 @@ def construct_ctx():

def test_execute_dsn_kwargs():
q = 'SELECT 1'
with testing.mysqld.Mysqld() as mysqld:
dsn = mysqld.dsn()
conn = pymysql.connect(database=dsn['db'],
user=dsn['user'],
password='',
host=dsn['host'],
port=dsn['port'])
cur = conn.cursor()
cur.execute(q)
conn = pymysql.connect(database=MYSQL_DB_NAME,
user=MYSQL_USER,
password=MYSQL_PASSWORD,
host=MYSQL_HOST,
port=MYSQL_PORT)
cur = conn.cursor()
cur.execute(q)

subsegment = xray_recorder.current_segment().subsegments[-1]
assert subsegment.name == 'execute'
sql = subsegment.sql
assert sql['database_type'] == 'MySQL'
assert sql['user'] == dsn['user']
assert sql['user'] == MYSQL_USER
assert sql['driver_version'] == 'PyMySQL'
assert sql['database_version']


def test_execute_bad_query():
q = "SELECT blarg"
with testing.mysqld.Mysqld() as mysqld:
dsn = mysqld.dsn()
conn = pymysql.connect(database=dsn['db'],
user=dsn['user'],
password='',
host=dsn['host'],
port=dsn['port'])

cur = conn.cursor()
try:
cur.execute(q)
except Exception:
pass

conn = pymysql.connect(database=MYSQL_DB_NAME,
user=MYSQL_USER,
password=MYSQL_PASSWORD,
host=MYSQL_HOST,
port=MYSQL_PORT)
cur = conn.cursor()
try:
cur.execute(q)
except Exception:
pass

subsegment = xray_recorder.current_segment().subsegments[-1]
assert subsegment.name == "execute"
sql = subsegment.sql
assert sql['database_type'] == 'MySQL'
assert sql['user'] == dsn['user']
assert sql['user'] == MYSQL_USER
assert sql['driver_version'] == 'PyMySQL'
assert sql['database_version']

Expand Down
66 changes: 23 additions & 43 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
[tox]
skip_missing_interpreters = True
envlist =
py{27,34,35,36,37,38,39,310,311}-core
py{37,38,39,310,311}-core

; Unavailable for python 2.7 & 3.4
py{35,36,37,38,39,310,311}-ext-aiobotocore
py{37,38,39,310,311}-ext-aiobotocore

; Unavailable for python 2.7 & 3.4
py{35,36,37,38,39,310,311}-ext-aiohttp
py{37,38,39,310,311}-ext-aiohttp

py{27,34,35,36,37,38,39,310,311}-ext-botocore
py{37,38,39,310,311}-ext-botocore

py{27,34,35,36,37,38,39,310,311}-ext-bottle
py{37,38,39,310,311}-ext-bottle

; Django2 (2.2+) is only for python 3.5 +
py{35,36,37,38,39}-ext-django-2
py{37,38,39}-ext-django-2

; Django3 is only for python 3.6+
py{36,37,38,39,310}-ext-django-3
py{37,38,39,310}-ext-django-3

; Django4 is only for python 3.8+
py{38,39,310,311}-ext-django-4

py{27,34,35,36,37,38,39,310,311}-ext-flask
py{37,38,39,310,311}-ext-flask

py{27,34,35,36,37,38,39,310,311}-ext-flask_sqlalchemy
py{37,38,39,310,311}-ext-flask_sqlalchemy

py{27,34,35,36,37,38,39,310,311}-ext-httplib
py{37,38,39,310,311}-ext-httplib

py{37,38,39,310,311}-ext-httpx

py{27,34,35,36,37,38,39,310,311}-ext-pg8000
py{37,38,39,310,311}-ext-pg8000

py{27,34,35,36,37,38,39,310,311}-ext-psycopg2
py{37,38,39,310,311}-ext-psycopg2

py{27,34,35,36,37,38,39,310,311}-ext-pymysql
py{37,38,39,310,311}-ext-pymysql

py{27,34,35,36,37,38,39,310,311}-ext-pynamodb
py{37,38,39,310,311}-ext-pynamodb

py{27,34,35,36,37,38,39,310,311}-ext-requests
py{37,38,39,310,311}-ext-requests

py{27,34,35,36,37,38,39,310,311}-ext-sqlalchemy
py{37,38,39,310,311}-ext-sqlalchemy

py{27,34,35,36,37,38,39,310,311}-ext-sqlalchemy_core
py{37,38,39,310,311}-ext-sqlalchemy_core

py{27,34,35,36,37,38,39,310,311}-ext-sqlite3
py{37,38,39,310,311}-ext-sqlite3

[testenv]
passenv = TOXENV CI CODECOV_*
Expand All @@ -59,16 +55,8 @@ deps =
; Packages common to all test environments
wrapt

; Python 2.7 only deps
py{27}: enum34
py{27}: mock
py{27}: future

; Python 3.4 only deps
py34: typing >= 3.7.4.3

; Python 3.5+ only deps
py{35,36,37,38,39,310,311}: pytest-asyncio
py{37,38,39,310,311}: pytest-asyncio

ext-aiobotocore: aiobotocore >= 0.10.0
ext-aiobotocore: pytest-asyncio
Expand Down Expand Up @@ -101,19 +89,15 @@ deps =
ext-django-4: Django >=4.0,<5.0
ext-django: django-fake-model

py{27,34,35}-ext-pynamodb: pynamodb >=3.3.1,<4.4
py{27,34,35}-ext-pynamodb: botocore <1.28
py{36,37,38,39,310,311}-ext-pynamodb: pynamodb >=3.3.1
py{37,38,39,310,311}-ext-pynamodb: pynamodb >=3.3.1

ext-psycopg2: psycopg2
ext-psycopg2: testing.postgresql

ext-pg8000: pg8000 <= 1.20.0
ext-pg8000: testing.postgresql

ext-pymysql: testing.mysqld
py{27,34,35}-ext-pymysql: pymysql < 1.0.0
py{36,37,38,39,310,311}-ext-pymysql: pymysql >= 1.0.0
py{37,38,39,310,311}-ext-pymysql: pymysql >= 1.0.0

setenv =
DJANGO_SETTINGS_MODULE = tests.ext.django.app.settings
Expand All @@ -123,9 +107,7 @@ setenv =
commands =
coverage erase

; Async methods are only available for python 3.5+
py{27,34}-core: coverage run --append --source aws_xray_sdk -m pytest --ignore tests/ext --ignore tests/test_async_local_storage.py --ignore tests/test_async_recorder.py
py{35,36,37,38,39,310,311}-core: coverage run --append --source aws_xray_sdk -m pytest --ignore tests/ext
py{37,38,39,310,311}-core: coverage run --append --source aws_xray_sdk -m pytest --ignore tests/ext

ext-aiobotocore: coverage run --append --source aws_xray_sdk -m pytest tests/ext/aiobotocore

Expand Down Expand Up @@ -157,9 +139,7 @@ commands =

ext-sqlalchemy: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlalchemy

; sqlalchemy_core - 2.0 style execution is not supported for python 3.4 & 3.5
py{27,36,37,38,39,310,311}-ext-sqlalchemy_core: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlalchemy_core
py{34,35}-ext-sqlalchemy_core: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlalchemy_core --ignore tests/ext/sqlalchemy_core/test_sqlalchemy_core_2.py
py{37,38,39,310,311}-ext-sqlalchemy_core: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlalchemy_core

ext-sqlite3: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlite3

Expand Down

0 comments on commit da9e422

Please sign in to comment.