Class: Sentry::Envelope::Item Private

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

Overview

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.

API:

  • private

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.

API:

  • private

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

API:

  • private

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.

API:

  • private

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.

API:

  • private



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

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_category ⇒ Object (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.

API:

  • private



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

def data_category
  @data_category
end

#headers ⇒ Object (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.

API:

  • private



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

def headers
  @headers
end

#payload ⇒ Object (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.

API:

  • private



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

def payload
  @payload
end

#size_limit ⇒ Object (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.

API:

  • private



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

def size_limit
  @size_limit
end

#type ⇒ Object (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.

API:

  • private



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

def type
  @type
end

Class Method Details

.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

API:

  • private



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" then type
  when "sessions" then "session"
  when "check_in" then "monitor"
  when "statsd", "metric_meta" then "metric_bucket"
  when "event" then "error"
  when "client_report" then "internal"
  else "default"
  end
end

Instance Method Details

#serialize ⇒ 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.

API:

  • private



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sentry/envelope/item.rb', line 40

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_breakdown ⇒ 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.

API:

  • private



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

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

#to_s ⇒ 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.

API:

  • private



36
37
38
# File 'lib/sentry/envelope/item.rb', line 36

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