@@ -45,7 +45,7 @@ def tearDown(self):
45
45
self .instrumentor .uninstrument ()
46
46
super ().tearDown ()
47
47
48
- def validate_spans (self , expected_db_statement ):
48
+ def validate_spans (self , expected_db_operation , expected_db_statement = None ):
49
49
spans = self .memory_exporter .get_finished_spans ()
50
50
self .assertEqual (len (spans ), 2 )
51
51
for span in spans :
@@ -74,7 +74,11 @@ def validate_spans(self, expected_db_statement):
74
74
MONGODB_COLLECTION_NAME ,
75
75
)
76
76
self .assertEqual (
77
- pymongo_span .attributes [SpanAttributes .DB_STATEMENT ],
77
+ pymongo_span .attributes [SpanAttributes .DB_OPERATION ],
78
+ expected_db_operation ,
79
+ )
80
+ self .assertEqual (
81
+ pymongo_span .attributes .get (SpanAttributes .DB_STATEMENT , None ),
78
82
expected_db_statement ,
79
83
)
80
84
@@ -86,11 +90,12 @@ def test_insert(self):
86
90
)
87
91
insert_result_id = insert_result .inserted_id
88
92
93
+ expected_db_operation = "insert"
89
94
expected_db_statement = (
90
- f"insert [{{'name': 'testName', 'value': 'testValue', '_id': "
95
+ f"[{{'name': 'testName', 'value': 'testValue', '_id': "
91
96
f"ObjectId('{ insert_result_id } ')}}]"
92
97
)
93
- self .validate_spans (expected_db_statement )
98
+ self .validate_spans (expected_db_operation , expected_db_statement )
94
99
95
100
def test_update (self ):
96
101
"""Should create a child span for update"""
@@ -99,29 +104,32 @@ def test_update(self):
99
104
{"name" : "testName" }, {"$set" : {"value" : "someOtherValue" }}
100
105
)
101
106
107
+ expected_db_operation = "update"
102
108
expected_db_statement = (
103
- "update [SON([('q', {'name': 'testName'}), ('u', "
109
+ "[SON([('q', {'name': 'testName'}), ('u', "
104
110
"{'$set': {'value': 'someOtherValue'}}), ('multi', False), ('upsert', False)])]"
105
111
)
106
- self .validate_spans (expected_db_statement )
112
+ self .validate_spans (expected_db_operation , expected_db_statement )
107
113
108
114
def test_find (self ):
109
115
"""Should create a child span for find"""
110
116
with self ._tracer .start_as_current_span ("rootSpan" ):
111
117
self ._collection .find_one ({"name" : "testName" })
112
118
113
- expected_db_statement = "find {'name': 'testName'}"
114
- self .validate_spans (expected_db_statement )
119
+ expected_db_operation = "find"
120
+ expected_db_statement = "{'name': 'testName'}"
121
+ self .validate_spans (expected_db_operation , expected_db_statement )
115
122
116
123
def test_delete (self ):
117
124
"""Should create a child span for delete"""
118
125
with self ._tracer .start_as_current_span ("rootSpan" ):
119
126
self ._collection .delete_one ({"name" : "testName" })
120
127
128
+ expected_db_operation = "delete"
121
129
expected_db_statement = (
122
- "delete [SON([('q', {'name': 'testName'}), ('limit', 1)])]"
130
+ "[SON([('q', {'name': 'testName'}), ('limit', 1)])]"
123
131
)
124
- self .validate_spans (expected_db_statement )
132
+ self .validate_spans (expected_db_operation , expected_db_statement )
125
133
126
134
def test_find_without_capture_statement (self ):
127
135
"""Should create a child span for find"""
@@ -130,8 +138,9 @@ def test_find_without_capture_statement(self):
130
138
with self ._tracer .start_as_current_span ("rootSpan" ):
131
139
self ._collection .find_one ({"name" : "testName" })
132
140
133
- expected_db_statement = "find"
134
- self .validate_spans (expected_db_statement )
141
+ expected_db_operation = "find"
142
+ expected_db_statement = None
143
+ self .validate_spans (expected_db_operation , expected_db_statement )
135
144
136
145
def test_uninstrument (self ):
137
146
# check that integration is working
0 commit comments