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, options = 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
EVENT_BASIC_OPTIONS.each do |option_key, shortcut|
if value = options[option_key]
event << '|'
event << shortcut
event << value.to_s.delete('|')
end
end
if tags = tag_serializer.format(options[:tags])
event << '|#'
event << tags
end
if event.bytesize > MAX_EVENT_SIZE
if options[: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
|