@@ -415,6 +415,41 @@ def method():
415415 assert span .get_metric ('db.rowcount' ) == 123 , 'Row count is set as a metric'
416416 assert span .get_tag ('sql.rows' ) == '123' , 'Row count is set as a tag (for legacy django cursor replacement)'
417417
418+ def test_fetch_analytics_off (self ):
419+ with self .override_config (
420+ 'dbapi2' ,
421+ dict (analytics_enabled = True )
422+ ):
423+ cursor = self .cursor
424+ cursor .rowcount = 0
425+ cursor .fetchone .return_value = '__result__'
426+ pin = Pin ('pin_name' , tracer = self .tracer )
427+ traced_cursor = FetchTracedCursor (cursor , pin )
428+ assert '__result__' == traced_cursor .fetchone ('arg_1' , kwarg1 = 'kwarg1' )
429+
430+ span = self .tracer .writer .pop ()[0 ]
431+ self .assertIsNone (span .get_metric (ANALYTICS_SAMPLE_RATE_KEY ))
432+
433+ cursor = self .cursor
434+ cursor .rowcount = 0
435+ cursor .fetchall .return_value = '__result__'
436+ pin = Pin ('pin_name' , tracer = self .tracer )
437+ traced_cursor = FetchTracedCursor (cursor , pin )
438+ assert '__result__' == traced_cursor .fetchall ('arg_1' , kwarg1 = 'kwarg1' )
439+
440+ span = self .tracer .writer .pop ()[0 ]
441+ self .assertIsNone (span .get_metric (ANALYTICS_SAMPLE_RATE_KEY ))
442+
443+ cursor = self .cursor
444+ cursor .rowcount = 0
445+ cursor .fetchmany .return_value = '__result__'
446+ pin = Pin ('pin_name' , tracer = self .tracer )
447+ traced_cursor = FetchTracedCursor (cursor , pin )
448+ assert '__result__' == traced_cursor .fetchmany ('arg_1' , kwarg1 = 'kwarg1' )
449+
450+ span = self .tracer .writer .pop ()[0 ]
451+ self .assertIsNone (span .get_metric (ANALYTICS_SAMPLE_RATE_KEY ))
452+
418453
419454class TestTracedConnection (BaseTracerTestCase ):
420455 def setUp (self ):
@@ -458,7 +493,7 @@ def test_rollback_is_traced(self):
458493 assert tracer .writer .pop ()[0 ].name == 'mock.connection.rollback'
459494 connection .rollback .assert_called_with ()
460495
461- def test_cursor_analytics_with_rate (self ):
496+ def test_connection_analytics_with_rate (self ):
462497 with self .override_config (
463498 'dbapi2' ,
464499 dict (analytics_enabled = True , analytics_sample_rate = 0.5 )
@@ -470,4 +505,4 @@ def test_cursor_analytics_with_rate(self):
470505 traced_connection = TracedConnection (connection , pin )
471506 traced_connection .commit ()
472507 span = tracer .writer .pop ()[0 ]
473- self .assertEqual (span .get_metric (ANALYTICS_SAMPLE_RATE_KEY ), 0.5 )
508+ self .assertIsNone (span .get_metric (ANALYTICS_SAMPLE_RATE_KEY ))
0 commit comments