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.
Instance Attribute Summary collapse
-
#api_host ⇒ String
Set this attribute in order to override the destination of these Honeycomb events (defaults to
Client::API_HOST
). -
#data ⇒ Hash<String=>any>
readonly
The fields added to this event.
-
#dataset ⇒ String
The Honeycomb dataset this event is destined for (defaults to the
Builder
‘sdataset
, which in turn defaults to theClient
’sdataset
). -
#metadata ⇒ Object
Set this attribute to any
Object
you might need to identify this Event as it is returned to the responses queue (e.g. tag an Event with an internal ID in order to retry something specific on failure). -
#sample_rate ⇒ Fixnum
Set this attribute to indicate that it represents
sample_rate
number of events (e.g. setting this to10
will result in a 1-in-10 chance of it being successfully emitted to Honeycomb, and the Honeycomb query engine will interpret it as representative of 10 events). -
#timestamp ⇒ Time
Set this attribute in order to override the timestamp associated with the event (defaults to the
Time.now
atEvent
creation). -
#writekey ⇒ String
The Honeycomb API key with which to authenticate this request.
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) ⇒ 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.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/libhoney/event.rb', line 47 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| add_field(k, v) } dyn_fields.each { |k, v| add_field(k, v.call) } end |
Instance Attribute Details
#api_host ⇒ String
Returns Set this attribute in order to override the destination of these Honeycomb events (defaults to Client::API_HOST
).
28 29 30 |
# File 'lib/libhoney/event.rb', line 28 def api_host @api_host end |
#data ⇒ Hash<String=>any> (readonly)
Returns the fields added to this event.
42 43 44 |
# File 'lib/libhoney/event.rb', line 42 def data @data end |
#dataset ⇒ String
Returns the Honeycomb dataset this event is destined for (defaults to the Builder
‘s dataset
, which in turn defaults to the Client
’s dataset
).
18 19 20 |
# File 'lib/libhoney/event.rb', line 18 def dataset @dataset end |
#metadata ⇒ Object
Returns Set this attribute to any Object
you might need to identify this Event as it is returned to the responses queue (e.g. tag an Event with an internal ID in order to retry something specific on failure).
34 35 36 |
# File 'lib/libhoney/event.rb', line 34 def @metadata end |
#sample_rate ⇒ Fixnum
Returns Set this attribute to indicate that it represents sample_rate
number of events (e.g. setting this to 10
will result in a 1-in-10 chance of it being successfully emitted to Honeycomb, and the Honeycomb query engine will interpret it as representative of 10 events).
24 25 26 |
# File 'lib/libhoney/event.rb', line 24 def sample_rate @sample_rate end |
#timestamp ⇒ Time
Returns Set this attribute in order to override the timestamp associated with the event (defaults to the Time.now
at Event
creation).
39 40 41 |
# File 'lib/libhoney/event.rb', line 39 def @timestamp end |
#writekey ⇒ String
Returns the Honeycomb API key with which to authenticate this request.
13 14 15 |
# File 'lib/libhoney/event.rb', line 13 def writekey @writekey end |
Instance Method Details
#add(newdata) ⇒ self
adds a group of field->values to this event.
71 72 73 74 |
# File 'lib/libhoney/event.rb', line 71 def add(newdata) @data.merge!(newdata) self end |
#add_field(name, val) ⇒ self
adds a single field->value mapping to this event.
85 86 87 88 |
# File 'lib/libhoney/event.rb', line 85 def add_field(name, val) @data[name] = val self end |
#send ⇒ self
sends this event to Honeycomb
110 111 112 113 114 115 116 117 118 |
# File 'lib/libhoney/event.rb', line 110 def send # discard if sampling rate says so if @libhoney.should_drop(sample_rate) @libhoney.send_dropped_response(self, 'event dropped due to sampling') return end send_presampled end |
#send_presampled ⇒ self
sends a presampled event to Honeycomb
123 124 125 126 127 128 129 130 131 |
# File 'lib/libhoney/event.rb', line 123 def send_presampled if Thread.current[:libhoney_transmitting] @libhoney.send_dropped_response(self, 'dropped event generated during transmission') else @libhoney.send_event(self) end self end |
#with_timer(name) ⇒ self
times the execution of a block and adds a field containing the duration in milliseconds
98 99 100 101 102 103 104 105 |
# File 'lib/libhoney/event.rb', line 98 def with_timer(name) start = Time.now yield duration = Time.now - start # report in ms add_field(name, duration * 1000) self end |