@@ -45,7 +45,7 @@ def tearDown(self):
4545 self .instrumentor .uninstrument ()
4646 super ().tearDown ()
4747
48- def validate_spans (self , expected_db_statement ):
48+ def validate_spans (self , expected_db_operation , expected_db_statement = None ):
4949 spans = self .memory_exporter .get_finished_spans ()
5050 self .assertEqual (len (spans ), 2 )
5151 for span in spans :
@@ -74,7 +74,11 @@ def validate_spans(self, expected_db_statement):
7474 MONGODB_COLLECTION_NAME ,
7575 )
7676 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 ),
7882 expected_db_statement ,
7983 )
8084
@@ -86,11 +90,12 @@ def test_insert(self):
8690 )
8791 insert_result_id = insert_result .inserted_id
8892
93+ expected_db_operation = "insert"
8994 expected_db_statement = (
90- f"insert [{{'name': 'testName', 'value': 'testValue', '_id': "
95+ f"[{{'name': 'testName', 'value': 'testValue', '_id': "
9196 f"ObjectId('{ insert_result_id } ')}}]"
9297 )
93- self .validate_spans (expected_db_statement )
98+ self .validate_spans (expected_db_operation , expected_db_statement )
9499
95100 def test_update (self ):
96101 """Should create a child span for update"""
@@ -99,29 +104,32 @@ def test_update(self):
99104 {"name" : "testName" }, {"$set" : {"value" : "someOtherValue" }}
100105 )
101106
107+ expected_db_operation = "update"
102108 expected_db_statement = (
103- "update [SON([('q', {'name': 'testName'}), ('u', "
109+ "[SON([('q', {'name': 'testName'}), ('u', "
104110 "{'$set': {'value': 'someOtherValue'}}), ('multi', False), ('upsert', False)])]"
105111 )
106- self .validate_spans (expected_db_statement )
112+ self .validate_spans (expected_db_operation , expected_db_statement )
107113
108114 def test_find (self ):
109115 """Should create a child span for find"""
110116 with self ._tracer .start_as_current_span ("rootSpan" ):
111117 self ._collection .find_one ({"name" : "testName" })
112118
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 )
115122
116123 def test_delete (self ):
117124 """Should create a child span for delete"""
118125 with self ._tracer .start_as_current_span ("rootSpan" ):
119126 self ._collection .delete_one ({"name" : "testName" })
120127
128+ expected_db_operation = "delete"
121129 expected_db_statement = (
122- "delete [SON([('q', {'name': 'testName'}), ('limit', 1)])]"
130+ "[SON([('q', {'name': 'testName'}), ('limit', 1)])]"
123131 )
124- self .validate_spans (expected_db_statement )
132+ self .validate_spans (expected_db_operation , expected_db_statement )
125133
126134 def test_find_without_capture_statement (self ):
127135 """Should create a child span for find"""
@@ -130,8 +138,9 @@ def test_find_without_capture_statement(self):
130138 with self ._tracer .start_as_current_span ("rootSpan" ):
131139 self ._collection .find_one ({"name" : "testName" })
132140
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 )
135144
136145 def test_uninstrument (self ):
137146 # check that integration is working
0 commit comments