@@ -45,7 +45,9 @@ def tearDown(self):
4545        self .instrumentor .uninstrument ()
4646        super ().tearDown ()
4747
48-     def  validate_spans (self , expected_db_statement ):
48+     def  validate_spans (
49+         self , expected_db_operation , expected_db_statement = None 
50+     ):
4951        spans  =  self .memory_exporter .get_finished_spans ()
5052        self .assertEqual (len (spans ), 2 )
5153        for  span  in  spans :
@@ -74,7 +76,11 @@ def validate_spans(self, expected_db_statement):
7476            MONGODB_COLLECTION_NAME ,
7577        )
7678        self .assertEqual (
77-             pymongo_span .attributes [SpanAttributes .DB_STATEMENT ],
79+             pymongo_span .attributes [SpanAttributes .DB_OPERATION ],
80+             expected_db_operation ,
81+         )
82+         self .assertEqual (
83+             pymongo_span .attributes .get (SpanAttributes .DB_STATEMENT , None ),
7884            expected_db_statement ,
7985        )
8086
@@ -86,11 +92,12 @@ def test_insert(self):
8692            )
8793            insert_result_id  =  insert_result .inserted_id 
8894
95+         expected_db_operation  =  "insert" 
8996        expected_db_statement  =  (
90-             f"insert  [{{'name': 'testName', 'value': 'testValue', '_id': " 
97+             f"[{{'name': 'testName', 'value': 'testValue', '_id': " 
9198            f"ObjectId('{ insert_result_id }  ')}}]" 
9299        )
93-         self .validate_spans (expected_db_statement )
100+         self .validate_spans (expected_db_operation ,  expected_db_statement )
94101
95102    def  test_update (self ):
96103        """Should create a child span for update""" 
@@ -99,29 +106,32 @@ def test_update(self):
99106                {"name" : "testName" }, {"$set" : {"value" : "someOtherValue" }}
100107            )
101108
109+         expected_db_operation  =  "update" 
102110        expected_db_statement  =  (
103-             "update  [SON([('q', {'name': 'testName'}), ('u', " 
111+             "[SON([('q', {'name': 'testName'}), ('u', " 
104112            "{'$set': {'value': 'someOtherValue'}}), ('multi', False), ('upsert', False)])]" 
105113        )
106-         self .validate_spans (expected_db_statement )
114+         self .validate_spans (expected_db_operation ,  expected_db_statement )
107115
108116    def  test_find (self ):
109117        """Should create a child span for find""" 
110118        with  self ._tracer .start_as_current_span ("rootSpan" ):
111119            self ._collection .find_one ({"name" : "testName" })
112120
113-         expected_db_statement  =  "find {'name': 'testName'}" 
114-         self .validate_spans (expected_db_statement )
121+         expected_db_operation  =  "find" 
122+         expected_db_statement  =  "{'name': 'testName'}" 
123+         self .validate_spans (expected_db_operation , expected_db_statement )
115124
116125    def  test_delete (self ):
117126        """Should create a child span for delete""" 
118127        with  self ._tracer .start_as_current_span ("rootSpan" ):
119128            self ._collection .delete_one ({"name" : "testName" })
120129
130+         expected_db_operation  =  "delete" 
121131        expected_db_statement  =  (
122-             "delete  [SON([('q', {'name': 'testName'}), ('limit', 1)])]" 
132+             "[SON([('q', {'name': 'testName'}), ('limit', 1)])]" 
123133        )
124-         self .validate_spans (expected_db_statement )
134+         self .validate_spans (expected_db_operation ,  expected_db_statement )
125135
126136    def  test_find_without_capture_statement (self ):
127137        """Should create a child span for find""" 
@@ -130,8 +140,9 @@ def test_find_without_capture_statement(self):
130140        with  self ._tracer .start_as_current_span ("rootSpan" ):
131141            self ._collection .find_one ({"name" : "testName" })
132142
133-         expected_db_statement  =  "find" 
134-         self .validate_spans (expected_db_statement )
143+         expected_db_operation  =  "find" 
144+         expected_db_statement  =  None 
145+         self .validate_spans (expected_db_operation , expected_db_statement )
135146
136147    def  test_uninstrument (self ):
137148        # check that integration is working 
0 commit comments