Class: ElasticAPM::Transport::Base Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/elastic_apm/transport/base.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

WATCHER_EXECUTION_INTERVAL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

5
WORKER_JOIN_TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

5

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(config) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/elastic_apm/transport/base.rb', line 40

def initialize(config)
  @config = config
  @queue = SizedQueue.new(config.api_buffer_size)

  @serializers = Serializers.new(config)
  @filters = Filters.new(config)

  @stopped = Concurrent::AtomicBoolean.new
  @workers = Array.new(config.pool_size)

  @worker_mutex = Mutex.new
end

Instance Attribute Details

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/elastic_apm/transport/base.rb', line 53

def config
  @config
end

#filtersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/elastic_apm/transport/base.rb', line 53

def filters
  @filters
end

#queueObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/elastic_apm/transport/base.rb', line 53

def queue
  @queue
end

#stoppedObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/elastic_apm/transport/base.rb', line 53

def stopped
  @stopped
end

#watcherObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/elastic_apm/transport/base.rb', line 53

def watcher
  @watcher
end

#workersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/elastic_apm/transport/base.rb', line 53

def workers
  @workers
end

Instance Method Details

#add_filter(key, callback) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



93
94
95
# File 'lib/elastic_apm/transport/base.rb', line 93

def add_filter(key, callback)
  @filters.add(key, callback)
end

#handle_forking!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



97
98
99
100
101
102
103
104
# File 'lib/elastic_apm/transport/base.rb', line 97

def handle_forking!
  # We can't just stop and start again because the StopMessage
  # will then be the first message processed when the transport is
  # restarted.
  stop_watcher
  ensure_worker_count
  create_watcher
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
60
61
62
63
64
# File 'lib/elastic_apm/transport/base.rb', line 55

def start
  debug '%s: Starting Transport', pid_str
  # Set @stopped to false first, in case transport is restarted;
  # ensure_worker_count requires @stopped to be false
  # ~estolfo
  @stopped.make_false unless @stopped.false?

  ensure_worker_count
  create_watcher
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
69
70
71
72
73
# File 'lib/elastic_apm/transport/base.rb', line 66

def stop
  debug '%s: Stopping Transport', pid_str

  @stopped.make_true

  stop_watcher
  stop_workers
end

#submit(resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/elastic_apm/transport/base.rb', line 75

def submit(resource)
  if @stopped.true?
    warn '%s: Transport stopping, no new events accepted', pid_str
    debug 'Dropping: %s', resource.inspect
    return false
  end

  queue.push(resource, true)

  true
rescue ThreadError
  throttled_queue_full_warning
  nil
rescue Exception => e
  error '%s: Failed adding to the transport queue: %p', pid_str, e.inspect
  nil
end