@@ -47,6 +47,12 @@ def ignored_tasks(self):
4747 def ignored_tasks (self , new_ignored_tasks ):
4848 self ._ignored_tasks = set (new_ignored_tasks )
4949
50+ @synchronized
51+ def update (self , data ):
52+ self ._sample_rate = data ["active_sample_rate" ]
53+ self ._ignored_paths = data ["wsgi_ignore_path" ]
54+ self ._ignored_tasks = data ["celery_ignore_task" ]
55+
5056
5157class MetricType (Enum ):
5258 WSGI = "WSGI"
@@ -56,18 +62,30 @@ class MetricType(Enum):
5662class Metric :
5763 def __init__ (self ) -> None :
5864 self ._lock = RLock ()
65+ self ._activate = {
66+ MetricType .WSGI : False ,
67+ MetricType .CELERY : False ,
68+ }
5969 self ._counters = {
6070 MetricType .WSGI : Counter (),
6171 MetricType .CELERY : Counter (),
6272 }
6373
74+ def set_mode (self , _type , mode ):
75+ self ._activate [_type ] = mode
76+
77+ def get_mode (self , _type ):
78+ return self ._activate [_type ]
79+
6480 @synchronized
6581 def count_path (self , path ):
66- self ._counters [MetricType .WSGI ][path ] += 1
82+ if self ._activate [MetricType .WSGI ]:
83+ self ._counters [MetricType .WSGI ][path ] += 1
6784
6885 @synchronized
6986 def count_task (self , path ):
70- self ._counters [MetricType .CELERY ][path ] += 1
87+ if self ._activate [MetricType .CELERY ]:
88+ self ._counters [MetricType .CELERY ][path ] += 1
7189
7290 @synchronized
7391 def get_and_reset (self , _type ):
0 commit comments