Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPansino committed Nov 19, 2024
1 parent 8d904f7 commit c1aa140
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
15 changes: 12 additions & 3 deletions newrelic/hooks/datastore_pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from newrelic.api.function_trace import wrap_function_trace
from newrelic.common.object_wrapper import wrap_function_wrapper


_pymongo_client_async_methods = (
"aggregate",
"aggregate_raw_batches",
Expand Down Expand Up @@ -138,14 +137,19 @@ def instrument_pymongo_synchronous_pool(module):
module, "Connection.__init__", name=f"{module.__name__}:Connection.__init__", terminal=True, rollup=rollup
)


def instrument_pymongo_asynchronous_pool(module):
rollup = ("Datastore/all", "Datastore/MongoDB/all")

# Must name function explicitly as pymongo overrides the
# __getattr__() method in a way that breaks introspection.

wrap_function_trace(
module, "AsyncConnection.__init__", name=f"{module.__name__}:AsyncConnection.__init__", terminal=True, rollup=rollup
module,
"AsyncConnection.__init__",
name=f"{module.__name__}:AsyncConnection.__init__",
terminal=True,
rollup=rollup,
)


Expand All @@ -164,14 +168,19 @@ def instrument_pymongo_synchronous_mongo_client(module):
module, "MongoClient.__init__", name=f"{module.__name__}:MongoClient.__init__", terminal=True, rollup=rollup
)


def instrument_pymongo_asynchronous_mongo_client(module):
rollup = ("Datastore/all", "Datastore/MongoDB/all")

# Must name function explicitly as pymongo overrides the
# __getattr__() method in a way that breaks introspection.

wrap_function_trace(
module, "AsyncMongoClient.__init__", name=f"{module.__name__}:AsyncMongoClient.__init__", terminal=True, rollup=rollup
module,
"AsyncMongoClient.__init__",
name=f"{module.__name__}:AsyncMongoClient.__init__",
terminal=True,
rollup=rollup,
)


Expand Down
7 changes: 3 additions & 4 deletions tests/datastore_pymongo/test_async_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@

import sqlite3

import pytest

import pymongo
import pytest
from pymongo.asynchronous.mongo_client import AsyncMongoClient
from testing_support.db_settings import mongodb_settings
from testing_support.validators.validate_span_events import validate_span_events
from testing_support.validators.validate_database_duration import (
validate_database_duration,
)
from testing_support.validators.validate_span_events import validate_span_events
from testing_support.validators.validate_transaction_errors import (
validate_transaction_errors,
)
Expand All @@ -34,7 +33,7 @@
from newrelic.common import system_info
from newrelic.common.package_version_utils import get_package_version_tuple

# Skip if AsyncMongoClient has not been implemented yet
# Skip if AsyncMongoClient has not been implemented yet
if get_package_version_tuple("pymongo") < (4, 9, 0):
pytest.skip(allow_module_level=True, reason="AsyncMongoClient not available.")

Expand Down
2 changes: 1 addition & 1 deletion tests/datastore_pymongo/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import pymongo
from testing_support.db_settings import mongodb_settings
from testing_support.validators.validate_span_events import validate_span_events
from testing_support.validators.validate_database_duration import (
validate_database_duration,
)
from testing_support.validators.validate_span_events import validate_span_events
from testing_support.validators.validate_transaction_errors import (
validate_transaction_errors,
)
Expand Down
3 changes: 1 addition & 2 deletions tests/datastore_pymongo/test_uninstrumented_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
# limitations under the License.

import pytest

from pymongo.synchronous.mongo_client import MongoClient
from pymongo.asynchronous.mongo_client import AsyncMongoClient
from pymongo.synchronous.mongo_client import MongoClient
from testing_support.db_settings import mongodb_settings

DB_SETTINGS = mongodb_settings()[0]
Expand Down

0 comments on commit c1aa140

Please sign in to comment.