@@ -247,7 +247,7 @@ class DimensionalMetrics(CustomMetrics):
247
247
def __contains__ (self , key ):
248
248
if not isinstance (key [1 ], frozenset ):
249
249
# Convert tags dict to a frozen set for proper comparisons
250
- create_metric_identity (* key )
250
+ key = create_metric_identity (* key )
251
251
return key in self .__stats_table
252
252
253
253
def record_dimensional_metric (self , name , value , tags = None ):
@@ -259,6 +259,16 @@ def record_dimensional_metric(self, name, value, tags=None):
259
259
key = create_metric_identity (name , tags )
260
260
self .record_custom_metric (key , value )
261
261
262
+ class DimensionalStatsTable (dict ):
263
+
264
+ """Extends dict to coerce a set of tags to a hashable identity."""
265
+
266
+ def __contains__ (self , key ):
267
+ if key [1 ] is not None and not isinstance (key [1 ], frozenset ):
268
+ # Convert tags dict to a frozen set for proper comparisons
269
+ key = create_metric_identity (* key )
270
+ return super (DimensionalStatsTable , self ).__contains__ (key )
271
+
262
272
263
273
class SlowSqlStats (list ):
264
274
def __init__ (self ):
@@ -458,7 +468,7 @@ class StatsEngine(object):
458
468
def __init__ (self ):
459
469
self .__settings = None
460
470
self .__stats_table = {}
461
- self .__dimensional_stats_table = {}
471
+ self .__dimensional_stats_table = DimensionalStatsTable ()
462
472
self ._transaction_events = SampledDataSet ()
463
473
self ._error_events = SampledDataSet ()
464
474
self ._custom_events = SampledDataSet ()
@@ -908,7 +918,7 @@ def record_dimensional_metric(self, name, value, tags=None):
908
918
else :
909
919
new_stats = TimeStats (1 , value , value , value , value , value ** 2 )
910
920
911
- key = create_metric_identity (name , tags = None )
921
+ key = create_metric_identity (name , tags )
912
922
stats = self .__dimensional_stats_table .get (key )
913
923
if stats is None :
914
924
self .__dimensional_stats_table [key ] = new_stats
@@ -1568,6 +1578,7 @@ def reset_stats(self, settings, reset_stream=False):
1568
1578
1569
1579
self .__settings = settings
1570
1580
self .__stats_table = {}
1581
+ self .__dimensional_stats_table = {}
1571
1582
self .__sql_stats_table = {}
1572
1583
self .__slow_transaction = None
1573
1584
self .__slow_transaction_map = {}
@@ -1594,6 +1605,7 @@ def reset_metric_stats(self):
1594
1605
"""
1595
1606
1596
1607
self .__stats_table = {}
1608
+ self .__dimensional_stats_table = {}
1597
1609
1598
1610
def reset_transaction_events (self ):
1599
1611
"""Resets the accumulated statistics back to initial state for
0 commit comments