Skip to content

Commit ba7850a

Browse files
committed
Simplify existing instrumentation
1 parent e07ffc3 commit ba7850a

File tree

1 file changed

+20
-39
lines changed

1 file changed

+20
-39
lines changed

newrelic/hooks/datastore_firestore.py

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,6 @@
1818
from newrelic.common.async_wrapper import generator_wrapper
1919
from newrelic.api.datastore_trace import DatastoreTrace
2020

21-
_firestore_document_commands = (
22-
"create",
23-
"delete",
24-
"get",
25-
"set",
26-
"update",
27-
)
28-
_firestore_document_generator_commands = (
29-
"collections",
30-
)
31-
32-
_firestore_collection_commands = (
33-
"add",
34-
"get",
35-
)
36-
_firestore_collection_generator_commands = (
37-
"stream",
38-
"list_documents"
39-
)
4021

4122
_get_object_id = lambda obj, *args, **kwargs: obj.id
4223

@@ -61,28 +42,28 @@ def instrument_google_cloud_firestore_v1_base_client(module):
6142

6243

6344
def instrument_google_cloud_firestore_v1_collection(module):
64-
for name in _firestore_collection_commands:
65-
if hasattr(module.CollectionReference, name) and not getattr(getattr(module.CollectionReference, name), "_nr_wrapped", False):
66-
wrap_datastore_trace(
67-
module, "CollectionReference.%s" % name, product="Firestore", target=_get_object_id, operation=name
68-
)
69-
getattr(module.CollectionReference, name)._nr_wrapped = True
45+
if hasattr(module, "CollectionReference"):
46+
class_ = module.CollectionReference
47+
for method in ("add", "get"):
48+
if hasattr(class_, method):
49+
wrap_datastore_trace(
50+
module, "CollectionReference.%s" % method, product="Firestore", target=_get_object_id, operation=method
51+
)
7052

71-
for name in _firestore_collection_generator_commands:
72-
if hasattr(module.CollectionReference, name) and not getattr(getattr(module.CollectionReference, name), "_nr_wrapped", False):
73-
wrap_generator_method(module, "CollectionReference", name)
74-
getattr(module.CollectionReference, name)._nr_wrapped = True
53+
for method in ("stream", "list_documents"):
54+
if hasattr(class_, method):
55+
wrap_generator_method(module, "CollectionReference", method)
7556

7657

7758
def instrument_google_cloud_firestore_v1_document(module):
78-
for name in _firestore_document_commands:
79-
if hasattr(module.DocumentReference, name) and not getattr(getattr(module.DocumentReference, name), "_nr_wrapped", False):
80-
wrap_datastore_trace(
81-
module, "DocumentReference.%s" % name, product="Firestore", target=_get_object_id, operation=name
82-
)
83-
getattr(module.DocumentReference, name)._nr_wrapped = True
59+
if hasattr(module, "DocumentReference"):
60+
class_ = module.DocumentReference
61+
for method in ("create", "delete", "get", "set", "update"):
62+
if hasattr(class_, method):
63+
wrap_datastore_trace(
64+
module, "DocumentReference.%s" % method, product="Firestore", target=_get_object_id, operation=method
65+
)
8466

85-
for name in _firestore_document_generator_commands:
86-
if hasattr(module.DocumentReference, name) and not getattr(getattr(module.DocumentReference, name), "_nr_wrapped", False):
87-
wrap_generator_method(module, "DocumentReference", name)
88-
getattr(module.DocumentReference, name)._nr_wrapped = True
67+
for method in ("collections",):
68+
if hasattr(class_, method):
69+
wrap_generator_method(module, "DocumentReference", method)

0 commit comments

Comments
 (0)