lib/elastic_apm/agent.rb in elastic-apm-0.7.4 vs lib/elastic_apm/agent.rb in elastic-apm-0.8.0
- old
+ new
@@ -6,11 +6,11 @@
require 'elastic_apm/stacktrace_builder'
require 'elastic_apm/error'
require 'elastic_apm/http'
require 'elastic_apm/spies'
require 'elastic_apm/serializers'
-require 'elastic_apm/timed_worker'
+require 'elastic_apm/worker'
module ElasticAPM
# rubocop:disable Metrics/ClassLength
# @api private
class Agent
@@ -105,16 +105,27 @@
def enqueue_transaction(transaction)
boot_worker unless worker_running?
pending_transactions.push(transaction)
+
+ return unless should_flush_transactions?
+
+ messages.push(Worker::FlushMsg.new)
end
+ def should_flush_transactions?
+ return true unless config.flush_interval
+ return true if pending_transactions.length >= config.max_queue_size
+
+ false
+ end
+
def enqueue_error(error)
boot_worker unless worker_running?
- messages.push(TimedWorker::ErrorMsg.new(error))
+ messages.push(Worker::ErrorMsg.new(error))
end
# instrumentation
def current_transaction
@@ -180,20 +191,20 @@
def boot_worker
debug 'Booting worker'
@worker_thread = Thread.new do
- TimedWorker.new(
+ Worker.new(
config,
messages,
pending_transactions,
http
).run_forever
end
end
def kill_worker
- messages << TimedWorker::StopMsg.new
+ messages << Worker::StopMsg.new
if @worker_thread && !@worker_thread.join(5) # 5 secs
raise 'Failed to wait for worker, not all messages sent'
end