lib/ddtrace/workers/runtime_metrics.rb in ddtrace-0.47.0 vs lib/ddtrace/workers/runtime_metrics.rb in ddtrace-0.48.0
- old
+ new
@@ -18,11 +18,11 @@
attr_reader \
:metrics
def initialize(options = {})
- @metrics = options.fetch(:metrics, Runtime::Metrics.new)
+ @metrics = options.fetch(:metrics) { Runtime::Metrics.new }
# Workers::Async::Thread settings
self.fork_policy = options.fetch(:fork_policy, Workers::Async::Thread::FORK_POLICY_STOP)
# Workers::IntervalLoop settings
@@ -39,9 +39,22 @@
end
def associate_with_span(*args)
# Start the worker
metrics.associate_with_span(*args).tap { perform }
+ end
+
+ # TODO: `close_metrics` is only needed because
+ # Datadog::Components directly manipulates the lifecycle of
+ # Runtime::Metrics.statsd instances.
+ # This should be avoided, as it prevents this class from
+ # ensuring correct resource decommission of its internal
+ # dependencies.
+ def stop(*args, close_metrics: true)
+ self.enabled = false
+ result = super(*args)
+ @metrics.close if close_metrics
+ result
end
def_delegators \
:metrics,
:register_service