@@ -47,6 +47,12 @@ def ignored_tasks(self):
47
47
def ignored_tasks (self , new_ignored_tasks ):
48
48
self ._ignored_tasks = set (new_ignored_tasks )
49
49
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
+
50
56
51
57
class MetricType (Enum ):
52
58
WSGI = "WSGI"
@@ -56,18 +62,30 @@ class MetricType(Enum):
56
62
class Metric :
57
63
def __init__ (self ) -> None :
58
64
self ._lock = RLock ()
65
+ self ._activate = {
66
+ MetricType .WSGI : False ,
67
+ MetricType .CELERY : False ,
68
+ }
59
69
self ._counters = {
60
70
MetricType .WSGI : Counter (),
61
71
MetricType .CELERY : Counter (),
62
72
}
63
73
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
+
64
80
@synchronized
65
81
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
67
84
68
85
@synchronized
69
86
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
71
89
72
90
@synchronized
73
91
def get_and_reset (self , _type ):
0 commit comments