-
Notifications
You must be signed in to change notification settings - Fork 651
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
Add support for db cursors and connections in context managers #1028
Conversation
Here is an example snippet that will not report tracing without this patch: with psycopg2.connect(...) as conn, conn.cursor() as cursor: cursor.execute("select 1;")
Kind of forgot there were other drivers I might want to add the same test for. However, running into a test fail with that, so I'll mark as draft until I've looked into that. |
Since anonymous volumes do not get reused, each test run left behind new volumes.
The same function exists in the aiopg tests under a different name.
735a7f0
to
7f43a85
Compare
Turns out the error was just due to The wrapper is pretty straight-forward, so I was not sure whether to add the tests to all packages and stopped half-way. I also removed some unused imports and renamed a helper function for consistency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good, thanks for picking this up. Could you add a note in the dbapi changelog?
Done. |
Awesome! Thanks @ffe4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this PR just for dbapi? If you're willing, looks like asyncpg also supports context managers for transactions https://magicstack.github.io/asyncpg/current/api/index.html?highlight=context%20manager#transactions
tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py
Show resolved
Hide resolved
The async with self._connection.transaction():
await self._connection.execute("SELECT 42;") |
@codeboten LGTM
Looks like this is covered already since it just executes the |
Thank you for finishing this, @ffe4 |
Description
This PR is a replacement for #821 with added docker tests.
I also added the
-v
flag todocker-compose down
in the tox config to clean up anonymous volumes that get left behind and not reused.Type of change
Checklist: