Class: Libhoney::Event
- Inherits:
-
Object
- Object
- Libhoney::Event
- Defined in:
- lib/libhoney/event.rb
Overview
This is the event object that you can fill up with data. The data itself is a ruby hash.
Instance Attribute Summary collapse
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#dataset ⇒ Object
Returns the value of attribute dataset.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#writekey ⇒ Object
Returns the value of attribute writekey.
Instance Method Summary collapse
-
#add(newdata) ⇒ self
adds a group of field->values to this event.
-
#add_field(name, val) ⇒ self
adds a single field->value mapping to this event.
-
#initialize(libhoney, builder, fields = {}, dyn_fields = {}) ⇒ Event
constructor
private
A new instance of Event.
-
#send ⇒ self
sends this event to honeycomb.
-
#send_presampled ⇒ self
sends a presampled event to honeycomb.
-
#with_timer(name, &block) ⇒ self
times the execution of a block and adds a field containing the duration in milliseconds.
Constructor Details
#initialize(libhoney, builder, fields = {}, dyn_fields = {}) ⇒ Event
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 Event.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/libhoney/event.rb', line 14 def initialize(libhoney, builder, fields = {}, dyn_fields = {}) @libhoney = libhoney @writekey = builder.writekey @dataset = builder.dataset @sample_rate = builder.sample_rate @api_host = builder.api_host @timestamp = Time.now @metadata = nil @data = { } fields.each { |k, v| self.add_field(k, v) } dyn_fields.each { |k, v| self.add_field(k, v.call) } self end |
Instance Attribute Details
#api_host ⇒ Object
Returns the value of attribute api_host.
6 7 8 |
# File 'lib/libhoney/event.rb', line 6 def api_host @api_host end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/libhoney/event.rb', line 9 def data @data end |
#dataset ⇒ Object
Returns the value of attribute dataset.
6 7 8 |
# File 'lib/libhoney/event.rb', line 6 def dataset @dataset end |
#metadata ⇒ Object
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/libhoney/event.rb', line 7 def @metadata end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
6 7 8 |
# File 'lib/libhoney/event.rb', line 6 def sample_rate @sample_rate end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/libhoney/event.rb', line 7 def @timestamp end |
#writekey ⇒ Object
Returns the value of attribute writekey.
6 7 8 |
# File 'lib/libhoney/event.rb', line 6 def writekey @writekey end |
Instance Method Details
#add(newdata) ⇒ self
adds a group of field->values to this event.
41 42 43 44 |
# File 'lib/libhoney/event.rb', line 41 def add(newdata) @data.merge!(newdata) self end |
#add_field(name, val) ⇒ self
adds a single field->value mapping to this event.
55 56 57 58 |
# File 'lib/libhoney/event.rb', line 55 def add_field(name, val) @data[name] = val self end |
#send ⇒ self
sends this event to honeycomb
80 81 82 83 84 85 86 87 88 |
# File 'lib/libhoney/event.rb', line 80 def send # discard if sampling rate says so if @libhoney.should_drop(self.sample_rate) @libhoney.send_dropped_response(self, "event dropped due to sampling") return end self.send_presampled() end |
#send_presampled ⇒ self
sends a presampled event to honeycomb
93 94 95 96 97 98 99 100 101 |
# File 'lib/libhoney/event.rb', line 93 def send_presampled raise ArgumentError.new("No metrics added to event. Won't send empty event.") if self.data.length == 0 raise ArgumentError.new("No APIHost for Honeycomb. Can't send to the Great Unknown.") if self.api_host == "" raise ArgumentError.new("No WriteKey specified. Can't send event.") if self.writekey == "" raise ArgumentError.new("No Dataset for Honeycomb. Can't send datasetless.") if self.dataset == "" @libhoney.send_event(self) self end |
#with_timer(name, &block) ⇒ self
times the execution of a block and adds a field containing the duration in milliseconds
68 69 70 71 72 73 74 75 |
# File 'lib/libhoney/event.rb', line 68 def with_timer(name, &block) start = Time.now block.call duration = Time.now - start # report in ms self.add_field(name, duration * 1000) self end |