Class: NewRelic::TelemetrySdk::Buffer
- Inherits:
-
Object
- Object
- NewRelic::TelemetrySdk::Buffer
- Includes:
- Logger
- Defined in:
- lib/newrelic/telemetry_sdk/buffer.rb
Overview
Instance Attribute Summary collapse
-
#common_attributes ⇒ Object
Attributes that should be added to every item in the batch e.g.
Instance Method Summary collapse
-
#flush ⇒ Object
Return a batch of data that has been collected in this buffer as an Array of Hashes.
-
#initialize(common_attributes = nil) ⇒ Buffer
constructor
Record a discrete piece of data (e.g. a Span) into the buffer for batching purposes.
- #record(item) ⇒ Object
Methods included from Logger
#clear_already_logged, #log_error, #log_once, logger, #logger, logger=, #logger=
Constructor Details
#initialize(common_attributes = nil) ⇒ Buffer
Record a discrete piece of data (e.g. a Span) into the buffer for batching purposes.
29 30 31 32 33 |
# File 'lib/newrelic/telemetry_sdk/buffer.rb', line 29 def initialize common_attributes=nil @items = [] @common_attributes = common_attributes @lock = Mutex.new end |
Instance Attribute Details
#common_attributes ⇒ Object
Attributes that should be added to every item in the batch e.g. {host: ‘my_host’}
20 21 22 |
# File 'lib/newrelic/telemetry_sdk/buffer.rb', line 20 def common_attributes @common_attributes end |
Instance Method Details
#flush ⇒ Object
Return a batch of data that has been collected in this buffer as an Array of Hashes. Also returns a Hash of any common attributes that have been set on the buffer to be attached to each individual data item.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/newrelic/telemetry_sdk/buffer.rb', line 52 def flush data = nil @lock.synchronize do data = @items @items = [] end data.map!(&:to_h) return data, @common_attributes rescue => e log_error "Encountered error while flushing buffer", e end |