@@ -187,9 +187,7 @@ def __init__(self, config=None, **inline):
187187 )
188188 self .include_paths_re = stacks .get_path_regex (self .config .include_paths ) if self .config .include_paths else None
189189 self .exclude_paths_re = stacks .get_path_regex (self .config .exclude_paths ) if self .config .exclude_paths else None
190- self ._metrics = MetricsRegistry (
191- self .config .metrics_interval / 1000.0 , self .queue , ignore_patterns = self .config .disable_metrics
192- )
190+ self ._metrics = MetricsRegistry (self )
193191 for path in self .config .metrics_sets :
194192 self ._metrics .register (path )
195193 if self .config .breakdown_metrics :
@@ -200,15 +198,14 @@ def __init__(self, config=None, **inline):
200198 self ._thread_managers ["config" ] = self .config
201199 else :
202200 self ._config_updater = None
203-
204201 if self .config .use_elastic_excepthook :
205202 self .original_excepthook = sys .excepthook
206203 self .excepthook_overwritten_by_user = (
207204 self .original_excepthook is not sys .__excepthook__
208205 )
209206 sys .excepthook = self ._excepthook
210-
211- self .start_threads ()
207+ if config . enabled :
208+ self .start_threads ()
212209
213210 def start_threads (self ):
214211 with self ._thread_starter_lock :
@@ -217,7 +214,7 @@ def start_threads(self):
217214 self .logger .debug ("Detected PID change from %r to %r, starting threads" , self ._pid , current_pid )
218215 for manager_type , manager in self ._thread_managers .items ():
219216 self .logger .debug ("Starting %s thread" , manager_type )
220- manager .start_thread ()
217+ manager .start_thread (pid = current_pid )
221218 self ._pid = current_pid
222219
223220 def get_handler (self , name ):
@@ -227,6 +224,8 @@ def capture(self, event_type, date=None, context=None, custom=None, stack=None,
227224 """
228225 Captures and processes an event and pipes it off to Client.send.
229226 """
227+ if not self .config .is_recording :
228+ return
230229 if event_type == "Exception" :
231230 # never gather log stack for exceptions
232231 stack = False
@@ -281,7 +280,8 @@ def begin_transaction(self, transaction_type, trace_parent=None, start=None):
281280 :param start: override the start timestamp, mostly useful for testing
282281 :return: the started transaction object
283282 """
284- return self .tracer .begin_transaction (transaction_type , trace_parent = trace_parent , start = start )
283+ if self .config .is_recording :
284+ return self .tracer .begin_transaction (transaction_type , trace_parent = trace_parent , start = start )
285285
286286 def end_transaction (self , name = None , result = "" , duration = None ):
287287 """
@@ -296,9 +296,10 @@ def end_transaction(self, name=None, result="", duration=None):
296296 return transaction
297297
298298 def close (self ):
299- with self ._thread_starter_lock :
300- for _manager_type , manager in self ._thread_managers .items ():
301- manager .stop_thread ()
299+ if self .config .enabled :
300+ with self ._thread_starter_lock :
301+ for _ , manager in self ._thread_managers .items ():
302+ manager .stop_thread ()
302303
303304 def get_service_info (self ):
304305 if self ._service_info :
0 commit comments