Class: Datadog::Statsd::Serialization::EventSerializer
- Inherits:
-
Object
- Object
- Datadog::Statsd::Serialization::EventSerializer
- Defined in:
- lib/datadog/statsd/serialization/event_serializer.rb
Constant Summary collapse
- EVENT_BASIC_OPTIONS =
{ date_happened: 'd:', hostname: 'h:', aggregation_key: 'k:', priority: 'p:', source_type_name: 's:', alert_type: 't:', }.freeze
Instance Method Summary collapse
- #format(title, text, options = EMPTY_OPTIONS) ⇒ Object
-
#initialize(global_tags: []) ⇒ EventSerializer
constructor
A new instance of EventSerializer.
Constructor Details
permalink #initialize(global_tags: []) ⇒ EventSerializer
Returns a new instance of EventSerializer.
16 17 18 |
# File 'lib/datadog/statsd/serialization/event_serializer.rb', line 16 def initialize(global_tags: []) @tag_serializer = TagSerializer.new() end |
Instance Method Details
permalink #format(title, text, options = EMPTY_OPTIONS) ⇒ Object
[View source]
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/datadog/statsd/serialization/event_serializer.rb', line 20 def format(title, text, = EMPTY_OPTIONS) title = escape(title) text = escape(text) String.new.tap do |event| event << '_e{' event << title.bytesize.to_s event << ',' event << text.bytesize.to_s event << '}:' event << title event << '|' event << text # we are serializing the generic service check options # before serializing specialized options that need edge-cases EVENT_BASIC_OPTIONS.each do |option_key, shortcut| if value = [option_key] event << '|' event << shortcut event << value.to_s.delete('|') end end # also returns the global tags from serializer if = tag_serializer.format([:tags]) event << '|#' event << end if event.bytesize > MAX_EVENT_SIZE if [:truncate_if_too_long] event.slice!(MAX_EVENT_SIZE..event.length) else raise "Event #{title} payload is too big (more that 8KB), event discarded" end end end end |