Skip to content

DEBUG - run single test workflow #2392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: pczajka-debug
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/run_single_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run custom pytest

on:
push:

jobs:
run-pytest:
runs-on: ubuntu-latest
strategy:
matrix:
cloud-provider: [aws, azure, gcp]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Setup parameters file
shell: bash
env:
PARAMETERS_SECRET: ${{ secrets.PARAMETERS_SECRET }}
run: |
gpg --quiet --batch --yes --decrypt --passphrase="$PARAMETERS_SECRET" \
.github/workflows/parameters/public/parameters_${{ matrix.cloud-provider }}.py.gpg > test/parameters.py

- name: Install dependencies
run: |
python -m pip install ".[development,aio,secure-local-storage]"

- name: Run pytest
run: |
pytest -vvv -k "otel_error" .
16 changes: 12 additions & 4 deletions src/snowflake/connector/aio/_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,19 @@ async def request(
HTTP_HEADER_USER_AGENT: PYTHON_CONNECTOR_USER_AGENT,
}
try:
from opentelemetry.propagate import inject
# SNOW-1763555: inject OpenTelemetry headers if available specifically in WC3 format
# into our request headers in case tracing is enabled. This should make sure that
# our requests are accounted for properly if OpenTelemetry is used by users.
from opentelemetry.trace.propagation.tracecontext import (
TraceContextTextMapPropagator,
)

inject(headers)
except ModuleNotFoundError as e:
logger.debug(f"Opentelemtry otel injection failed because of: {e}")
TraceContextTextMapPropagator().inject(headers)
except Exception:
logger.debug(
"Opentelemtry otel injection failed",
exc_info=True,
)
if self._connection.service_name:
headers[HTTP_HEADER_SERVICE_NAME] = self._connection.service_name
if method == "post":
Expand Down
1 change: 1 addition & 0 deletions test/integ/aio/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ async def aio_connection(db_parameters):
warehouse=db_parameters["warehouse"],
protocol=db_parameters["protocol"],
timezone="UTC",
role=db_parameters.get("role", None),
)
yield cnx
await cnx.close()
1 change: 1 addition & 0 deletions test/integ/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def init_test_schema(db_parameters) -> Generator[None, None, None]:
database=ret["database"],
account=ret["account"],
protocol=ret["protocol"],
role=ret.get("role", None),
) as con:
con.cursor().execute(f"CREATE SCHEMA IF NOT EXISTS {TEST_SCHEMA}")
yield
Expand Down
16 changes: 16 additions & 0 deletions test/unit/aio/test_connection_async_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,19 @@ async def test_ssl_error_hint(caplog):
exc.value, OperationalError
)
assert "SSL error" in caplog.text and _CONNECTIVITY_ERR_MSG in caplog.text


async def test_otel_error_message_async(caplog, mock_post_requests):
"""This test assumes that OpenTelemetry is not installed when tests are running."""
with mock.patch("snowflake.connector.aio._network.SnowflakeRestful._post_request"):
with caplog.at_level(logging.DEBUG):
async with fake_db_conn():
...
assert caplog.records
important_records = [
record
for record in caplog.records
if "Opentelemtry otel injection failed" in record.message
]
assert len(important_records) == 1
assert important_records[0].exc_text is not None
Loading