18
18
from newrelic .common .async_wrapper import generator_wrapper
19
19
from newrelic .api .datastore_trace import DatastoreTrace
20
20
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
- )
40
21
41
22
_get_object_id = lambda obj , * args , ** kwargs : obj .id
42
23
@@ -61,28 +42,28 @@ def instrument_google_cloud_firestore_v1_base_client(module):
61
42
62
43
63
44
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
+ )
70
52
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 )
75
56
76
57
77
58
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
+ )
84
66
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