Skip to content

Commit

Permalink
* Contribute.MD should point out that manually running black must use…
Browse files Browse the repository at this point in the history
… --config parameter pointing to the pyproject.toml as tests will fail upstream otherwise.
  • Loading branch information
reiktar committed Mar 15, 2024
1 parent 6025de9 commit 08e0c50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
from psycopg import ( # pylint: disable=import-self,no-name-in-module
AsyncCursor as pg_async_cursor,
)
from psycopg import Cursor as pg_cursor # pylint: disable=no-name-in-module,import-self
from psycopg import ( # pylint: disable=no-name-in-module,import-self
Cursor as pg_cursor,
)
from psycopg.sql import Composed # pylint: disable=no-name-in-module

from opentelemetry.instrumentation import dbapi
Expand Down Expand Up @@ -182,7 +184,9 @@ def _instrument(self, **kwargs):
def _uninstrument(self, **kwargs):
""" "Disable Psycopg instrumentation"""
dbapi.unwrap_connect(psycopg, "connect") # pylint: disable=no-member
dbapi.unwrap_connect(psycopg.Connection, "connect") # pylint: disable=no-member
dbapi.unwrap_connect(
psycopg.Connection, "connect" # pylint: disable=no-member
)
dbapi.unwrap_connect(
psycopg.AsyncConnection, "connect" # pylint: disable=no-member
)
Expand All @@ -194,7 +198,9 @@ def instrument_connection(connection, tracer_provider=None):
connection._is_instrumented_by_opentelemetry = False

if not connection._is_instrumented_by_opentelemetry:
setattr(connection, _OTEL_CURSOR_FACTORY_KEY, connection.cursor_factory)
setattr(
connection, _OTEL_CURSOR_FACTORY_KEY, connection.cursor_factory
)
connection.cursor_factory = _new_cursor_factory(
tracer_provider=tracer_provider
)
Expand All @@ -208,7 +214,9 @@ def instrument_connection(connection, tracer_provider=None):
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql
@staticmethod
def uninstrument_connection(connection):
connection.cursor_factory = getattr(connection, _OTEL_CURSOR_FACTORY_KEY, None)
connection.cursor_factory = getattr(
connection, _OTEL_CURSOR_FACTORY_KEY, None
)

return connection

Expand Down Expand Up @@ -244,7 +252,9 @@ async def wrapped_connection(
new_factory_kwargs = {"db_api": self}
if base_cursor_factory:
new_factory_kwargs["base_factory"] = base_cursor_factory
kwargs["cursor_factory"] = _new_cursor_async_factory(**new_factory_kwargs)
kwargs["cursor_factory"] = _new_cursor_async_factory(
**new_factory_kwargs
)
connection = await connect_method(*args, **kwargs)
self.get_connection_attributes(connection)
return connection
Expand Down Expand Up @@ -307,7 +317,9 @@ def callproc(self, *args, **kwargs):
return TracedCursorFactory


def _new_cursor_async_factory(db_api=None, base_factory=None, tracer_provider=None):
def _new_cursor_async_factory(
db_api=None, base_factory=None, tracer_provider=None
):
if not db_api:
db_api = DatabaseApiAsyncIntegration(
__name__,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ async def test_span_name_async(self):
)
await cursor.execute("tab\tseparated query")
await cursor.execute("/* leading comment */ query")
await cursor.execute("/* leading comment */ query /* trailing comment */")
await cursor.execute(
"/* leading comment */ query /* trailing comment */"
)
await cursor.execute("query /* trailing comment */")

spans_list = self.memory_exporter.get_finished_spans()
Expand Down

0 comments on commit 08e0c50

Please sign in to comment.