Class: Sentry::Envelope::Item Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/envelope/item.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1000
MAX_SERIALIZED_PAYLOAD_SIZE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1024 * 1000
SIZE_LIMITS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Hash.new(MAX_SERIALIZED_PAYLOAD_SIZE).update(
  "profile" => 1024 * 1000 * 50
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers, payload) ⇒ Item

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 Item.



35
36
37
38
39
40
41
# File 'lib/sentry/envelope/item.rb', line 35

def initialize(headers, payload)
  @headers = headers
  @payload = payload
  @type = headers[:type] || "event"
  @data_category = self.class.data_category(type)
  @size_limit = SIZE_LIMITS[type]
end

Instance Attribute Details

#data_categoryObject (readonly)

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.



13
14
15
# File 'lib/sentry/envelope/item.rb', line 13

def data_category
  @data_category
end

#headersObject (readonly)

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.



13
14
15
# File 'lib/sentry/envelope/item.rb', line 13

def headers
  @headers
end

#payloadObject (readonly)

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.



13
14
15
# File 'lib/sentry/envelope/item.rb', line 13

def payload
  @payload
end

#size_limitObject (readonly)

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.



13
14
15
# File 'lib/sentry/envelope/item.rb', line 13

def size_limit
  @size_limit
end

#typeObject (readonly)

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.



13
14
15
# File 'lib/sentry/envelope/item.rb', line 13

def type
  @type
end

Class Method Details

.byte_data_category(data_category) ⇒ Object

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.



28
29
30
31
32
33
# File 'lib/sentry/envelope/item.rb', line 28

def self.byte_data_category(data_category)
  case data_category
  when "log_item" then "log_byte"
  when "trace_metric" then "trace_metric_byte"
  end
end

.data_category(type) ⇒ Object

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.

rate limits and client reports use the data_category rather than envelope item type



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sentry/envelope/item.rb', line 16

def self.data_category(type)
  case type
  when "session", "attachment", "transaction", "profile", "span", "trace_metric" then type
  when "log" then "log_item"
  when "sessions" then "session"
  when "check_in" then "monitor"
  when "event" then "error"
  when "client_report" then "internal"
  else "default"
  end
end

Instance Method Details

#byte_data_categoryObject

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.



43
44
45
# File 'lib/sentry/envelope/item.rb', line 43

def byte_data_category
  self.class.byte_data_category(data_category)
end

#item_countObject

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.



47
48
49
# File 'lib/sentry/envelope/item.rb', line 47

def item_count
  headers[:item_count] || 1
end

#lost_event_byte_sizeObject

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.



51
52
53
54
55
# File 'lib/sentry/envelope/item.rb', line 51

def lost_event_byte_size
  return unless byte_data_category

  (payload.is_a?(String) ? payload : JSON.generate(payload)).bytesize
end

#serializeObject

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.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sentry/envelope/item.rb', line 61

def serialize
  result = to_s

  if result.bytesize > size_limit
    remove_breadcrumbs!
    result = to_s
  end

  if result.bytesize > size_limit
    reduce_stacktrace!
    result = to_s
  end

  [result, result.bytesize > size_limit]
end

#size_breakdownObject

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.



77
78
79
80
81
# File 'lib/sentry/envelope/item.rb', line 77

def size_breakdown
  payload.map do |key, value|
    "#{key}: #{JSON.generate(value).bytesize}"
  end.join(", ")
end

#to_sObject

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.



57
58
59
# File 'lib/sentry/envelope/item.rb', line 57

def to_s
  [JSON.generate(@headers), @payload.is_a?(String) ? @payload : JSON.generate(@payload)].join("\n")
end